Spaces:
Runtime error
Runtime error
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
from dotenv import load_dotenv
|
| 3 |
-
|
| 4 |
load_dotenv()
|
| 5 |
|
| 6 |
# --- Supabase Setup (only if credentials are provided) ---
|
|
@@ -71,19 +71,32 @@ def wiki_search(query: str) -> str:
|
|
| 71 |
|
| 72 |
@tool
|
| 73 |
def web_search(query: str) -> str:
|
| 74 |
-
"""
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
|
| 88 |
@tool
|
| 89 |
def arxiv_search(query: str) -> str:
|
|
|
|
| 1 |
import os
|
| 2 |
from dotenv import load_dotenv
|
| 3 |
+
from duckduckgo_search import ddg
|
| 4 |
load_dotenv()
|
| 5 |
|
| 6 |
# --- Supabase Setup (only if credentials are provided) ---
|
|
|
|
| 71 |
|
| 72 |
@tool
|
| 73 |
def web_search(query: str) -> str:
|
| 74 |
+
"""
|
| 75 |
+
Search the web using DuckDuckGo and return the top 3 results
|
| 76 |
+
(title, URL, and snippet).
|
| 77 |
+
"""
|
| 78 |
+
results = ddg(query, max_results=3) or []
|
| 79 |
+
formatted = []
|
| 80 |
+
for r in results:
|
| 81 |
+
title = r.get("title", "").strip()
|
| 82 |
+
url = r.get("href", "").strip()
|
| 83 |
+
body = r.get("body", "").strip()
|
| 84 |
+
formatted.append(f"• **{title}**\n {url}\n _{body}_")
|
| 85 |
+
return "\n\n".join(formatted)
|
| 86 |
+
# def web_search(query: str) -> str:
|
| 87 |
+
# """Search the web using Tavily and return up to 3 results"""
|
| 88 |
+
# try:
|
| 89 |
+
# tavily_api_key = os.getenv("TAVILY_API_KEY")
|
| 90 |
+
# if not tavily_api_key:
|
| 91 |
+
# return "Web search unavailable: TAVILY_API_KEY not configured"
|
| 92 |
|
| 93 |
+
# search_tool = TavilySearchResults(max_results=3, api_key=tavily_api_key)
|
| 94 |
+
# docs = search_tool.invoke({"query": query})
|
| 95 |
+
# return "\n\n---\n\n".join(
|
| 96 |
+
# f'<Document source="{doc.get("url", "Unknown")}"/>\n{doc.get("content", "")}' for doc in docs
|
| 97 |
+
# )
|
| 98 |
+
# except Exception as e:
|
| 99 |
+
# return f"Web search failed: {str(e)}"
|
| 100 |
|
| 101 |
@tool
|
| 102 |
def arxiv_search(query: str) -> str:
|