Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
@@ -10,12 +10,13 @@ API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
10 |
# ------------------------
|
11 |
# Tool definitions
|
12 |
# ------------------------
|
|
|
13 |
@tool
|
14 |
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()
|
@@ -32,18 +33,6 @@ def fetch_random_question() -> dict:
|
|
32 |
resp.raise_for_status()
|
33 |
return resp.json()
|
34 |
|
35 |
-
@tool
|
36 |
-
def fetch_file(task_id: str) -> bytes:
|
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()
|
45 |
-
return resp.content
|
46 |
-
|
47 |
@tool
|
48 |
def submit_answers(
|
49 |
username: str,
|
@@ -51,12 +40,12 @@ def submit_answers(
|
|
51 |
answers: list
|
52 |
) -> dict:
|
53 |
"""
|
54 |
-
Submit the agent's answers to
|
55 |
|
56 |
-
:param username: Hugging Face username for submission
|
57 |
-
:param agent_code: URL
|
58 |
-
:param answers: List of dicts
|
59 |
-
:return:
|
60 |
"""
|
61 |
payload = {
|
62 |
"username": username,
|
@@ -69,19 +58,22 @@ def submit_answers(
|
|
69 |
|
70 |
def create_agent() -> CodeAgent:
|
71 |
"""
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
:return: Configured CodeAgent instance.
|
76 |
"""
|
77 |
model = OpenAIServerModel(model_name="gpt-3.5-turbo")
|
78 |
agent = CodeAgent(
|
79 |
-
tools=[
|
|
|
|
|
|
|
|
|
80 |
model=model,
|
81 |
prompt_template=(
|
82 |
"Here is a GAIA question:\n"
|
83 |
"{question}\n"
|
84 |
-
"Provide
|
85 |
)
|
86 |
)
|
87 |
return agent
|
|
|
|
10 |
# ------------------------
|
11 |
# Tool definitions
|
12 |
# ------------------------
|
13 |
+
|
14 |
@tool
|
15 |
def fetch_questions() -> list:
|
16 |
"""
|
17 |
Fetch the full list of GAIA evaluation questions.
|
18 |
|
19 |
+
:return: 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()
|
|
|
33 |
resp.raise_for_status()
|
34 |
return resp.json()
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
@tool
|
37 |
def submit_answers(
|
38 |
username: str,
|
|
|
40 |
answers: list
|
41 |
) -> dict:
|
42 |
"""
|
43 |
+
Submit the agent's answers to GAIA and get the scoring.
|
44 |
|
45 |
+
:param username: The Hugging Face username for identifying the submission.
|
46 |
+
:param agent_code: URL to your Space code (for verification purposes).
|
47 |
+
:param answers: List of dicts each with 'task_id' and 'submitted_answer'.
|
48 |
+
:return: A dict containing 'score', 'correct_count', 'total_attempted', 'message', etc.
|
49 |
"""
|
50 |
payload = {
|
51 |
"username": username,
|
|
|
58 |
|
59 |
def create_agent() -> CodeAgent:
|
60 |
"""
|
61 |
+
Build and return a configured CodeAgent using OpenAI GPT-3.5 Turbo.
|
62 |
+
Requires OPENAI_API_KEY in the environment.
|
|
|
|
|
63 |
"""
|
64 |
model = OpenAIServerModel(model_name="gpt-3.5-turbo")
|
65 |
agent = CodeAgent(
|
66 |
+
tools=[
|
67 |
+
fetch_questions,
|
68 |
+
fetch_random_question,
|
69 |
+
submit_answers, # fetch_file è stato rimosso
|
70 |
+
],
|
71 |
model=model,
|
72 |
prompt_template=(
|
73 |
"Here is a GAIA question:\n"
|
74 |
"{question}\n"
|
75 |
+
"Provide ONLY the exact answer (exact-match), with no extra text."
|
76 |
)
|
77 |
)
|
78 |
return agent
|
79 |
+
|