Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
@@ -15,7 +15,7 @@ def fetch_questions() -> list:
|
|
15 |
"""
|
16 |
Fetch the full list of GAIA evaluation questions.
|
17 |
|
18 |
-
:return:
|
19 |
"""
|
20 |
resp = requests.get(f"{API_URL}/questions", timeout=15)
|
21 |
resp.raise_for_status()
|
@@ -26,7 +26,7 @@ def fetch_random_question() -> dict:
|
|
26 |
"""
|
27 |
Fetch a single random GAIA question.
|
28 |
|
29 |
-
:return: A dict
|
30 |
"""
|
31 |
resp = requests.get(f"{API_URL}/random-question", timeout=15)
|
32 |
resp.raise_for_status()
|
@@ -37,8 +37,8 @@ def fetch_file(task_id: str) -> bytes:
|
|
37 |
"""
|
38 |
Download a file associated with a given GAIA task.
|
39 |
|
40 |
-
:param task_id: The
|
41 |
-
:return: Raw bytes of the file.
|
42 |
"""
|
43 |
resp = requests.get(f"{API_URL}/files/{task_id}", timeout=15)
|
44 |
resp.raise_for_status()
|
@@ -51,12 +51,12 @@ def submit_answers(
|
|
51 |
answers: list
|
52 |
) -> dict:
|
53 |
"""
|
54 |
-
Submit the agent's answers to GAIA and
|
55 |
|
56 |
-
:param username:
|
57 |
-
:param agent_code: URL to
|
58 |
-
:param answers: List of dicts each with 'task_id' and 'submitted_answer'.
|
59 |
-
:return: Dict with keys 'score', 'correct_count', 'total_attempted', 'message', etc.
|
60 |
"""
|
61 |
payload = {
|
62 |
"username": username,
|
@@ -67,20 +67,21 @@ def submit_answers(
|
|
67 |
resp.raise_for_status()
|
68 |
return resp.json()
|
69 |
|
70 |
-
|
71 |
def create_agent() -> CodeAgent:
|
72 |
"""
|
73 |
-
|
74 |
-
Expects OPENAI_API_KEY in the environment.
|
|
|
|
|
75 |
"""
|
76 |
-
|
77 |
agent = CodeAgent(
|
78 |
tools=[fetch_questions, fetch_random_question, fetch_file, submit_answers],
|
79 |
-
model=
|
80 |
prompt_template=(
|
81 |
"Here is a GAIA question:\n"
|
82 |
"{question}\n"
|
83 |
-
"
|
84 |
)
|
85 |
)
|
86 |
return agent
|
|
|
15 |
"""
|
16 |
Fetch the full list of GAIA evaluation questions.
|
17 |
|
18 |
+
:return: List of question dicts, each containing 'task_id' and 'question'.
|
19 |
"""
|
20 |
resp = requests.get(f"{API_URL}/questions", timeout=15)
|
21 |
resp.raise_for_status()
|
|
|
26 |
"""
|
27 |
Fetch a single random GAIA question.
|
28 |
|
29 |
+
:return: A dict with keys 'task_id' and 'question'.
|
30 |
"""
|
31 |
resp = requests.get(f"{API_URL}/random-question", timeout=15)
|
32 |
resp.raise_for_status()
|
|
|
37 |
"""
|
38 |
Download a file associated with a given GAIA task.
|
39 |
|
40 |
+
:param task_id: The GAIA task ID whose file should be downloaded.
|
41 |
+
:return: Raw bytes of the file content.
|
42 |
"""
|
43 |
resp = requests.get(f"{API_URL}/files/{task_id}", timeout=15)
|
44 |
resp.raise_for_status()
|
|
|
51 |
answers: list
|
52 |
) -> dict:
|
53 |
"""
|
54 |
+
Submit the agent's answers to the GAIA API and retrieve scoring results.
|
55 |
|
56 |
+
:param username: Hugging Face username for submission identification.
|
57 |
+
:param agent_code: URL linking to the code repository of this Space.
|
58 |
+
:param answers: List of dicts, each with 'task_id' and 'submitted_answer'.
|
59 |
+
:return: Dict with keys 'username', 'score', 'correct_count', 'total_attempted', 'message', etc.
|
60 |
"""
|
61 |
payload = {
|
62 |
"username": username,
|
|
|
67 |
resp.raise_for_status()
|
68 |
return resp.json()
|
69 |
|
|
|
70 |
def create_agent() -> CodeAgent:
|
71 |
"""
|
72 |
+
Factory that initializes and returns a configured CodeAgent using OpenAI GPT-3.5-turbo.
|
73 |
+
Expects OPENAI_API_KEY set in the environment.
|
74 |
+
|
75 |
+
:return: Configured CodeAgent instance.
|
76 |
"""
|
77 |
+
model = OpenAIServerModel(model_name="gpt-3.5-turbo")
|
78 |
agent = CodeAgent(
|
79 |
tools=[fetch_questions, fetch_random_question, fetch_file, submit_answers],
|
80 |
+
model=model,
|
81 |
prompt_template=(
|
82 |
"Here is a GAIA question:\n"
|
83 |
"{question}\n"
|
84 |
+
"Provide only the exact answer (exact-match), with no additional explanation."
|
85 |
)
|
86 |
)
|
87 |
return agent
|