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

Update tools/search_tool.py

Browse files
Files changed (1) hide show
  1. tools/search_tool.py +9 -4
tools/search_tool.py CHANGED
@@ -1,18 +1,23 @@
1
  from smolagents import tool
2
  from duckduckgo_search import DDGS
3
 
 
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."
 
1
  from smolagents import tool
2
  from duckduckgo_search import DDGS
3
 
4
+
5
  @tool
6
  def web_search(query: str) -> str:
7
  """
8
+ Search the web for factual answers about the query using DuckDuckGo.
9
+
10
  Args:
11
+ query (str): The question or search term to look up.
12
+
13
  Returns:
14
+ str: Relevant information extracted from search results, preferably from Wikipedia.
15
  """
16
  refined = f"{query} site:en.wikipedia.org"
17
  with DDGS() as ddgs:
18
  results = ddgs.text(refined)
19
  for r in results[:5]:
20
+ snippet = r.get("body") or r.get("content") or ""
21
+ if snippet:
22
+ return f"{snippet}\n\nSource: [{r['href']}]({r['href']})"
23
  return "Could not find a direct answer from Wikipedia."