Thanh Vinh Vo
commited on
Commit
·
7eb4502
1
Parent(s):
7c71cec
update
Browse files
app.py
CHANGED
|
@@ -282,21 +282,22 @@ def get_wikipedia_section_tables(
|
|
| 282 |
|
| 283 |
|
| 284 |
@tool
|
| 285 |
-
def
|
| 286 |
"""
|
| 287 |
A tool that downloads file that was mentioned in a question and store it as local file.
|
|
|
|
| 288 |
Args:
|
| 289 |
question_id: Question ID.
|
| 290 |
file_name: File name.
|
| 291 |
Returns:
|
| 292 |
-
str: Local
|
| 293 |
"""
|
| 294 |
import os
|
| 295 |
|
| 296 |
import requests
|
| 297 |
|
| 298 |
url = f"{DEFAULT_API_URL}/files/{question_id}"
|
| 299 |
-
print(f"Fetching
|
| 300 |
|
| 301 |
# Create downloads directory if it doesn't exist
|
| 302 |
response = None
|
|
@@ -320,11 +321,11 @@ def get_file(question_id: str, file_name: str) -> str:
|
|
| 320 |
with open(local_path, "wb") as f:
|
| 321 |
f.write(response.content)
|
| 322 |
|
| 323 |
-
print(f"
|
| 324 |
return local_path
|
| 325 |
|
| 326 |
except requests.exceptions.RequestException as e:
|
| 327 |
-
raise ValueError(f"Failed to
|
| 328 |
except Exception as e:
|
| 329 |
# Print first 200 characters of response content for debugging
|
| 330 |
content_preview = (
|
|
@@ -332,7 +333,7 @@ def get_file(question_id: str, file_name: str) -> str:
|
|
| 332 |
if response and hasattr(response, "content")
|
| 333 |
else b"No response"
|
| 334 |
)
|
| 335 |
-
print(f"Error downloading
|
| 336 |
raise ValueError(f"Failed to download text file from {url}: {e}")
|
| 337 |
|
| 338 |
|
|
|
|
| 282 |
|
| 283 |
|
| 284 |
@tool
|
| 285 |
+
def download_file(question_id: str, file_name: str) -> str:
|
| 286 |
"""
|
| 287 |
A tool that downloads file that was mentioned in a question and store it as local file.
|
| 288 |
+
Note that user still need to read file from local file path returned from the function. This function DOES NOT return file content.
|
| 289 |
Args:
|
| 290 |
question_id: Question ID.
|
| 291 |
file_name: File name.
|
| 292 |
Returns:
|
| 293 |
+
str: Local path where the file was stored.
|
| 294 |
"""
|
| 295 |
import os
|
| 296 |
|
| 297 |
import requests
|
| 298 |
|
| 299 |
url = f"{DEFAULT_API_URL}/files/{question_id}"
|
| 300 |
+
print(f"Fetching file from URL: {url}")
|
| 301 |
|
| 302 |
# Create downloads directory if it doesn't exist
|
| 303 |
response = None
|
|
|
|
| 321 |
with open(local_path, "wb") as f:
|
| 322 |
f.write(response.content)
|
| 323 |
|
| 324 |
+
print(f"File saved to: {local_path}")
|
| 325 |
return local_path
|
| 326 |
|
| 327 |
except requests.exceptions.RequestException as e:
|
| 328 |
+
raise ValueError(f"Failed to text file from {url}: {e}")
|
| 329 |
except Exception as e:
|
| 330 |
# Print first 200 characters of response content for debugging
|
| 331 |
content_preview = (
|
|
|
|
| 333 |
if response and hasattr(response, "content")
|
| 334 |
else b"No response"
|
| 335 |
)
|
| 336 |
+
print(f"Error downloading file. Content preview: {content_preview}")
|
| 337 |
raise ValueError(f"Failed to download text file from {url}: {e}")
|
| 338 |
|
| 339 |
|