wt002 commited on
Commit
a10617a
·
verified ·
1 Parent(s): 1461753

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py CHANGED
@@ -112,6 +112,45 @@ Answer:"""
112
  except Exception:
113
  return f"Error executing code:\n{traceback.format_exc()}"
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
  from transformers import pipeline
117
  from smolagents import Tool
 
112
  except Exception:
113
  return f"Error executing code:\n{traceback.format_exc()}"
114
 
115
+ import requests
116
+ from smolagents import Tool
117
+
118
+ class ArxivSearchTool(Tool):
119
+ name = "arxiv_search"
120
+ description = "Search Arxiv for papers matching a query and return titles and links."
121
+ inputs = {
122
+ "query": {"type": "string", "description": "Search query for Arxiv papers"}
123
+ }
124
+ output_type = "string"
125
+
126
+ def forward(self, query: str) -> str:
127
+ url = "http://export.arxiv.org/api/query"
128
+ params = {
129
+ "search_query": query,
130
+ "start": 0,
131
+ "max_results": 3,
132
+ "sortBy": "relevance",
133
+ "sortOrder": "descending"
134
+ }
135
+ try:
136
+ response = requests.get(url, params=params, timeout=10)
137
+ response.raise_for_status()
138
+ # Simple parse titles and links (basic, for demo)
139
+ import xml.etree.ElementTree as ET
140
+ root = ET.fromstring(response.content)
141
+ ns = {"atom": "http://www.w3.org/2005/Atom"}
142
+
143
+ entries = root.findall("atom:entry", ns)
144
+ results = []
145
+ for entry in entries:
146
+ title = entry.find("atom:title", ns).text.strip().replace('\n', ' ')
147
+ link = entry.find("atom:id", ns).text.strip()
148
+ results.append(f"{title}\n{link}")
149
+ return "\n\n".join(results) if results else "No results found."
150
+ except Exception as e:
151
+ return f"Error during Arxiv search: {e}"
152
+
153
+
154
 
155
  from transformers import pipeline
156
  from smolagents import Tool