File size: 633 Bytes
073ead7
148d441
 
0eaebbd
f84bc7f
148d441
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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."

    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}"