Spaces:
Sleeping
Sleeping
File size: 2,214 Bytes
c216f4b 70b0f89 c216f4b efa0ab7 70b0f89 c216f4b 70b0f89 efa0ab7 70b0f89 d3f09f9 70b0f89 c216f4b 70b0f89 434f948 70b0f89 d3f09f9 70b0f89 efa0ab7 70b0f89 efa0ab7 70b0f89 c216f4b d3f09f9 70b0f89 c216f4b efa0ab7 c216f4b 434f948 70b0f89 efa0ab7 434f948 c216f4b 70b0f89 efa0ab7 c216f4b efa0ab7 |
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 |
import os
import requests
from smolagents import CodeAgent, tool, OpenAIServerModel
# ------------------------
# Constants
# ------------------------
API_URL = "https://agents-course-unit4-scoring.hf.space"
# ------------------------
# Tool definitions
# ------------------------
@tool
def fetch_questions() -> list:
"""
Fetch the full list of GAIA evaluation questions.
:return: A list of question dicts, each with 'task_id' and 'question'.
"""
resp = requests.get(f"{API_URL}/questions", timeout=15)
resp.raise_for_status()
return resp.json()
@tool
def fetch_random_question() -> dict:
"""
Fetch a single random GAIA question.
:return: A dict with keys 'task_id' and 'question'.
"""
resp = requests.get(f"{API_URL}/random-question", timeout=15)
resp.raise_for_status()
return resp.json()
@tool
def submit_answers(
username: str,
agent_code: str,
answers: list
) -> dict:
"""
Submit the agent's answers to GAIA and get the scoring.
:param username: The Hugging Face username for identifying the submission.
:param agent_code: URL to your Space code (for verification purposes).
:param answers: List of dicts each with 'task_id' and 'submitted_answer'.
:return: A dict containing 'score', 'correct_count', 'total_attempted', 'message', etc.
"""
payload = {
"username": username,
"agent_code": agent_code,
"answers": answers
}
resp = requests.post(f"{API_URL}/submit", json=payload, timeout=60)
resp.raise_for_status()
return resp.json()
def create_agent() -> CodeAgent:
"""
Build and return a configured CodeAgent using OpenAI GPT-3.5 Turbo.
Requires OPENAI_API_KEY in the environment.
"""
model = OpenAIServerModel(model_name="gpt-3.5-turbo")
agent = CodeAgent(
tools=[
fetch_questions,
fetch_random_question,
submit_answers, # fetch_file è stato rimosso
],
model=model,
prompt_template=(
"Here is a GAIA question:\n"
"{question}\n"
"Provide ONLY the exact answer (exact-match), with no extra text."
)
)
return agent
|