Spaces:
Sleeping
Sleeping
Update tools/search_tool.py
Browse files- 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
|
| 11 |
-
|
| 12 |
Returns:
|
| 13 |
-
str:
|
| 14 |
"""
|
|
|
|
| 15 |
with DDGS() as ddgs:
|
| 16 |
-
results = ddgs.text(
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
| 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."
|