ktluege commited on
Commit
ba7d685
Β·
verified Β·
1 Parent(s): 292f5f0

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +32 -0
agent.py CHANGED
@@ -41,6 +41,38 @@ def divide(a: int, b: int) -> float:
41
  def modulus(a: int, b: int) -> int:
42
  """Get the modulus of two numbers."""
43
  return a % b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
 
46
  tools = [
 
41
  def modulus(a: int, b: int) -> int:
42
  """Get the modulus of two numbers."""
43
  return a % b
44
+ @tool
45
+ def wiki_search(query: str) -> str:
46
+ """Search Wikipedia for a query and return maximum 2 results."""
47
+ search_docs = WikipediaLoader(query=query, load_max_docs=2).load()
48
+ formatted_search_docs = "\n\n---\n\n".join(
49
+ [
50
+ f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
51
+ for doc in search_docs
52
+ ])
53
+ return {"wiki_results": formatted_search_docs}
54
+
55
+ @tool
56
+ def web_search(query: str) -> str:
57
+ """Search Tavily for a query and return maximum 3 results."""
58
+ search_docs = TavilySearchResults(max_results=3).invoke(query=query)
59
+ formatted_search_docs = "\n\n---\n\n".join(
60
+ [
61
+ f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
62
+ for doc in search_docs
63
+ ])
64
+ return {"web_results": formatted_search_docs}
65
+
66
+ @tool
67
+ def arvix_search(query: str) -> str:
68
+ """Search Arxiv for a query and return maximum 3 result."""
69
+ search_docs = ArxivLoader(query=query, load_max_docs=3).load()
70
+ formatted_search_docs = "\n\n---\n\n".join(
71
+ [
72
+ f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content[:1000]}\n</Document>'
73
+ for doc in search_docs
74
+ ])
75
+ return {"arvix_results": formatted_search_docs}
76
 
77
 
78
  tools = [