|
|
| import requests
|
|
|
| SCORING_API = "https://agents-course-unit4-scoring.hf.space"
|
|
|
| def get_all_questions() -> list[dict]:
|
| """
|
| Fetches all 20 Level 1 questions from the GAIA scoring API.
|
|
|
| Returns a list of dicts, each with:
|
| - task_id: str (unique ID for the question)
|
| - question: str (the question text)
|
| - file_name: str (filename of attached file, if any; else empty string)
|
| """
|
| response = requests.get(f"{SCORING_API}/questions", timeout=30)
|
| if response.status_code == 200:
|
| return response.json()
|
| else:
|
| raise Exception(f"Failed to fetch questions: {response.status_code}")
|
|
|
| def submit_answers(username: str, agent_code_url: str, answers: list[dict]) -> dict:
|
| """
|
| Submits answers to the GAIA API for scoring.
|
|
|
| Args:
|
| username: Your HuggingFace username.
|
| agent_code_url: URL to your HF Space code (e.g. https://huggingface.co/spaces/yourname/space/tree/main)
|
| answers: List of {"task_id": "...", "submitted_answer": "..."} dicts.
|
|
|
| Returns:
|
| A dict with your score and leaderboard position.
|
| """
|
| payload = {
|
| "username": username,
|
| "agent_code": agent_code_url,
|
| "answers": answers
|
| }
|
| response = requests.post(f"{SCORING_API}/submit", json=payload, timeout=60)
|
| if response.status_code == 200:
|
| return response.json()
|
| else:
|
| raise Exception(f"Submission failed: {response.status_code} — {response.text}") |