kpbotla commited on
Commit
0975dcb
·
verified ·
1 Parent(s): b2746c2

Update tools/search_tool.py

Browse files
Files changed (1) hide show
  1. tools/search_tool.py +8 -8
tools/search_tool.py CHANGED
@@ -4,15 +4,15 @@ from duckduckgo_search import DDGS
4
  @tool
5
  def web_search(query: str) -> str:
6
  """
7
- Returns top search results for a given query.
8
-
9
  Args:
10
- query (str): The search string.
11
-
12
  Returns:
13
- str: Top search results from DuckDuckGo.
14
  """
 
15
  with DDGS() as ddgs:
16
- results = ddgs.text(query)
17
- output = [f"{r['title']} - {r['href']}" for r in results[:3]]
18
- return "\n".join(output) if output else "No relevant results found."
 
 
 
4
  @tool
5
  def web_search(query: str) -> str:
6
  """
 
 
7
  Args:
8
+ query (str): The factual question to answer.
 
9
  Returns:
10
+ str: Extracted fact and URL.
11
  """
12
+ refined = f"{query} site:en.wikipedia.org"
13
  with DDGS() as ddgs:
14
+ results = ddgs.text(refined)
15
+ for r in results[:5]:
16
+ if "Mercedes Sosa" in r['body'] or "albums" in r['body']:
17
+ return f"{r['body']}\\n\\nSource: [{r['href']}]({r['href']})"
18
+ return "Could not find a direct answer from Wikipedia."