Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
"""LangGraph Agent"""
|
| 3 |
import os
|
| 4 |
from dotenv import load_dotenv
|
|
@@ -49,7 +48,7 @@ def subtract(a: int, b: int) -> int:
|
|
| 49 |
return a - b
|
| 50 |
|
| 51 |
@tool
|
| 52 |
-
def divide(a: int, b: int) ->
|
| 53 |
"""Divide two numbers.
|
| 54 |
|
| 55 |
Args:
|
|
@@ -71,7 +70,7 @@ def modulus(a: int, b: int) -> int:
|
|
| 71 |
return a % b
|
| 72 |
|
| 73 |
@tool
|
| 74 |
-
def wiki_search(query: str) ->
|
| 75 |
"""Search Wikipedia for a query and return maximum 2 results.
|
| 76 |
|
| 77 |
Args:
|
|
@@ -85,7 +84,7 @@ def wiki_search(query: str) -> str:
|
|
| 85 |
return {"wiki_results": formatted_search_docs}
|
| 86 |
|
| 87 |
@tool
|
| 88 |
-
def web_search(query: str) ->
|
| 89 |
"""Search Tavily for a query and return maximum 3 results.
|
| 90 |
|
| 91 |
Args:
|
|
@@ -99,7 +98,7 @@ def web_search(query: str) -> str:
|
|
| 99 |
return {"web_results": formatted_search_docs}
|
| 100 |
|
| 101 |
@tool
|
| 102 |
-
def
|
| 103 |
"""Search Arxiv for a query and return maximum 3 result.
|
| 104 |
|
| 105 |
Args:
|
|
@@ -110,7 +109,7 @@ def arvix_search(query: str) -> str:
|
|
| 110 |
f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content[:1000]}\n</Document>'
|
| 111 |
for doc in search_docs
|
| 112 |
])
|
| 113 |
-
return {"
|
| 114 |
|
| 115 |
|
| 116 |
|
|
@@ -148,7 +147,8 @@ tools = [
|
|
| 148 |
modulus,
|
| 149 |
wiki_search,
|
| 150 |
web_search,
|
| 151 |
-
|
|
|
|
| 152 |
]
|
| 153 |
|
| 154 |
# Build graph function
|
|
@@ -206,7 +206,7 @@ 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})
|
|
|
|
|
|
|
| 1 |
"""LangGraph Agent"""
|
| 2 |
import os
|
| 3 |
from dotenv import load_dotenv
|
|
|
|
| 48 |
return a - b
|
| 49 |
|
| 50 |
@tool
|
| 51 |
+
def divide(a: int, b: int) -> float:
|
| 52 |
"""Divide two numbers.
|
| 53 |
|
| 54 |
Args:
|
|
|
|
| 70 |
return a % b
|
| 71 |
|
| 72 |
@tool
|
| 73 |
+
def wiki_search(query: str) -> dict:
|
| 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) -> dict:
|
| 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 arxiv_search(query: str) -> dict:
|
| 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 {"arxiv_results": formatted_search_docs}
|
| 113 |
|
| 114 |
|
| 115 |
|
|
|
|
| 147 |
modulus,
|
| 148 |
wiki_search,
|
| 149 |
web_search,
|
| 150 |
+
arxiv_search,
|
| 151 |
+
create_retriever_tool,
|
| 152 |
]
|
| 153 |
|
| 154 |
# Build graph function
|
|
|
|
| 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="google")
|
| 210 |
# Run the graph
|
| 211 |
messages = [HumanMessage(content=question)]
|
| 212 |
messages = graph.invoke({"messages": messages})
|