""" Client for the Unit 4 scoring API used by the course (GAIA subset). Implements: GET /questions, GET /random-question, GET /files/{task_id}, POST /submit Base URL: https://agents-course-unit4-scoring.hf.space """ from typing import Any, Dict, List, Optional import requests class ScoringAPIClient: def __init__(self, base_url: str = "https://agents-course-unit4-scoring.hf.space"): self.base_url = base_url.rstrip("/") def _url(self, path: str) -> str: return f"{self.base_url}{path}" def get_questions(self) -> List[Dict[str, Any]]: resp = requests.get(self._url("/questions")) resp.raise_for_status() return resp.json() def get_random_question(self) -> Dict[str, Any]: resp = requests.get(self._url("/random-question")) resp.raise_for_status() return resp.json() def download_file(self, task_id: int, dest_path: str) -> None: resp = requests.get(self._url(f"/files/{task_id}"), stream=True) resp.raise_for_status() with open(dest_path, "wb") as f: for chunk in resp.iter_content(chunk_size=8192): if chunk: f.write(chunk) def submit(self, username: str, agent_code: str, answers: List[Dict[str, Any]]) -> Dict[str, Any]: payload = {"username": username, "agent_code": agent_code, "answers": answers} resp = requests.post(self._url("/submit"), json=payload) resp.raise_for_status() return resp.json() if __name__ == "__main__": c = ScoringAPIClient() qs = c.get_questions() print(f"Loaded {len(qs)} questions")