File size: 1,931 Bytes
7fb1978 |
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
import requests
import os
import json
# API base URL
BASE_URL = "https://agents-course-unit4-scoring.hf.space"
import os
def get_hf_username():
"""
Gets Hugging Face username for submission.
"""
return os.environ.get("HF_USERNAME", "shrutikaP8497") # replace with your HF username
def get_code_link():
"""
Returns the public URL to the Hugging Face Space code.
"""
return "https://huggingface.co/spaces/shrutikaP8497/gaia_agent_code"
def download_task_file(task_id, save_dir="downloads"):
"""
Downloads a file associated with a task from the GAIA evaluation API.
"""
os.makedirs(save_dir, exist_ok=True)
url = f"{BASE_URL}/files/{task_id}"
response = requests.get(url)
if response.status_code == 200:
filename = os.path.join(save_dir, task_id)
with open(filename, "wb") as f:
f.write(response.content)
return filename
else:
print(f"Failed to download file for task {task_id}")
return None
def format_answer(agent_output):
"""
Format the agent's response to meet submission requirements:
- Do NOT include 'FINAL ANSWER'
- Must be a concise string or comma-separated list
"""
if isinstance(agent_output, str):
return agent_output.strip()
elif isinstance(agent_output, list):
return ", ".join(map(str, agent_output))
elif isinstance(agent_output, (int, float)):
return str(agent_output)
else:
return str(agent_output)
def log_submission(task_id, answer, reasoning_trace=None, save_path="submission_log.jsonl"):
"""
Log the task_id and answer for debugging/submission traceability.
"""
entry = {
"task_id": task_id,
"submitted_answer": answer,
}
if reasoning_trace:
entry["reasoning_trace"] = reasoning_trace
with open(save_path, "a") as f:
f.write(json.dumps(entry) + "\n")
|