Ubik80 commited on
Commit
d3f09f9
·
verified ·
1 Parent(s): 70b0f89
Files changed (1) hide show
  1. agent.py +26 -33
agent.py CHANGED
@@ -1,5 +1,3 @@
1
-
2
-
3
  import os
4
  import requests
5
  from smolagents import CodeAgent, tool, OpenAIServerModel
@@ -18,37 +16,34 @@ def fetch_questions() -> list:
18
  """
19
  Fetch the full list of GAIA evaluation questions.
20
 
21
- :return: A list of question dictionaries, each with 'task_id' and 'question'.
22
  """
23
- response = requests.get(f"{API_URL}/questions", timeout=15)
24
- response.raise_for_status()
25
- return response.json()
26
-
27
 
28
  @tool
29
  def fetch_random_question() -> dict:
30
  """
31
  Fetch a single random GAIA question.
32
 
33
- :return: A dict with keys 'task_id' and 'question'.
34
  """
35
- response = requests.get(f"{API_URL}/random-question", timeout=15)
36
- response.raise_for_status()
37
- return response.json()
38
-
39
 
40
  @tool
41
  def fetch_file(task_id: str) -> bytes:
42
  """
43
- Download a file associated with a given task_id.
44
 
45
- :param task_id: The ID of the GAIA task whose file you want to download.
46
- :return: The file content as raw bytes.
47
  """
48
- response = requests.get(f"{API_URL}/files/{task_id}", timeout=15)
49
- response.raise_for_status()
50
- return response.content
51
-
52
 
53
  @tool
54
  def submit_answers(
@@ -57,37 +52,35 @@ def submit_answers(
57
  answers: list
58
  ) -> dict:
59
  """
60
- Submit the agent's answers to GAIA and return the scoring.
61
 
62
- :param username: Your Hugging Face username (identifies the submission).
63
- :param agent_code: URL to your HF Space code (for verification).
64
- :param answers: List of dicts each with 'task_id' and 'submitted_answer'.
65
- :return: A dict containing 'score', 'correct_count', 'total_attempted', 'message', etc.
66
  """
67
  payload = {
68
  "username": username,
69
  "agent_code": agent_code,
70
  "answers": answers
71
  }
72
- response = requests.post(f"{API_URL}/submit", json=payload, timeout=60)
73
- response.raise_for_status()
74
- return response.json()
75
-
76
 
77
  def create_agent() -> CodeAgent:
78
  """
79
- Factory that returns a configured CodeAgent instance using OpenAI.
80
-
81
  Expects OPENAI_API_KEY in the environment.
82
  """
83
- openai_model = OpenAIServerModel(model_name="gpt-3.5-turbo")
84
  agent = CodeAgent(
85
  tools=[fetch_questions, fetch_random_question, fetch_file, submit_answers],
86
- model=openai_model,
87
  prompt_template=(
88
  "Here is a GAIA question:\n"
89
  "{question}\n"
90
- "Provide ONLY the exact answer (exact-match) with no extra text."
91
  )
92
  )
93
  return agent
 
 
 
1
  import os
2
  import requests
3
  from smolagents import CodeAgent, tool, OpenAIServerModel
 
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()
23
+ return resp.json()
 
24
 
25
  @tool
26
  def fetch_random_question() -> dict:
27
  """
28
  Fetch a single random GAIA question.
29
 
30
+ :return: A dict containing 'task_id' and 'question'.
31
  """
32
+ resp = requests.get(f"{API_URL}/random-question", timeout=15)
33
+ resp.raise_for_status()
34
+ return resp.json()
 
35
 
36
  @tool
37
  def fetch_file(task_id: str) -> bytes:
38
  """
39
+ Download a file associated with a given GAIA task.
40
 
41
+ :param task_id: The ID of the GAIA task whose file to download.
42
+ :return: Raw bytes of the file.
43
  """
44
+ resp = requests.get(f"{API_URL}/files/{task_id}", timeout=15)
45
+ resp.raise_for_status()
46
+ return resp.content
 
47
 
48
  @tool
49
  def submit_answers(
 
52
  answers: list
53
  ) -> dict:
54
  """
55
+ Submit the agent's answers and get back the scoring.
56
 
57
+ :param username: Your HF username for the submission.
58
+ :param agent_code: URL to your Space code (for verification).
59
+ :param answers: List of dicts with 'task_id' and 'submitted_answer'.
60
+ :return: Dict with keys 'score', 'correct_count', 'total_attempted', 'message', etc.
61
  """
62
  payload = {
63
  "username": username,
64
  "agent_code": agent_code,
65
  "answers": answers
66
  }
67
+ resp = requests.post(f"{API_URL}/submit", json=payload, timeout=60)
68
+ resp.raise_for_status()
69
+ return resp.json()
 
70
 
71
  def create_agent() -> CodeAgent:
72
  """
73
+ Build and return a configured CodeAgent using OpenAI GPT-3.5 Turbo.
 
74
  Expects OPENAI_API_KEY in the environment.
75
  """
76
+ model = OpenAIServerModel(model_name="gpt-3.5-turbo")
77
  agent = CodeAgent(
78
  tools=[fetch_questions, fetch_random_question, fetch_file, submit_answers],
79
+ model=model,
80
  prompt_template=(
81
  "Here is a GAIA question:\n"
82
  "{question}\n"
83
+ "Respond with only the exact answer (exact-match), no extra text."
84
  )
85
  )
86
  return agent