Spaces:
Sleeping
Sleeping
Update tools.py
Browse files
tools.py
CHANGED
|
@@ -210,3 +210,31 @@ def search_papers(query: str) -> str:
|
|
| 210 |
|
| 211 |
except Exception as e:
|
| 212 |
return f"Error fetching papers: {e}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
|
| 211 |
except Exception as e:
|
| 212 |
return f"Error fetching papers: {e}"
|
| 213 |
+
|
| 214 |
+
@tool
|
| 215 |
+
def download_file(task_id: str) -> str:
|
| 216 |
+
"""
|
| 217 |
+
Downloads a file associated with the given task ID.
|
| 218 |
+
Returns the file path where the file is saved locally.
|
| 219 |
+
|
| 220 |
+
Args:
|
| 221 |
+
task_id: The task id to download attachment from.
|
| 222 |
+
"""
|
| 223 |
+
file_url = f"{DEFAULT_API_URL}/files/{task_id}"
|
| 224 |
+
local_file_path = f"downloads/{task_id}.file"
|
| 225 |
+
|
| 226 |
+
print(f"Downloading file for task ID {task_id} from {file_url}...")
|
| 227 |
+
try:
|
| 228 |
+
response = requests.get(file_url, stream=True, timeout=15)
|
| 229 |
+
response.raise_for_status()
|
| 230 |
+
|
| 231 |
+
os.makedirs("downloads", exist_ok=True)
|
| 232 |
+
with open(local_file_path, "wb") as file:
|
| 233 |
+
for chunk in response.iter_content(chunk_size=8192):
|
| 234 |
+
file.write(chunk)
|
| 235 |
+
|
| 236 |
+
print(f"File downloaded successfully: {local_file_path}")
|
| 237 |
+
return local_file_path
|
| 238 |
+
except requests.exceptions.RequestException as e:
|
| 239 |
+
print(f"Error downloading file for task {task_id}: {e}")
|
| 240 |
+
raise
|