Ubik80 commited on
Commit
89e6d63
·
verified ·
1 Parent(s): 64d872f

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +38 -22
agent.py CHANGED
@@ -15,22 +15,30 @@ def fetch_questions() -> list:
15
  """
16
  Fetch the full list of GAIA evaluation questions.
17
 
18
- :return: A list of question dicts, each with 'task_id' and 'question'.
 
 
 
 
19
  """
20
- resp = requests.get(f"{API_URL}/questions", timeout=15)
21
- resp.raise_for_status()
22
- return resp.json()
23
 
24
  @tool
25
  def fetch_random_question() -> dict:
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()
33
- return resp.json()
34
 
35
  @tool
36
  def submit_answers(
@@ -39,34 +47,42 @@ def submit_answers(
39
  answers: list
40
  ) -> dict:
41
  """
42
- Submit the agent's answers to GAIA and get the scoring.
43
 
44
- :param username: The Hugging Face username for identifying the submission.
45
- :param agent_code: URL to your Space code (for verification purposes).
46
- :param answers: List of dicts each with 'task_id' and 'submitted_answer'.
47
- :return: A dict containing 'score', 'correct_count', 'total_attempted', 'message', etc.
 
 
 
48
  """
49
  payload = {
50
  "username": username,
51
  "agent_code": agent_code,
52
  "answers": answers
53
  }
54
- resp = requests.post(f"{API_URL}/submit", json=payload, timeout=60)
55
- resp.raise_for_status()
56
- return resp.json()
57
 
 
 
 
58
  def create_agent() -> CodeAgent:
59
  """
60
  Build and return a configured CodeAgent using OpenAI GPT-3.5 Turbo.
61
- Requires OPENAI_API_KEY in the environment.
 
 
 
 
 
 
62
  """
63
  model = OpenAIServerModel(model_name="gpt-3.5-turbo")
64
  agent = CodeAgent(
65
- tools=[
66
- fetch_questions,
67
- fetch_random_question,
68
- submit_answers,
69
- ],
70
  model=model,
71
  prompt_template=(
72
  "Here is a GAIA question:\n"
 
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(
 
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,
87
  prompt_template=(
88
  "Here is a GAIA question:\n"