File size: 2,271 Bytes
f1acfc4 30d98fa f1acfc4 |
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
import importlib
__all__ = ['ArxivTool']
class ArxivTool():
dependencies = ["arxiv==2.1.3"]
inputSchema = {
"name": "ArxivTool",
"description": "Searches arXiv for academic papers based on a query.",
"parameters": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "Search query for papers on arXiv.",
"examples":[
"superconductors gem5",
"machine learning in healthcare",
"quantum computing algorithms"
]
},
"max_results": {
"type": "integer",
"description": "Maximum number of papers to retrieve. Default is 5.",
"default": 5
}
},
"required": ["query"],
}
}
def run(self, **kwargs):
query = kwargs.get("query")
max_results = kwargs.get("max_results", 5)
if not query:
return {
"status": "error",
"message": "Missing required parameter: 'query'",
"output": None
}
try:
arxiv = importlib.import_module("arxiv")
client = arxiv.Client()
search = arxiv.Search(
query=query,
max_results=max_results,
)
papers = []
for result in client.results(search):
papers.append({
"title": result.title,
"authors": [author.name for author in result.authors],
"published": result.published.isoformat(),
"summary": result.summary.strip(),
"pdf_url": result.pdf_url,
})
return {
"status": "success",
"message": f"Found {len(papers)} paper(s) on arXiv",
"output": papers,
}
except Exception as e:
return {
"status": "error",
"message": f"arXiv search failed: {str(e)}",
"output": None,
}
|