Spaces:
Sleeping
Sleeping
File size: 896 Bytes
073ead7 148d441 0eaebbd f84bc7f 148d441 47f6d65 c25a1a2 148d441 c25a1a2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
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 |