Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
@@ -48,7 +48,7 @@ def subtract(a: int, b: int) -> int:
|
|
48 |
return a - b
|
49 |
|
50 |
@tool
|
51 |
-
def divide(a: int, b: int) ->
|
52 |
"""Divide two numbers.
|
53 |
|
54 |
Args:
|
@@ -70,7 +70,7 @@ def modulus(a: int, b: int) -> int:
|
|
70 |
return a % b
|
71 |
|
72 |
@tool
|
73 |
-
def wiki_search(query: str) ->
|
74 |
"""Search Wikipedia for a query and return maximum 2 results.
|
75 |
|
76 |
Args:
|
@@ -84,7 +84,7 @@ def wiki_search(query: str) -> dict:
|
|
84 |
return {"wiki_results": formatted_search_docs}
|
85 |
|
86 |
@tool
|
87 |
-
def web_search(query: str) ->
|
88 |
"""Search Tavily for a query and return maximum 3 results.
|
89 |
|
90 |
Args:
|
@@ -98,7 +98,7 @@ def web_search(query: str) -> dict:
|
|
98 |
return {"web_results": formatted_search_docs}
|
99 |
|
100 |
@tool
|
101 |
-
def
|
102 |
"""Search Arxiv for a query and return maximum 3 result.
|
103 |
|
104 |
Args:
|
@@ -109,7 +109,7 @@ def arxiv_search(query: str) -> dict:
|
|
109 |
f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content[:1000]}\n</Document>'
|
110 |
for doc in search_docs
|
111 |
])
|
112 |
-
return {"
|
113 |
|
114 |
|
115 |
|
@@ -147,8 +147,7 @@ tools = [
|
|
147 |
modulus,
|
148 |
wiki_search,
|
149 |
web_search,
|
150 |
-
|
151 |
-
create_retriever_tool,
|
152 |
]
|
153 |
|
154 |
# Build graph function
|
@@ -206,10 +205,9 @@ def build_graph(provider: str = "groq"):
|
|
206 |
if __name__ == "__main__":
|
207 |
question = "When was a picture of St. Thomas Aquinas first added to the Wikipedia page on the Principle of double effect?"
|
208 |
# Build the graph
|
209 |
-
graph = build_graph(provider="
|
210 |
# Run the graph
|
211 |
messages = [HumanMessage(content=question)]
|
212 |
messages = graph.invoke({"messages": messages})
|
213 |
for m in messages["messages"]:
|
214 |
m.pretty_print()
|
215 |
-
|
|
|
48 |
return a - b
|
49 |
|
50 |
@tool
|
51 |
+
def divide(a: int, b: int) -> int:
|
52 |
"""Divide two numbers.
|
53 |
|
54 |
Args:
|
|
|
70 |
return a % b
|
71 |
|
72 |
@tool
|
73 |
+
def wiki_search(query: str) -> str:
|
74 |
"""Search Wikipedia for a query and return maximum 2 results.
|
75 |
|
76 |
Args:
|
|
|
84 |
return {"wiki_results": formatted_search_docs}
|
85 |
|
86 |
@tool
|
87 |
+
def web_search(query: str) -> str:
|
88 |
"""Search Tavily for a query and return maximum 3 results.
|
89 |
|
90 |
Args:
|
|
|
98 |
return {"web_results": formatted_search_docs}
|
99 |
|
100 |
@tool
|
101 |
+
def arvix_search(query: str) -> str:
|
102 |
"""Search Arxiv for a query and return maximum 3 result.
|
103 |
|
104 |
Args:
|
|
|
109 |
f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content[:1000]}\n</Document>'
|
110 |
for doc in search_docs
|
111 |
])
|
112 |
+
return {"arvix_results": formatted_search_docs}
|
113 |
|
114 |
|
115 |
|
|
|
147 |
modulus,
|
148 |
wiki_search,
|
149 |
web_search,
|
150 |
+
arvix_search,
|
|
|
151 |
]
|
152 |
|
153 |
# Build graph function
|
|
|
205 |
if __name__ == "__main__":
|
206 |
question = "When was a picture of St. Thomas Aquinas first added to the Wikipedia page on the Principle of double effect?"
|
207 |
# Build the graph
|
208 |
+
graph = build_graph(provider="groq")
|
209 |
# Run the graph
|
210 |
messages = [HumanMessage(content=question)]
|
211 |
messages = graph.invoke({"messages": messages})
|
212 |
for m in messages["messages"]:
|
213 |
m.pretty_print()
|
|