notsakeeb commited on
Commit
e96192c
·
verified ·
1 Parent(s): 9d29a37

Create utils.py

Browse files
Files changed (1) hide show
  1. utils.py +34 -0
utils.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import re
3
+ from pathlib import Path
4
+ from typing import Any
5
+
6
+ import requests
7
+
8
+
9
+ class GaiaClient:
10
+ """
11
+ Client for GAIA API, as defined in https://huggingface.co/learn/agents-course/en/unit4/hands-on.
12
+ """
13
+
14
+ def __init__(
15
+ self,
16
+ target: Path,
17
+ username: str = None,
18
+ space_id: str = None,
19
+ api_url: str = "https://agents-course-unit4-scoring.hf.space",
20
+ ):
21
+ self.target = target
22
+ self.target.mkdir(exist_ok=True)
23
+ self.api_url = api_url
24
+ self.username = username
25
+ self.agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
26
+
27
+ def download_file_for_task(self, task_id: str, filename: str) -> Path:
28
+ file_url = f"{self.api_url}/files/{task_id}"
29
+
30
+ r = requests.get(file_url, timeout=15, allow_redirects=True)
31
+ with open(self.target / filename, "wb") as fp:
32
+ fp.write(r.content)
33
+
34
+ return self.target / filename