Spaces:
Sleeping
Sleeping
Fetch arxiv
Browse files
agent.py
CHANGED
|
@@ -108,6 +108,50 @@ def web_search(query: str) -> dict:
|
|
| 108 |
)
|
| 109 |
return {"web_results" : formatted_search_docs}
|
| 110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
@tool
|
| 112 |
def arxiv_search(query: str) -> dict:
|
| 113 |
"""
|
|
@@ -454,7 +498,7 @@ create_retriever_tool = create_retriever_tool(
|
|
| 454 |
|
| 455 |
tools = [
|
| 456 |
add, subtract, multiply, divide, modulus,
|
| 457 |
-
web_search, wiki_search, arxiv_search,
|
| 458 |
read_file, get_youtube_transcript,
|
| 459 |
download_file_from_url, save_and_read_file,
|
| 460 |
# extract_text_from_image, analyze_csv_file, analyze_excel_file, analyze_image, transform_image,
|
|
|
|
| 108 |
)
|
| 109 |
return {"web_results" : formatted_search_docs}
|
| 110 |
|
| 111 |
+
@tool
|
| 112 |
+
def fetch_arxiv_paper(paper_id_or_url: str) -> dict:
|
| 113 |
+
"""
|
| 114 |
+
Fetches a specific Arxiv paper when given its unique ID (e.g., '2001.08361') or its full URL.
|
| 115 |
+
Use this tool when the user provides a direct link or paper ID.
|
| 116 |
+
Args:
|
| 117 |
+
paper_id_or_url: The Arxiv ID or the full URL of the paper.
|
| 118 |
+
"""
|
| 119 |
+
try:
|
| 120 |
+
# Use regex to find the Arxiv ID from a URL
|
| 121 |
+
# This looks for patterns like '2001.08361' or '1706.03762'
|
| 122 |
+
match = re.search(r'(\d{4}\.\d{4,5})', paper_id_or_url)
|
| 123 |
+
|
| 124 |
+
if match:
|
| 125 |
+
paper_id = match.group(1)
|
| 126 |
+
else:
|
| 127 |
+
# Assume the input is already just the ID
|
| 128 |
+
paper_id = paper_id_or_url
|
| 129 |
+
|
| 130 |
+
# Use the extracted ID to load the specific document
|
| 131 |
+
loader = ArxivLoader(query=paper_id, load_max_docs=1)
|
| 132 |
+
docs = loader.load()
|
| 133 |
+
|
| 134 |
+
if not docs:
|
| 135 |
+
return {"error": f"Could not find a paper with ID: {paper_id}"}
|
| 136 |
+
|
| 137 |
+
# Format the output using the structured method
|
| 138 |
+
doc = docs[0]
|
| 139 |
+
title = doc.metadata.get('Title', 'No Title Found')
|
| 140 |
+
authors = doc.metadata.get('Authors', 'No Authors Found')
|
| 141 |
+
summary = doc.metadata.get('Summary', 'No Summary Found').replace('\n', ' ')
|
| 142 |
+
|
| 143 |
+
doc_string = (
|
| 144 |
+
f"<Document>\n"
|
| 145 |
+
f" <Title>{title}</Title>\n"
|
| 146 |
+
f" <Authors>{authors}</Authors>\n"
|
| 147 |
+
f" <Summary>{summary}</Summary>\n"
|
| 148 |
+
f"</Document>"
|
| 149 |
+
)
|
| 150 |
+
return {"arxiv_paper": doc_string}
|
| 151 |
+
|
| 152 |
+
except Exception as e:
|
| 153 |
+
return {"error": f"Failed to fetch Arxiv paper: {str(e)}"}
|
| 154 |
+
|
| 155 |
@tool
|
| 156 |
def arxiv_search(query: str) -> dict:
|
| 157 |
"""
|
|
|
|
| 498 |
|
| 499 |
tools = [
|
| 500 |
add, subtract, multiply, divide, modulus,
|
| 501 |
+
web_search, wiki_search, arxiv_search, fetch_arxiv_paper
|
| 502 |
read_file, get_youtube_transcript,
|
| 503 |
download_file_from_url, save_and_read_file,
|
| 504 |
# extract_text_from_image, analyze_csv_file, analyze_excel_file, analyze_image, transform_image,
|