Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
@@ -15,22 +15,30 @@ def fetch_questions() -> list:
|
|
15 |
"""
|
16 |
Fetch the full list of GAIA evaluation questions.
|
17 |
|
18 |
-
:
|
|
|
|
|
|
|
|
|
19 |
"""
|
20 |
-
|
21 |
-
|
22 |
-
return
|
23 |
|
24 |
@tool
|
25 |
def fetch_random_question() -> dict:
|
26 |
"""
|
27 |
Fetch a single random GAIA question.
|
28 |
|
29 |
-
:
|
|
|
|
|
|
|
|
|
30 |
"""
|
31 |
-
|
32 |
-
|
33 |
-
return
|
34 |
|
35 |
@tool
|
36 |
def submit_answers(
|
@@ -39,34 +47,42 @@ def submit_answers(
|
|
39 |
answers: list
|
40 |
) -> dict:
|
41 |
"""
|
42 |
-
Submit the agent's answers to GAIA and
|
43 |
|
44 |
-
:
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
48 |
"""
|
49 |
payload = {
|
50 |
"username": username,
|
51 |
"agent_code": agent_code,
|
52 |
"answers": answers
|
53 |
}
|
54 |
-
|
55 |
-
|
56 |
-
return
|
57 |
|
|
|
|
|
|
|
58 |
def create_agent() -> CodeAgent:
|
59 |
"""
|
60 |
Build and return a configured CodeAgent using OpenAI GPT-3.5 Turbo.
|
61 |
-
Requires OPENAI_API_KEY
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
"""
|
63 |
model = OpenAIServerModel(model_name="gpt-3.5-turbo")
|
64 |
agent = CodeAgent(
|
65 |
-
tools=[
|
66 |
-
fetch_questions,
|
67 |
-
fetch_random_question,
|
68 |
-
submit_answers,
|
69 |
-
],
|
70 |
model=model,
|
71 |
prompt_template=(
|
72 |
"Here is a GAIA question:\n"
|
|
|
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 |
+
response = requests.get(f"{API_URL}/questions", timeout=15)
|
25 |
+
response.raise_for_status()
|
26 |
+
return response.json()
|
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 containing 'task_id' and 'question'.
|
38 |
"""
|
39 |
+
response = requests.get(f"{API_URL}/random-question", timeout=15)
|
40 |
+
response.raise_for_status()
|
41 |
+
return response.json()
|
42 |
|
43 |
@tool
|
44 |
def submit_answers(
|
|
|
47 |
answers: list
|
48 |
) -> dict:
|
49 |
"""
|
50 |
+
Submit the agent's answers to GAIA and retrieve scoring.
|
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 purposes.
|
55 |
+
answers (list): List of dicts, each with 'task_id' and 'submitted_answer'.
|
56 |
+
|
57 |
+
Returns:
|
58 |
+
dict: Contains 'score', 'correct_count', 'total_attempted', 'message', and other metadata.
|
59 |
"""
|
60 |
payload = {
|
61 |
"username": username,
|
62 |
"agent_code": agent_code,
|
63 |
"answers": answers
|
64 |
}
|
65 |
+
response = requests.post(f"{API_URL}/submit", json=payload, timeout=60)
|
66 |
+
response.raise_for_status()
|
67 |
+
return response.json()
|
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 the environment variable OPENAI_API_KEY to be set.
|
76 |
+
|
77 |
+
Args:
|
78 |
+
None
|
79 |
+
|
80 |
+
Returns:
|
81 |
+
CodeAgent: A SmolAgents CodeAgent instance with configured tools and prompt.
|
82 |
"""
|
83 |
model = OpenAIServerModel(model_name="gpt-3.5-turbo")
|
84 |
agent = CodeAgent(
|
85 |
+
tools=[fetch_questions, fetch_random_question, submit_answers],
|
|
|
|
|
|
|
|
|
86 |
model=model,
|
87 |
prompt_template=(
|
88 |
"Here is a GAIA question:\n"
|