-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.py
More file actions
16 lines (13 loc) · 695 Bytes
/
tools.py
File metadata and controls
16 lines (13 loc) · 695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from langchain_community.tools import WikipediaQueryRun
from langchain_community.utilities import WikipediaAPIWrapper
from langchain.tools import tool
from datetime import datetime
api_wrapper = WikipediaAPIWrapper(top_k_results=2, doc_content_chars_max=100)
wiki_tool = WikipediaQueryRun(api_wrapper=api_wrapper)
@tool("save", description="Save data to text file")
def save_to_txt(data:str, filename:str = "research.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 saved to {filename}"