Aya1610 commited on
Commit
b0d7736
·
verified ·
1 Parent(s): cbfa38d

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +26 -13
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
- """Search the web using Tavily and return up to 3 results"""
75
- try:
76
- tavily_api_key = os.getenv("TAVILY_API_KEY")
77
- if not tavily_api_key:
78
- return "Web search unavailable: TAVILY_API_KEY not configured"
 
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
- search_tool = TavilySearchResults(max_results=3, api_key=tavily_api_key)
81
- docs = search_tool.invoke({"query": query})
82
- return "\n\n---\n\n".join(
83
- f'<Document source="{doc.get("url", "Unknown")}"/>\n{doc.get("content", "")}' for doc in docs
84
- )
85
- except Exception as e:
86
- return f"Web search failed: {str(e)}"
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: