Spaces:
Sleeping
Sleeping
File size: 2,935 Bytes
e51386e 8ac5ef4 580bcf5 8ac5ef4 580bcf5 d5a26c7 e51386e 8ac5ef4 580bcf5 8ac5ef4 580bcf5 8ac5ef4 580bcf5 e51386e |
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File: utils/gaia_api.py
import requests
from typing import List, Dict, Optional
import json
class GaiaAPI:
"""Client for interacting with GAIA Benchmark API"""
# Fixed API endpoint
BASE_URL = "https://agents-course-unit4-scoring.hf.space"
@classmethod
def get_questions(cls) -> List[Dict]:
"""Fetch all GAIA questions"""
try:
response = requests.get(f"{cls.BASE_URL}/questions")
response.raise_for_status()
return response.json()
except Exception as e:
print(f"Error fetching questions: {str(e)}")
# Return sample questions for testing
return cls._get_sample_questions()
@classmethod
def get_random_question(cls) -> Dict:
"""Get a single random question"""
try:
response = requests.get(f"{cls.BASE_URL}/random-question")
response.raise_for_status()
return response.json()
except Exception as e:
print(f"Error fetching random question: {str(e)}")
return cls._get_sample_questions()[0]
@classmethod
def get_file(cls, task_id: str) -> bytes:
"""Download file associated with task"""
try:
response = requests.get(f"{cls.BASE_URL}/files/{task_id}")
response.raise_for_status()
return response.content
except Exception as e:
print(f"Error fetching file for task {task_id}: {str(e)}")
return b""
@classmethod
def submit_answers(cls, username: str, agent_code: str, answers: List[Dict]) -> Dict:
"""Submit answers to GAIA for scoring"""
try:
payload = {
"username": username,
"agent_code": agent_code,
"answers": answers
}
response = requests.post(f"{cls.BASE_URL}/submit", json=payload)
response.raise_for_status()
return response.json()
except Exception as e:
print(f"Error submitting answers: {str(e)}")
return {"error": str(e), "score": 0}
@classmethod
def _get_sample_questions(cls) -> List[Dict]:
"""Sample questions for testing when API is unavailable"""
return [
{
"task_id": "sample_001",
"question": "What is the capital of France?",
"level": 1,
"final_answer": "Paris"
},
{
"task_id": "sample_002",
"question": "Calculate 15 * 8 + 7",
"level": 1,
"final_answer": "127"
},
{
"task_id": "sample_003",
"question": "Name three programming languages commonly used for web development",
"level": 1,
"final_answer": "JavaScript, Python, PHP"
}
] |