Spaces:
Sleeping
Sleeping
File size: 1,495 Bytes
3af908f | 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 | """Course scoring API client (no GAIA dataset download)."""
from __future__ import annotations
import os
from pathlib import Path
import requests
DEFAULT_API_URL = os.getenv(
"COURSE_API_URL", "https://agents-course-unit4-scoring.hf.space"
)
def fetch_course_questions(api_url: str = DEFAULT_API_URL) -> list[dict]:
response = requests.get(f"{api_url.rstrip('/')}/questions", timeout=15)
response.raise_for_status()
return response.json()
def fetch_random_question(api_url: str = DEFAULT_API_URL) -> dict:
response = requests.get(f"{api_url.rstrip('/')}/random-question", timeout=15)
response.raise_for_status()
return response.json()
def download_attachment(
api_url: str,
task_id: str,
file_name: str,
dest_dir: Path,
) -> Path:
dest_dir.mkdir(parents=True, exist_ok=True)
destination = dest_dir / file_name
response = requests.get(
f"{api_url.rstrip('/')}/files/{task_id}",
timeout=60,
)
response.raise_for_status()
destination.write_bytes(response.content)
return destination
def submit_answers(
api_url: str,
username: str,
agent_code: str,
answers: list[dict],
) -> dict:
payload = {
"username": username.strip(),
"agent_code": agent_code,
"answers": answers,
}
response = requests.post(
f"{api_url.rstrip('/')}/submit",
json=payload,
timeout=120,
)
response.raise_for_status()
return response.json()
|