Ubik80 commited on
Commit
4b51ad9
·
verified ·
1 Parent(s): c396a92

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +22 -34
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
- 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(
45
- username: str,
46
- agent_code: str,
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,
 
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,