Spaces:
Sleeping
Sleeping
from smolagents.tools import Tool | |
import wikipedia | |
#@tool | |
class WikipediaLookupTool(Tool): | |
name = "wikipedia_lookup" | |
description = "Look up content from the English Wikipedia based on a query string." | |
inputs = { | |
'query': { | |
'type': 'string', | |
'description': 'The search term to look up on Wikipedia.' | |
} | |
} | |
output_type = "string" | |
def forward(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}" | |
def __init__(self, *args, **kwargs): | |
self.is_initialized = False |