Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
@@ -15,72 +15,60 @@ def fetch_questions() -> list:
|
|
15 |
"""
|
16 |
Fetch the full list of GAIA evaluation questions.
|
17 |
|
18 |
-
Args:
|
19 |
-
None
|
20 |
-
|
21 |
Returns:
|
22 |
list: A list of question dicts, each with 'task_id' and 'question'.
|
23 |
"""
|
24 |
-
|
25 |
-
|
26 |
-
return
|
|
|
27 |
|
28 |
@tool
|
29 |
def fetch_random_question() -> dict:
|
30 |
"""
|
31 |
Fetch a single random GAIA question.
|
32 |
|
33 |
-
Args:
|
34 |
-
None
|
35 |
-
|
36 |
Returns:
|
37 |
-
dict: A dict
|
38 |
"""
|
39 |
-
|
40 |
-
|
41 |
-
return
|
|
|
42 |
|
43 |
@tool
|
44 |
-
def submit_answers(
|
45 |
-
username: str,
|
46 |
-
agent_code: str,
|
47 |
-
answers: list
|
48 |
-
) -> dict:
|
49 |
"""
|
50 |
-
Submit the agent's answers to GAIA and
|
51 |
|
52 |
Args:
|
53 |
username (str): The Hugging Face username identifying the submission.
|
54 |
-
agent_code (str): URL to your Space code repository for verification
|
55 |
-
answers (list):
|
56 |
|
57 |
Returns:
|
58 |
-
dict:
|
59 |
"""
|
60 |
payload = {
|
61 |
"username": username,
|
62 |
"agent_code": agent_code,
|
63 |
"answers": answers
|
64 |
}
|
65 |
-
|
66 |
-
|
67 |
-
return
|
|
|
68 |
|
69 |
-
# ------------------------
|
70 |
-
# Agent factory
|
71 |
-
# ------------------------
|
72 |
def create_agent() -> CodeAgent:
|
73 |
"""
|
74 |
Build and return a configured CodeAgent using OpenAI GPT-3.5 Turbo.
|
75 |
-
Requires
|
76 |
-
|
77 |
-
Args:
|
78 |
-
None
|
79 |
|
80 |
Returns:
|
81 |
-
CodeAgent:
|
82 |
"""
|
83 |
-
|
|
|
84 |
agent = CodeAgent(
|
85 |
tools=[fetch_questions, fetch_random_question, submit_answers],
|
86 |
model=model,
|
|
|
15 |
"""
|
16 |
Fetch the full list of GAIA evaluation questions.
|
17 |
|
|
|
|
|
|
|
18 |
Returns:
|
19 |
list: A list of question dicts, each with 'task_id' and 'question'.
|
20 |
"""
|
21 |
+
resp = requests.get(f"{API_URL}/questions", timeout=15)
|
22 |
+
resp.raise_for_status()
|
23 |
+
return resp.json()
|
24 |
+
|
25 |
|
26 |
@tool
|
27 |
def fetch_random_question() -> dict:
|
28 |
"""
|
29 |
Fetch a single random GAIA question.
|
30 |
|
|
|
|
|
|
|
31 |
Returns:
|
32 |
+
dict: A dict with keys 'task_id' and 'question'.
|
33 |
"""
|
34 |
+
resp = requests.get(f"{API_URL}/random-question", timeout=15)
|
35 |
+
resp.raise_for_status()
|
36 |
+
return resp.json()
|
37 |
+
|
38 |
|
39 |
@tool
|
40 |
+
def submit_answers(username: str, agent_code: str, answers: list) -> dict:
|
|
|
|
|
|
|
|
|
41 |
"""
|
42 |
+
Submit the agent's answers to GAIA and get the scoring.
|
43 |
|
44 |
Args:
|
45 |
username (str): The Hugging Face username identifying the submission.
|
46 |
+
agent_code (str): URL to your Space code repository for verification.
|
47 |
+
answers (list): A list of dicts, each with 'task_id' and 'submitted_answer'.
|
48 |
|
49 |
Returns:
|
50 |
+
dict: A dict containing 'score', 'correct_count', 'total_attempted', 'message', etc.
|
51 |
"""
|
52 |
payload = {
|
53 |
"username": username,
|
54 |
"agent_code": agent_code,
|
55 |
"answers": answers
|
56 |
}
|
57 |
+
resp = requests.post(f"{API_URL}/submit", json=payload, timeout=60)
|
58 |
+
resp.raise_for_status()
|
59 |
+
return resp.json()
|
60 |
+
|
61 |
|
|
|
|
|
|
|
62 |
def create_agent() -> CodeAgent:
|
63 |
"""
|
64 |
Build and return a configured CodeAgent using OpenAI GPT-3.5 Turbo.
|
65 |
+
Requires OPENAI_API_KEY in the environment.
|
|
|
|
|
|
|
66 |
|
67 |
Returns:
|
68 |
+
CodeAgent: An instance of CodeAgent configured with the GAIA tools.
|
69 |
"""
|
70 |
+
# Correctly pass the model_id parameter here:
|
71 |
+
model = OpenAIServerModel(model_id="gpt-3.5-turbo")
|
72 |
agent = CodeAgent(
|
73 |
tools=[fetch_questions, fetch_random_question, submit_answers],
|
74 |
model=model,
|