Spaces:
Sleeping
Sleeping
| from smolagents import tool | |
| from duckduckgo_search import DDGS | |
| def web_search(query: str) -> str: | |
| """ | |
| Search the web for factual answers about the query using DuckDuckGo. | |
| Args: | |
| query (str): The question or search term to look up. | |
| Returns: | |
| str: Relevant information extracted from search results, preferably from Wikipedia. | |
| """ | |
| refined = f"{query} site:en.wikipedia.org" | |
| with DDGS() as ddgs: | |
| results = ddgs.text(refined) | |
| for r in results[:5]: | |
| snippet = r.get("body") or r.get("content") or "" | |
| if snippet: | |
| return f"{snippet}\n\nSource: [{r['href']}]({r['href']})" | |
| return "Could not find a direct answer from Wikipedia." | |