Spaces:
Runtime error
Runtime error
tools.py
CHANGED
|
@@ -310,22 +310,47 @@ web_search_tool = Tool(
|
|
| 310 |
)
|
| 311 |
|
| 312 |
def arvix_search(query: str) -> str:
|
| 313 |
-
"""Search Arxiv for a query and return maximum 3
|
| 314 |
|
| 315 |
Args:
|
| 316 |
-
query: The search query.
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 325 |
arvix_search_tool = Tool(
|
| 326 |
name="arvix_search",
|
| 327 |
func=arvix_search,
|
| 328 |
-
description="Searches for and retrieves information
|
| 329 |
)
|
| 330 |
|
| 331 |
def extract_image_text(img_path: str) -> str:
|
|
|
|
| 310 |
)
|
| 311 |
|
| 312 |
def arvix_search(query: str) -> str:
|
| 313 |
+
"""Search Arxiv for a query and return maximum 3 results.
|
| 314 |
|
| 315 |
Args:
|
| 316 |
+
query: The search query.
|
| 317 |
+
|
| 318 |
+
Returns:
|
| 319 |
+
Formatted string containing search results from Arxiv papers.
|
| 320 |
+
"""
|
| 321 |
+
try:
|
| 322 |
+
# Load documents from Arxiv
|
| 323 |
+
search_docs = ArxivLoader(query=query, load_max_docs=3).load()
|
| 324 |
+
|
| 325 |
+
# Check if we got any results
|
| 326 |
+
if not search_docs:
|
| 327 |
+
return "No results found for the query: " + query
|
| 328 |
+
|
| 329 |
+
# Process each document with safe metadata access
|
| 330 |
+
formatted_docs = []
|
| 331 |
+
for doc in search_docs:
|
| 332 |
+
# Use .get() method for safe dictionary access with fallback values
|
| 333 |
+
source = doc.metadata.get("source", "Unknown source")
|
| 334 |
+
page = doc.metadata.get("page", "N/A")
|
| 335 |
+
|
| 336 |
+
# Create the formatted document string
|
| 337 |
+
formatted_doc = f'<Document source="{source}" page="{page}"/>\n{doc.page_content[:1000]}\n</Document>'
|
| 338 |
+
formatted_docs.append(formatted_doc)
|
| 339 |
+
|
| 340 |
+
# Join all documents with separators
|
| 341 |
+
formatted_search_docs = "\n\n---\n\n".join(formatted_docs)
|
| 342 |
+
|
| 343 |
+
# Return the string directly (not wrapped in a dictionary)
|
| 344 |
+
return formatted_search_docs
|
| 345 |
+
|
| 346 |
+
except Exception as e:
|
| 347 |
+
# Handle any unexpected errors gracefully
|
| 348 |
+
return f"Error searching Arxiv: {str(e)}"
|
| 349 |
+
|
| 350 |
arvix_search_tool = Tool(
|
| 351 |
name="arvix_search",
|
| 352 |
func=arvix_search,
|
| 353 |
+
description="Searches for and retrieves information from Arxiv, a database storing scientific papers. Returns formatted text containing paper abstracts and metadata."
|
| 354 |
)
|
| 355 |
|
| 356 |
def extract_image_text(img_path: str) -> str:
|