import json import re from pathlib import Path from typing import Any import requests class GaiaClient: """ Client for GAIA API, as defined in https://huggingface.co/learn/agents-course/en/unit4/hands-on. """ def __init__( self, target: Path, username: str = None, space_id: str = None, api_url: str = "https://agents-course-unit4-scoring.hf.space", ): self.target = target self.target.mkdir(exist_ok=True) self.api_url = api_url self.username = username self.agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main" def download_file_for_task(self, task_id: str, filename: str) -> Path: file_url = f"{self.api_url}/files/{task_id}" r = requests.get(file_url, timeout=15, allow_redirects=True) with open(self.target / filename, "wb") as fp: fp.write(r.content) return self.target / filename