Spaces:
Sleeping
Sleeping
Download agentsTools/tool_fetch_task_file.py from Adex2121/AgentCourseFinal: direct link, hf CLI and curl.
- Browser
- Download file 1.08 kB
-
https://huggingface.co/spaces/Adex2121/AgentCourseFinal/resolve/803cba5a31c124fddfd1f4ffbd12c5fca18ffedb/agentsTools/tool_fetch_task_file.py
- Command line
-
hf download hf://spaces/Adex2121/AgentCourseFinal@803cba5a31c124fddfd1f4ffbd12c5fca18ffedb/agentsTools/tool_fetch_task_file.py
-
curl -L -o tool_fetch_task_file.py https://huggingface.co/spaces/Adex2121/AgentCourseFinal/resolve/803cba5a31c124fddfd1f4ffbd12c5fca18ffedb/agentsTools/tool_fetch_task_file.py
1.08 kB
| from smolagents import tool | |
| import os | |
| import requests | |
| DEFAULT_API_URL = os.getenv("AGENT_API_URL", "https://agents-course-unit4-scoring.hf.space") | |
| def fetch_task_file(task_id: str) -> dict: | |
| """ | |
| Fetches the file associated with a task ID using the API URL from env. | |
| Args: | |
| task_id: The task ID to fetch. | |
| Returns: | |
| dict: task_id, content, status | |
| """ | |
| full_url = f"{DEFAULT_API_URL}/files/{task_id}" | |
| print(f"📥 Tool:fetch_task_file requesting {full_url}") | |
| try: | |
| response = requests.get(full_url, timeout=10) | |
| if response.status_code == 200: | |
| return { | |
| "task_id": task_id, | |
| "content": response.text[:5000], | |
| "status": "Success" | |
| } | |
| return { | |
| "task_id": task_id, | |
| "content": "", | |
| "status": f"{response.status_code} - {response.reason}" | |
| } | |
| except Exception as e: | |
| return { | |
| "task_id": task_id, | |
| "content": "", | |
| "status": f"Error: {str(e)}" | |
| } | |