Spaces:
Sleeping
Sleeping
from smolagents import tool | |
import wikipedia | |
class WikipediaLookupTool: | |
name = "wikipedia_lookup" | |
description = "Look up content from the English Wikipedia based on a query string." | |
def __call__(self, query: str) -> str: | |
try: | |
page = wikipedia.page(query) | |
return page.content # full text | |
except wikipedia.DisambiguationError as e: | |
return f"Disambiguation error. Options: {e.options[:5]}" | |
except wikipedia.PageError: | |
return f"Page not found for: {query}" | |
except Exception as e: | |
return f"Unexpected error: {e}" |