Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
@@ -1,15 +1,10 @@
|
|
|
|
1 |
import os
|
2 |
import requests
|
3 |
from smolagents import CodeAgent, tool, OpenAIServerModel
|
4 |
|
5 |
-
# ------------------------
|
6 |
-
# Constants
|
7 |
-
# ------------------------
|
8 |
API_URL = "https://agents-course-unit4-scoring.hf.space"
|
9 |
|
10 |
-
# ------------------------
|
11 |
-
# Tool definitions
|
12 |
-
# ------------------------
|
13 |
@tool
|
14 |
def fetch_questions() -> list:
|
15 |
"""
|
@@ -22,7 +17,6 @@ def fetch_questions() -> list:
|
|
22 |
resp.raise_for_status()
|
23 |
return resp.json()
|
24 |
|
25 |
-
|
26 |
@tool
|
27 |
def fetch_random_question() -> dict:
|
28 |
"""
|
@@ -35,19 +29,18 @@ def fetch_random_question() -> dict:
|
|
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):
|
46 |
-
agent_code (str): URL
|
47 |
-
answers (list):
|
48 |
|
49 |
Returns:
|
50 |
-
dict:
|
51 |
"""
|
52 |
payload = {
|
53 |
"username": username,
|
@@ -58,24 +51,21 @@ def submit_answers(username: str, agent_code: str, answers: list) -> dict:
|
|
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,
|
75 |
-
prompt_template
|
|
|
|
|
76 |
"Here is a GAIA question:\n"
|
77 |
-
"{
|
78 |
-
"
|
79 |
)
|
80 |
)
|
81 |
return agent
|
|
|
1 |
+
# agent.py
|
2 |
import os
|
3 |
import requests
|
4 |
from smolagents import CodeAgent, tool, OpenAIServerModel
|
5 |
|
|
|
|
|
|
|
6 |
API_URL = "https://agents-course-unit4-scoring.hf.space"
|
7 |
|
|
|
|
|
|
|
8 |
@tool
|
9 |
def fetch_questions() -> list:
|
10 |
"""
|
|
|
17 |
resp.raise_for_status()
|
18 |
return resp.json()
|
19 |
|
|
|
20 |
@tool
|
21 |
def fetch_random_question() -> dict:
|
22 |
"""
|
|
|
29 |
resp.raise_for_status()
|
30 |
return resp.json()
|
31 |
|
|
|
32 |
@tool
|
33 |
def submit_answers(username: str, agent_code: str, answers: list) -> dict:
|
34 |
"""
|
35 |
Submit the agent's answers to GAIA and get the scoring.
|
36 |
|
37 |
Args:
|
38 |
+
username (str): HF username for the submission.
|
39 |
+
agent_code (str): URL of your Space repo for verification.
|
40 |
+
answers (list): List of dicts, each with 'task_id' and 'submitted_answer'.
|
41 |
|
42 |
Returns:
|
43 |
+
dict: Contains 'score', 'correct_count', 'total_attempted', 'message', etc.
|
44 |
"""
|
45 |
payload = {
|
46 |
"username": username,
|
|
|
51 |
resp.raise_for_status()
|
52 |
return resp.json()
|
53 |
|
|
|
54 |
def create_agent() -> CodeAgent:
|
55 |
"""
|
56 |
Build and return a configured CodeAgent using OpenAI GPT-3.5 Turbo.
|
57 |
Requires OPENAI_API_KEY in the environment.
|
|
|
|
|
|
|
58 |
"""
|
|
|
59 |
model = OpenAIServerModel(model_id="gpt-3.5-turbo")
|
60 |
agent = CodeAgent(
|
61 |
tools=[fetch_questions, fetch_random_question, submit_answers],
|
62 |
model=model,
|
63 |
+
# Use `system_prompt`, not `prompt_template`
|
64 |
+
system_prompt=(
|
65 |
+
"You are a concise assistant.\n"
|
66 |
"Here is a GAIA question:\n"
|
67 |
+
"{task}\n"
|
68 |
+
"Respond with only the exact answer (exact-match), no extra text.\n"
|
69 |
)
|
70 |
)
|
71 |
return agent
|