| |
| """Tool set add-on per smolagents: Wikipedia e arXiv.""" |
| from smolagents import Tool |
| import wikipedia, arxiv |
|
|
| class WikipediaTool(Tool): |
| name = "wiki" |
| description = "Return full content of the most relevant Wikipedia page for the query." |
|
|
| def __call__(self, query: str) -> str: |
| try: |
| page = wikipedia.page(query, auto_suggest=True, redirect=True) |
| return page.content |
| except (wikipedia.PageError, wikipedia.DisambiguationError) as e: |
| return f"WIKI_ERROR: {e}" |
|
|
| class ArxivTool(Tool): |
| name = "arxiv" |
| description = "Return title and abstract of the most recent arXiv paper matching the query." |
|
|
| def __call__(self, query: str) -> str: |
| search = arxiv.Search( |
| query=query, |
| max_results=1, |
| sort_by=arxiv.SortCriterion.SubmittedDate |
| ) |
| paper = next(search.results(), None) |
| if paper: |
| return f"{paper.title}\n{paper.summary}" |
| return "ARXIV_NOTHING_FOUND" |
|
|