Spaces:
Runtime error
Runtime error
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -17,28 +17,34 @@ GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
|
| 17 |
# --- Tools ---
|
| 18 |
@tool
|
| 19 |
def multiply(a: int, b: int) -> int:
|
|
|
|
| 20 |
return a * b
|
| 21 |
|
| 22 |
@tool
|
| 23 |
def add(a: int, b: int) -> int:
|
|
|
|
| 24 |
return a + b
|
| 25 |
|
| 26 |
@tool
|
| 27 |
def subtract(a: int, b: int) -> int:
|
|
|
|
| 28 |
return a - b
|
| 29 |
|
| 30 |
@tool
|
| 31 |
def divide(a: int, b: int) -> float:
|
|
|
|
| 32 |
if b == 0:
|
| 33 |
raise ValueError("Cannot divide by zero.")
|
| 34 |
return a / b
|
| 35 |
|
| 36 |
@tool
|
| 37 |
def modulo(a: int, b: int) -> int:
|
|
|
|
| 38 |
return a % b
|
| 39 |
|
| 40 |
@tool
|
| 41 |
def wiki_search(query: str) -> str:
|
|
|
|
| 42 |
search_docs = WikipediaLoader(query=query, load_max_docs=2).load()
|
| 43 |
formatted = "\n\n---\n\n".join(
|
| 44 |
[f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}">\n{doc.page_content}\n</Document>' for doc in search_docs]
|
|
@@ -47,6 +53,7 @@ def wiki_search(query: str) -> str:
|
|
| 47 |
|
| 48 |
@tool
|
| 49 |
def arxiv_search(query: str) -> str:
|
|
|
|
| 50 |
search_docs = ArxivLoader(query=query, load_max_docs=3).load()
|
| 51 |
formatted = "\n\n---\n\n".join(
|
| 52 |
[f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}">\n{doc.page_content[:1000]}\n</Document>' for doc in search_docs]
|
|
@@ -55,7 +62,7 @@ def arxiv_search(query: str) -> str:
|
|
| 55 |
|
| 56 |
@tool
|
| 57 |
def web_search(query: str) -> str:
|
| 58 |
-
"""
|
| 59 |
with DDGS() as ddgs:
|
| 60 |
results = ddgs.text(query, max_results=5)
|
| 61 |
if not results:
|
|
|
|
| 17 |
# --- Tools ---
|
| 18 |
@tool
|
| 19 |
def multiply(a: int, b: int) -> int:
|
| 20 |
+
"""Multiplies two integers and returns the result."""
|
| 21 |
return a * b
|
| 22 |
|
| 23 |
@tool
|
| 24 |
def add(a: int, b: int) -> int:
|
| 25 |
+
"""Adds two integers and returns the result."""
|
| 26 |
return a + b
|
| 27 |
|
| 28 |
@tool
|
| 29 |
def subtract(a: int, b: int) -> int:
|
| 30 |
+
"""Subtracts the second integer from the first."""
|
| 31 |
return a - b
|
| 32 |
|
| 33 |
@tool
|
| 34 |
def divide(a: int, b: int) -> float:
|
| 35 |
+
"""Divides the first integer by the second, returns float."""
|
| 36 |
if b == 0:
|
| 37 |
raise ValueError("Cannot divide by zero.")
|
| 38 |
return a / b
|
| 39 |
|
| 40 |
@tool
|
| 41 |
def modulo(a: int, b: int) -> int:
|
| 42 |
+
"""Returns the remainder of the division of two integers."""
|
| 43 |
return a % b
|
| 44 |
|
| 45 |
@tool
|
| 46 |
def wiki_search(query: str) -> str:
|
| 47 |
+
"""Search Wikipedia for a given query and return up to 2 results formatted."""
|
| 48 |
search_docs = WikipediaLoader(query=query, load_max_docs=2).load()
|
| 49 |
formatted = "\n\n---\n\n".join(
|
| 50 |
[f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}">\n{doc.page_content}\n</Document>' for doc in search_docs]
|
|
|
|
| 53 |
|
| 54 |
@tool
|
| 55 |
def arxiv_search(query: str) -> str:
|
| 56 |
+
"""Search Arxiv for a given query and return up to 3 results formatted."""
|
| 57 |
search_docs = ArxivLoader(query=query, load_max_docs=3).load()
|
| 58 |
formatted = "\n\n---\n\n".join(
|
| 59 |
[f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}">\n{doc.page_content[:1000]}\n</Document>' for doc in search_docs]
|
|
|
|
| 62 |
|
| 63 |
@tool
|
| 64 |
def web_search(query: str) -> str:
|
| 65 |
+
"""Search DuckDuckGo (for websearch) for a query and return up to 5 links."""
|
| 66 |
with DDGS() as ddgs:
|
| 67 |
results = ddgs.text(query, max_results=5)
|
| 68 |
if not results:
|