Spaces:
Sleeping
Sleeping
File size: 1,076 Bytes
796c04e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
from smolagents import tool
import os
import requests
DEFAULT_API_URL = os.getenv("AGENT_API_URL", "https://agents-course-unit4-scoring.hf.space")
@tool
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)}"
} |