-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.py
More file actions
31 lines (23 loc) · 1001 Bytes
/
Copy pathtools.py
File metadata and controls
31 lines (23 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from langchain_community.tools import WikipediaQueryRun , DuckDuckGoSearchRun
from langchain_community.utilities import WikipediaAPIWrapper
from langchain.tools import Tool
from datetime import datetime
search = DuckDuckGoSearchRun()
search_tool = Tool(
name = "search",
func = search.run,
description = "Search the web for the information.",
)
api_wrapper = WikipediaAPIWrapper(top_k_results=1,doc_content_chars_max=50)
wiki_tool = WikipediaQueryRun(api_wrapper=api_wrapper)
def save_to_text(data:str, filename: str = "research_output.txt"):
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
formatted_text = f"--- Research output --- \nTimestamp: {timestamp}\n\n{data}\n\n"
with open(filename, "a", encoding = "utf-8") as f:
f.write(formatted_text)
return f"Data successfully saved to {filename}"
save_tool = Tool(
name = "Save_text_to_file",
func = save_to_text,
description = "Saves structured research data to a file."
)