File size: 1,552 Bytes
bf9fb98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# api_client.py
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}")