File size: 1,094 Bytes
aa31d0d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from smolagents import Tool
from typing import Any, Optional

class SimpleTool(Tool):
    name = "search_arxiv"
    description = "Searches for the most recent article on arXiv related to the given search term."
    inputs = {"search_term":{"type":"string","description":"A keyword or phrase used to find relevant articles on arXiv."}}
    output_type = "string"

    def forward(self, search_term:str)-> str: #it's import to specify the return type
        """
        Searches for the most recent article on arXiv related to the given search term.
        Args:
            search_term: A keyword or phrase used to find relevant articles on arXiv.
        """
        import requests
        formatted_search_term = search_term.replace(" ", "+")
        url = f"http://export.arxiv.org/api/query?search_query=all:\'{formatted_search_term}\'&sortBy=lastUpdatedDate&sortOrder=descending"
        #data = urllib.request.urlopen(url)
        data = requests.get(url)
        arxiv_result = data.read().decode('utf-8')
        return f"The most recent article on {search_term:} is: {arxiv_result}"