| |
| from smolagents import Tool |
| import wikipedia, arxiv |
|
|
| MAX_CHARS = 20_000 |
|
|
| class WikipediaTool(Tool): |
| name = "wiki" |
| description = "Return full content (truncated) of the most relevant Wikipedia page." |
|
|
| def __call__(self, query: str) -> str: |
| try: |
| page = wikipedia.page(query, auto_suggest=True, redirect=True) |
| return page.content[:MAX_CHARS] |
| except (wikipedia.PageError, wikipedia.DisambiguationError): |
| return "" |
|
|
| class ArxivTool(Tool): |
| name = "arxiv" |
| description = "Return title + abstract of the most recent arXiv paper that matches 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) |
| return f"{paper.title}\n{paper.summary}" if paper else "" |
|
|