File size: 955 Bytes
e96192c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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