Spaces:
Sleeping
Sleeping
Added summarization of old messages when context window gets too long, switched to DeepSeek-V3, scored 30%!
Browse files- .gitignore +2 -1
- app.py +71 -33
- functions/agent.py +110 -8
- functions/tools.py +8 -2
- questions.json +19 -21
- results.csv +15 -0
.gitignore
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
__pycache__
|
2 |
.venv
|
3 |
-
.vscode
|
|
|
|
1 |
__pycache__
|
2 |
.venv
|
3 |
+
.vscode
|
4 |
+
logs
|
app.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
'''HuggingFace Agents course final project GAIA agent benchmark.'''
|
2 |
|
3 |
# Standard library
|
|
|
|
|
4 |
import os
|
5 |
import requests
|
6 |
|
@@ -14,6 +16,37 @@ from functions.agent import create_agent
|
|
14 |
# --- Constants ---
|
15 |
from configuration import QUESTIONS, DEFAULT_API_URL, INSTRUCTIONS
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
19 |
"""
|
@@ -25,9 +58,9 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
25 |
|
26 |
if profile:
|
27 |
username = f'{profile.username}'
|
28 |
-
|
29 |
else:
|
30 |
-
|
31 |
return 'Please Login to Hugging Face with the button.', None
|
32 |
|
33 |
api_url = DEFAULT_API_URL
|
@@ -38,16 +71,16 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
38 |
try:
|
39 |
agent = create_agent()
|
40 |
except Exception as e: # pylint: disable=W0703
|
41 |
-
|
42 |
return f"Error initializing agent: {e}", None
|
43 |
|
44 |
# In the case of an app running as a hugging Face space, this link points toward your
|
45 |
# codebase (useful for others so please keep it public)
|
46 |
agent_code = f'https://huggingface.co/spaces/{space_id}/tree/main'
|
47 |
-
|
48 |
|
49 |
# 2. Fetch Questions
|
50 |
-
|
51 |
|
52 |
try:
|
53 |
response = requests.get(questions_url, timeout=15)
|
@@ -55,22 +88,22 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
55 |
questions_data = response.json()
|
56 |
|
57 |
if not questions_data:
|
58 |
-
|
59 |
return 'Fetched questions list is empty or invalid format.', None
|
60 |
|
61 |
-
|
62 |
|
63 |
except requests.exceptions.JSONDecodeError as e:
|
64 |
-
|
65 |
-
|
66 |
return f'Error decoding server response for questions: {e}', None
|
67 |
|
68 |
except requests.exceptions.RequestException as e:
|
69 |
-
|
70 |
return f'Error fetching questions: {e}', None
|
71 |
|
72 |
except Exception as e: # pylint: disable=W0703
|
73 |
-
|
74 |
return f'An unexpected error occurred fetching questions: {e}', None
|
75 |
|
76 |
with open('questions.json', 'w', encoding='utf-8') as f:
|
@@ -81,7 +114,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
81 |
results_log = []
|
82 |
answers_payload = []
|
83 |
|
84 |
-
|
85 |
|
86 |
for question_number in QUESTIONS:
|
87 |
item = questions_data[question_number - 1] # Adjust for zero-based index
|
@@ -89,7 +122,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
89 |
question_text = item.get("question")
|
90 |
|
91 |
if not task_id or question_text is None:
|
92 |
-
|
93 |
continue
|
94 |
|
95 |
try:
|
@@ -105,7 +138,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
105 |
})
|
106 |
|
107 |
except Exception as e: # pylint: disable=W0703
|
108 |
-
|
109 |
results_log.append({
|
110 |
"Task ID": task_id,
|
111 |
"Question": question_text,
|
@@ -113,7 +146,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
113 |
})
|
114 |
|
115 |
if not answers_payload:
|
116 |
-
|
117 |
return 'Agent did not produce any answers to submit.', pd.DataFrame(results_log)
|
118 |
|
119 |
# 4. Prepare Submission
|
@@ -125,10 +158,10 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
125 |
status_update = (
|
126 |
f'Agent finished. Submitting {len(answers_payload)} answers for user "{username}"...'
|
127 |
)
|
128 |
-
|
129 |
|
130 |
# 5. Submit
|
131 |
-
|
132 |
try:
|
133 |
response = requests.post(submit_url, json=submission_data, timeout=60)
|
134 |
response.raise_for_status()
|
@@ -141,8 +174,9 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
141 |
f"{result_data.get('total_attempted', '?')} correct)\n"
|
142 |
f"Message: {result_data.get('message', 'No message received.')}"
|
143 |
)
|
144 |
-
|
145 |
results_df = pd.DataFrame(results_log)
|
|
|
146 |
return final_status, results_df
|
147 |
|
148 |
except requests.exceptions.HTTPError as e:
|
@@ -156,26 +190,30 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
156 |
error_detail += f" Response: {e.response.text[:500]}"
|
157 |
|
158 |
status_message = f"Submission Failed: {error_detail}"
|
159 |
-
|
160 |
results_df = pd.DataFrame(results_log)
|
|
|
161 |
return status_message, results_df
|
162 |
|
163 |
except requests.exceptions.Timeout:
|
164 |
status_message = "Submission Failed: The request timed out."
|
165 |
-
|
166 |
results_df = pd.DataFrame(results_log)
|
|
|
167 |
return status_message, results_df
|
168 |
|
169 |
except requests.exceptions.RequestException as e:
|
170 |
status_message = f"Submission Failed: Network error - {e}"
|
171 |
-
|
172 |
results_df = pd.DataFrame(results_log)
|
|
|
173 |
return status_message, results_df
|
174 |
|
175 |
except Exception as e: # pylint: disable=W0703
|
176 |
status_message = f"An unexpected error occurred during submission: {e}"
|
177 |
-
|
178 |
results_df = pd.DataFrame(results_log)
|
|
|
179 |
return status_message, results_df
|
180 |
|
181 |
|
@@ -217,29 +255,29 @@ with gr.Blocks() as demo:
|
|
217 |
)
|
218 |
|
219 |
if __name__ == "__main__":
|
220 |
-
|
221 |
|
222 |
# Check for SPACE_HOST and SPACE_ID at startup for information
|
223 |
space_host_startup = os.getenv("SPACE_HOST")
|
224 |
space_id_startup = os.getenv("SPACE_ID") # Get SPACE_ID at startup
|
225 |
|
226 |
if space_host_startup:
|
227 |
-
|
228 |
-
|
229 |
else:
|
230 |
-
|
231 |
|
232 |
if space_id_startup: # Print repo URLs if SPACE_ID is found
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
else:
|
237 |
-
|
238 |
-
"ℹ️ SPACE_ID environment variable not found (running locally?)." \
|
239 |
"Repo URL cannot be determined."
|
240 |
)
|
241 |
|
242 |
-
|
243 |
|
244 |
-
|
245 |
demo.launch(debug=True, share=False)
|
|
|
1 |
'''HuggingFace Agents course final project GAIA agent benchmark.'''
|
2 |
|
3 |
# Standard library
|
4 |
+
import glob
|
5 |
+
import logging
|
6 |
import os
|
7 |
import requests
|
8 |
|
|
|
16 |
# --- Constants ---
|
17 |
from configuration import QUESTIONS, DEFAULT_API_URL, INSTRUCTIONS
|
18 |
|
19 |
+
# --- Logging Configuration ---
|
20 |
+
# Create logs directory if it doesn't exist
|
21 |
+
os.makedirs('logs', exist_ok=True)
|
22 |
+
|
23 |
+
# Clean up old log files
|
24 |
+
def cleanup_old_logs():
|
25 |
+
"""Remove old log files from the logs directory."""
|
26 |
+
log_files = glob.glob('logs/*.log')
|
27 |
+
for log_file in log_files:
|
28 |
+
try:
|
29 |
+
os.remove(log_file)
|
30 |
+
print(f"Removed old log file: {log_file}")
|
31 |
+
except OSError as e:
|
32 |
+
print(f"Error removing log file {log_file}: {e}")
|
33 |
+
|
34 |
+
# Clean up old logs before starting
|
35 |
+
cleanup_old_logs()
|
36 |
+
|
37 |
+
# Configure root logger
|
38 |
+
logging.basicConfig(
|
39 |
+
level=logging.DEBUG,
|
40 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
41 |
+
handlers=[
|
42 |
+
logging.FileHandler('logs/agent.log', encoding='utf-8'),
|
43 |
+
logging.StreamHandler() # Also log to console
|
44 |
+
]
|
45 |
+
)
|
46 |
+
|
47 |
+
# Get logger for this module
|
48 |
+
logger = logging.getLogger(__name__)
|
49 |
+
|
50 |
|
51 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
52 |
"""
|
|
|
58 |
|
59 |
if profile:
|
60 |
username = f'{profile.username}'
|
61 |
+
logger.info('User logged in: %s', username)
|
62 |
else:
|
63 |
+
logger.warning('User not logged in.')
|
64 |
return 'Please Login to Hugging Face with the button.', None
|
65 |
|
66 |
api_url = DEFAULT_API_URL
|
|
|
71 |
try:
|
72 |
agent = create_agent()
|
73 |
except Exception as e: # pylint: disable=W0703
|
74 |
+
logger.error("Error instantiating agent: %s", e)
|
75 |
return f"Error initializing agent: {e}", None
|
76 |
|
77 |
# In the case of an app running as a hugging Face space, this link points toward your
|
78 |
# codebase (useful for others so please keep it public)
|
79 |
agent_code = f'https://huggingface.co/spaces/{space_id}/tree/main'
|
80 |
+
logger.info('Agent code URL: %s', agent_code)
|
81 |
|
82 |
# 2. Fetch Questions
|
83 |
+
logger.info('Fetching questions from: %s', questions_url)
|
84 |
|
85 |
try:
|
86 |
response = requests.get(questions_url, timeout=15)
|
|
|
88 |
questions_data = response.json()
|
89 |
|
90 |
if not questions_data:
|
91 |
+
logger.warning('Fetched questions list is empty.')
|
92 |
return 'Fetched questions list is empty or invalid format.', None
|
93 |
|
94 |
+
logger.info('Fetched %d questions.', len(questions_data))
|
95 |
|
96 |
except requests.exceptions.JSONDecodeError as e:
|
97 |
+
logger.error('Error decoding JSON response from questions endpoint: %s', e)
|
98 |
+
logger.debug('Response text: %s', response.text[:500])
|
99 |
return f'Error decoding server response for questions: {e}', None
|
100 |
|
101 |
except requests.exceptions.RequestException as e:
|
102 |
+
logger.error('Error fetching questions: %s', e)
|
103 |
return f'Error fetching questions: {e}', None
|
104 |
|
105 |
except Exception as e: # pylint: disable=W0703
|
106 |
+
logger.error('An unexpected error occurred fetching questions: %s', e)
|
107 |
return f'An unexpected error occurred fetching questions: {e}', None
|
108 |
|
109 |
with open('questions.json', 'w', encoding='utf-8') as f:
|
|
|
114 |
results_log = []
|
115 |
answers_payload = []
|
116 |
|
117 |
+
logger.info('Running agent on %d questions...', len(questions_data))
|
118 |
|
119 |
for question_number in QUESTIONS:
|
120 |
item = questions_data[question_number - 1] # Adjust for zero-based index
|
|
|
122 |
question_text = item.get("question")
|
123 |
|
124 |
if not task_id or question_text is None:
|
125 |
+
logger.warning('Skipping item with missing task_id or question: %s', item)
|
126 |
continue
|
127 |
|
128 |
try:
|
|
|
138 |
})
|
139 |
|
140 |
except Exception as e: # pylint: disable=W0703
|
141 |
+
logger.error('Error running agent on task %s: %s', task_id, e)
|
142 |
results_log.append({
|
143 |
"Task ID": task_id,
|
144 |
"Question": question_text,
|
|
|
146 |
})
|
147 |
|
148 |
if not answers_payload:
|
149 |
+
logger.warning('Agent did not produce any answers to submit.')
|
150 |
return 'Agent did not produce any answers to submit.', pd.DataFrame(results_log)
|
151 |
|
152 |
# 4. Prepare Submission
|
|
|
158 |
status_update = (
|
159 |
f'Agent finished. Submitting {len(answers_payload)} answers for user "{username}"...'
|
160 |
)
|
161 |
+
logger.info(status_update)
|
162 |
|
163 |
# 5. Submit
|
164 |
+
logger.info('Submitting %d answers to: %s', len(answers_payload), submit_url)
|
165 |
try:
|
166 |
response = requests.post(submit_url, json=submission_data, timeout=60)
|
167 |
response.raise_for_status()
|
|
|
174 |
f"{result_data.get('total_attempted', '?')} correct)\n"
|
175 |
f"Message: {result_data.get('message', 'No message received.')}"
|
176 |
)
|
177 |
+
logger.info('Submission successful.')
|
178 |
results_df = pd.DataFrame(results_log)
|
179 |
+
results_df.to_csv('results.csv', index=False)
|
180 |
return final_status, results_df
|
181 |
|
182 |
except requests.exceptions.HTTPError as e:
|
|
|
190 |
error_detail += f" Response: {e.response.text[:500]}"
|
191 |
|
192 |
status_message = f"Submission Failed: {error_detail}"
|
193 |
+
logger.error(status_message)
|
194 |
results_df = pd.DataFrame(results_log)
|
195 |
+
results_df.to_csv('results.csv', index=False)
|
196 |
return status_message, results_df
|
197 |
|
198 |
except requests.exceptions.Timeout:
|
199 |
status_message = "Submission Failed: The request timed out."
|
200 |
+
logger.error(status_message)
|
201 |
results_df = pd.DataFrame(results_log)
|
202 |
+
results_df.to_csv('results.csv', index=False)
|
203 |
return status_message, results_df
|
204 |
|
205 |
except requests.exceptions.RequestException as e:
|
206 |
status_message = f"Submission Failed: Network error - {e}"
|
207 |
+
logger.error(status_message)
|
208 |
results_df = pd.DataFrame(results_log)
|
209 |
+
results_df.to_csv('results.csv', index=False)
|
210 |
return status_message, results_df
|
211 |
|
212 |
except Exception as e: # pylint: disable=W0703
|
213 |
status_message = f"An unexpected error occurred during submission: {e}"
|
214 |
+
logger.error(status_message)
|
215 |
results_df = pd.DataFrame(results_log)
|
216 |
+
results_df.to_csv('results.csv', index=False)
|
217 |
return status_message, results_df
|
218 |
|
219 |
|
|
|
255 |
)
|
256 |
|
257 |
if __name__ == "__main__":
|
258 |
+
logger.info("\n" + "-"*30 + " App Starting " + "-"*30)
|
259 |
|
260 |
# Check for SPACE_HOST and SPACE_ID at startup for information
|
261 |
space_host_startup = os.getenv("SPACE_HOST")
|
262 |
space_id_startup = os.getenv("SPACE_ID") # Get SPACE_ID at startup
|
263 |
|
264 |
if space_host_startup:
|
265 |
+
logger.info("✅ SPACE_HOST found: %s", space_host_startup)
|
266 |
+
logger.info(" Runtime URL should be: https://%s.hf.space", space_host_startup)
|
267 |
else:
|
268 |
+
logger.info("ℹ️ SPACE_HOST environment variable not found (running locally?).")
|
269 |
|
270 |
if space_id_startup: # Print repo URLs if SPACE_ID is found
|
271 |
+
logger.info("✅ SPACE_ID found: %s", space_id_startup)
|
272 |
+
logger.info(" Repo URL: https://huggingface.co/spaces/%s", space_id_startup)
|
273 |
+
logger.info(" Repo Tree URL: https://huggingface.co/spaces/%s/tree/main", space_id_startup)
|
274 |
else:
|
275 |
+
logger.info(
|
276 |
+
"ℹ️ SPACE_ID environment variable not found (running locally?). " \
|
277 |
"Repo URL cannot be determined."
|
278 |
)
|
279 |
|
280 |
+
logger.info("-" + "-"*(60 + len(" App Starting ")) + "\n")
|
281 |
|
282 |
+
logger.info("Launching Gradio Interface for Basic Agent Evaluation...")
|
283 |
demo.launch(debug=True, share=False)
|
functions/agent.py
CHANGED
@@ -1,39 +1,141 @@
|
|
1 |
'''Agent definition for GAIA question answering system.'''
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
# Imports for agent creation
|
4 |
-
from smolagents import CodeAgent, InferenceClientModel, VisitWebpageTool
|
5 |
from functions.tools import (
|
6 |
google_search,
|
7 |
wikipedia_search,
|
8 |
get_wikipedia_page
|
9 |
)
|
10 |
|
|
|
|
|
|
|
11 |
def create_agent():
|
12 |
'''Creates agent for GAIA question answering system.'''
|
13 |
|
14 |
model = InferenceClientModel(
|
15 |
-
"
|
16 |
-
provider="
|
17 |
-
max_tokens=
|
18 |
)
|
19 |
|
20 |
tools = [
|
21 |
wikipedia_search,
|
22 |
get_wikipedia_page,
|
23 |
google_search,
|
24 |
-
VisitWebpageTool()
|
25 |
]
|
26 |
|
27 |
agent = CodeAgent(
|
28 |
model=model,
|
29 |
tools=tools,
|
30 |
additional_authorized_imports=['bs4.*', 'json'],
|
|
|
31 |
name="GAIA_agent",
|
32 |
-
verbosity_level=
|
33 |
-
max_steps=
|
34 |
-
planning_interval=
|
35 |
description="GAIA agent for question answering"
|
36 |
)
|
37 |
|
38 |
|
39 |
return agent
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
'''Agent definition for GAIA question answering system.'''
|
2 |
|
3 |
+
# Standard library
|
4 |
+
import os
|
5 |
+
import json
|
6 |
+
import logging
|
7 |
+
|
8 |
+
from openai import OpenAI
|
9 |
+
|
10 |
# Imports for agent creation
|
11 |
+
from smolagents import CodeAgent, InferenceClientModel, VisitWebpageTool, ActionStep, MessageRole
|
12 |
from functions.tools import (
|
13 |
google_search,
|
14 |
wikipedia_search,
|
15 |
get_wikipedia_page
|
16 |
)
|
17 |
|
18 |
+
# Get logger for this module
|
19 |
+
logger = logging.getLogger(__name__)
|
20 |
+
|
21 |
def create_agent():
|
22 |
'''Creates agent for GAIA question answering system.'''
|
23 |
|
24 |
model = InferenceClientModel(
|
25 |
+
"deepseek-ai/DeepSeek-V3",
|
26 |
+
provider="together",
|
27 |
+
max_tokens=64000
|
28 |
)
|
29 |
|
30 |
tools = [
|
31 |
wikipedia_search,
|
32 |
get_wikipedia_page,
|
33 |
google_search,
|
34 |
+
VisitWebpageTool(),
|
35 |
]
|
36 |
|
37 |
agent = CodeAgent(
|
38 |
model=model,
|
39 |
tools=tools,
|
40 |
additional_authorized_imports=['bs4.*', 'json'],
|
41 |
+
step_callbacks=[step_memory_cap],
|
42 |
name="GAIA_agent",
|
43 |
+
verbosity_level=5,
|
44 |
+
max_steps=30,
|
45 |
+
planning_interval=2,
|
46 |
description="GAIA agent for question answering"
|
47 |
)
|
48 |
|
49 |
|
50 |
return agent
|
51 |
+
|
52 |
+
|
53 |
+
def step_memory_cap(memory_step: ActionStep, agent: CodeAgent) -> None:
|
54 |
+
'''Removes old steps from agent memory to keep context length under control.'''
|
55 |
+
|
56 |
+
task_step = agent.memory.steps[0]
|
57 |
+
planning_step = agent.memory.steps[1]
|
58 |
+
latest_step = agent.memory.steps[-1]
|
59 |
+
|
60 |
+
if len(agent.memory.steps) > 2:
|
61 |
+
agent.memory.steps = [task_step, planning_step, latest_step]
|
62 |
+
|
63 |
+
logger.info('Agent memory has %d steps', len(agent.memory.steps))
|
64 |
+
logger.info('Latest step is step %d', memory_step.step_number)
|
65 |
+
logger.info('Contains: %s messages', len(agent.memory.steps[-1].model_input_messages))
|
66 |
+
logger.info('Token usage: %s', agent.memory.steps[-1].token_usage.total_tokens)
|
67 |
+
|
68 |
+
for message in agent.memory.steps[-1].model_input_messages:
|
69 |
+
logger.debug(' Role: %s: %s', message['role'], message['content'][:100])
|
70 |
+
|
71 |
+
token_usage = agent.memory.steps[-1].token_usage.total_tokens
|
72 |
+
|
73 |
+
if token_usage > 50000:
|
74 |
+
logger.info('Token usage is %d, summarizing old messages', token_usage)
|
75 |
+
|
76 |
+
summary = summarize_old_messages(
|
77 |
+
agent.memory.steps[-1].model_input_messages[1:]
|
78 |
+
)
|
79 |
+
|
80 |
+
if summary is not None:
|
81 |
+
|
82 |
+
new_messages = [agent.memory.steps[-1].model_input_messages[0]]
|
83 |
+
new_messages.append({
|
84 |
+
'role': MessageRole.USER,
|
85 |
+
'content': [{'type': 'text', 'text': f'Here is a summary of your investigation so far: {summary}'}]
|
86 |
+
})
|
87 |
+
agent.memory.steps = [agent.memory.steps[0]]
|
88 |
+
agent.memory.steps[0].model_input_messages = new_messages
|
89 |
+
|
90 |
+
for message in agent.memory.steps[0].model_input_messages:
|
91 |
+
logger.debug(' Role: %s: %s', message['role'], message['content'][:100])
|
92 |
+
|
93 |
+
|
94 |
+
def summarize_old_messages(messages: dict) -> dict:
|
95 |
+
'''Summarizes old messages to keep context length under control.'''
|
96 |
+
|
97 |
+
client = OpenAI(api_key=os.environ['MODAL_API_KEY'])
|
98 |
+
|
99 |
+
client.base_url = (
|
100 |
+
'https://gperdrizet--vllm-openai-compatible-summarization-serve.modal.run/v1'
|
101 |
+
)
|
102 |
+
|
103 |
+
# Default to first avalible model
|
104 |
+
model = client.models.list().data[0]
|
105 |
+
model_id = model.id
|
106 |
+
|
107 |
+
messages = [
|
108 |
+
{
|
109 |
+
'role': 'system',
|
110 |
+
'content': f'Summarize the following interaction between an AI agent and a user. Return the summary formatted as text, not as JSON: {json.dumps(messages)}'
|
111 |
+
}
|
112 |
+
]
|
113 |
+
|
114 |
+
completion_args = {
|
115 |
+
'model': model_id,
|
116 |
+
'messages': messages,
|
117 |
+
# "frequency_penalty": args.frequency_penalty,
|
118 |
+
# "max_tokens": 128,
|
119 |
+
# "n": args.n,
|
120 |
+
# "presence_penalty": args.presence_penalty,
|
121 |
+
# "seed": args.seed,
|
122 |
+
# "stop": args.stop,
|
123 |
+
# "stream": args.stream,
|
124 |
+
# "temperature": args.temperature,
|
125 |
+
# "top_p": args.top_p,
|
126 |
+
}
|
127 |
+
|
128 |
+
try:
|
129 |
+
response = client.chat.completions.create(**completion_args)
|
130 |
+
|
131 |
+
except Exception as e: # pylint: disable=broad-exception-caught
|
132 |
+
response = None
|
133 |
+
logger.error('Error during Modal API call: %s', e)
|
134 |
+
|
135 |
+
if response is not None:
|
136 |
+
summary = response.choices[0].message.content
|
137 |
+
|
138 |
+
else:
|
139 |
+
summary = None
|
140 |
+
|
141 |
+
return summary
|
functions/tools.py
CHANGED
@@ -1,11 +1,16 @@
|
|
1 |
'''Tools for GAIA question answering agent.'''
|
2 |
|
|
|
3 |
import bleach
|
4 |
import requests
|
5 |
from bleach.css_sanitizer import CSSSanitizer
|
6 |
-
from bs4 import BeautifulSoup
|
7 |
from smolagents import tool
|
8 |
from googlesearch import search
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
@tool
|
11 |
def google_search(query: str) -> dict:
|
@@ -82,7 +87,8 @@ def wikipedia_search(query: str) -> dict:
|
|
82 |
@tool
|
83 |
def get_wikipedia_page(query: str) -> str:
|
84 |
"""
|
85 |
-
Get the content of a Wikipedia page as HTML.
|
|
|
86 |
|
87 |
Args:
|
88 |
query (str): The title of the Wikipedia page.
|
|
|
1 |
'''Tools for GAIA question answering agent.'''
|
2 |
|
3 |
+
import logging
|
4 |
import bleach
|
5 |
import requests
|
6 |
from bleach.css_sanitizer import CSSSanitizer
|
|
|
7 |
from smolagents import tool
|
8 |
from googlesearch import search
|
9 |
+
from bs4 import BeautifulSoup
|
10 |
+
|
11 |
+
# Get logger for this module
|
12 |
+
logger = logging.getLogger(__name__)
|
13 |
+
|
14 |
|
15 |
@tool
|
16 |
def google_search(query: str) -> dict:
|
|
|
87 |
@tool
|
88 |
def get_wikipedia_page(query: str) -> str:
|
89 |
"""
|
90 |
+
Get the content of a Wikipedia page as HTML. Use this tool when trying to
|
91 |
+
retrieve information from a Wikipedia page or article.
|
92 |
|
93 |
Args:
|
94 |
query (str): The title of the Wikipedia page.
|
questions.json
CHANGED
@@ -1,22 +1,20 @@
|
|
1 |
-
|
2 |
-
{"task_id":"
|
3 |
-
{"task_id":"
|
4 |
-
{"task_id":"
|
5 |
-
{"task_id":"
|
6 |
-
{"task_id":"
|
7 |
-
{"task_id":"
|
8 |
-
{"task_id":"
|
9 |
-
{"task_id":"
|
10 |
-
{"task_id":"
|
11 |
-
{"task_id":"
|
12 |
-
{"task_id":"
|
13 |
-
{"task_id":"
|
14 |
-
{"task_id":"
|
15 |
-
{"task_id":"
|
16 |
-
{"task_id":"
|
17 |
-
{"task_id":"
|
18 |
-
{"task_id":"
|
19 |
-
{"task_id":"
|
20 |
-
{"task_id":"7bd855d8-463d-4ed5-93ca-5fe35145f733","question":"The attached Excel file contains the sales of menu items for a local fast-food chain. What were the total sales that the chain made from food (not including drinks)? Express your answer in USD with two decimal places.","Level":"1","file_name":"7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx"},
|
21 |
{"task_id":"5a0c1adf-205e-4841-a666-7c3ef95def9d","question":"What is the first name of the only Malko Competition recipient from the 20th Century (after 1977) whose nationality on record is a country that no longer exists?","Level":"1","file_name":""}
|
22 |
-
]
|
|
|
1 |
+
{"task_id":"8e867cd7-cff9-4e6c-867a-ff5ddc2550be","question":"How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.","Level":"1","file_name":""}
|
2 |
+
{"task_id":"a1e91b78-d3d8-4675-bb8d-62741b4b68a6","question":"In the video https:\/\/www.youtube.com\/watch?v=L1vXCYZAYYM, what is the highest number of bird species to be on camera simultaneously?","Level":"1","file_name":""}
|
3 |
+
{"task_id":"2d83110e-a098-4ebb-9987-066c06fa42d0","question":".rewsna eht sa \"tfel\" drow eht fo etisoppo eht etirw ,ecnetnes siht dnatsrednu uoy fI","Level":"1","file_name":""}
|
4 |
+
{"task_id":"cca530fc-4052-43b2-b130-b30968d8aa44","question":"Review the chess position provided in the image. It is black's turn. Provide the correct next move for black which guarantees a win. Please provide your response in algebraic notation.","Level":"1","file_name":"cca530fc-4052-43b2-b130-b30968d8aa44.png"}
|
5 |
+
{"task_id":"4fc2f1ae-8625-45b5-ab34-ad4433bc21f8","question":"Who nominated the only Featured Article on English Wikipedia about a dinosaur that was promoted in November 2016?","Level":"1","file_name":""}
|
6 |
+
{"task_id":"6f37996b-2ac7-44b0-8e68-6d28256631b4","question":"Given this table defining * on the set S = {a, b, c, d, e}\n\n|*|a|b|c|d|e|\n|---|---|---|---|---|---|\n|a|a|b|c|b|d|\n|b|b|c|a|e|c|\n|c|c|a|b|b|a|\n|d|b|e|b|e|d|\n|e|d|b|a|d|c|\n\nprovide the subset of S involved in any possible counter-examples that prove * is not commutative. Provide your answer as a comma separated list of the elements in the set in alphabetical order.","Level":"1","file_name":""}
|
7 |
+
{"task_id":"9d191bce-651d-4746-be2d-7ef8ecadb9c2","question":"Examine the video at https:\/\/www.youtube.com\/watch?v=1htKBjuUWec.\n\nWhat does Teal'c say in response to the question \"Isn't that hot?\"","Level":"1","file_name":""}
|
8 |
+
{"task_id":"cabe07ed-9eca-40ea-8ead-410ef5e83f91","question":"What is the surname of the equine veterinarian mentioned in 1.E Exercises from the chemistry materials licensed by Marisa Alviar-Agnew & Henry Agnew under the CK-12 license in LibreText's Introductory Chemistry materials as compiled 08\/21\/2023?","Level":"1","file_name":""}
|
9 |
+
{"task_id":"3cef3a44-215e-4aed-8e3b-b1e3f08063b7","question":"I'm making a grocery list for my mom, but she's a professor of botany and she's a real stickler when it comes to categorizing things. I need to add different foods to different categories on the grocery list, but if I make a mistake, she won't buy anything inserted in the wrong category. Here's the list I have so far:\n\nmilk, eggs, flour, whole bean coffee, Oreos, sweet potatoes, fresh basil, plums, green beans, rice, corn, bell pepper, whole allspice, acorns, broccoli, celery, zucchini, lettuce, peanuts\n\nI need to make headings for the fruits and vegetables. Could you please create a list of just the vegetables from my list? If you could do that, then I can figure out how to categorize the rest of the list into the appropriate categories. But remember that my mom is a real stickler, so make sure that no botanical fruits end up on the vegetable list, or she won't get them when she's at the store. Please alphabetize the list of vegetables, and place each item in a comma separated list.","Level":"1","file_name":""}
|
10 |
+
{"task_id":"99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3","question":"Hi, I'm making a pie but I could use some help with my shopping list. I have everything I need for the crust, but I'm not sure about the filling. I got the recipe from my friend Aditi, but she left it as a voice memo and the speaker on my phone is buzzing so I can't quite make out what she's saying. Could you please listen to the recipe and list all of the ingredients that my friend described? I only want the ingredients for the filling, as I have everything I need to make my favorite pie crust. I've attached the recipe as Strawberry pie.mp3.\n\nIn your response, please only list the ingredients, not any measurements. So if the recipe calls for \"a pinch of salt\" or \"two cups of ripe strawberries\" the ingredients on the list would be \"salt\" and \"ripe strawberries\".\n\nPlease format your response as a comma separated list of ingredients. Also, please alphabetize the ingredients.","Level":"1","file_name":"99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3.mp3"}
|
11 |
+
{"task_id":"305ac316-eef6-4446-960a-92d80d542f82","question":"Who did the actor who played Ray in the Polish-language version of Everybody Loves Raymond play in Magda M.? Give only the first name.","Level":"1","file_name":""}
|
12 |
+
{"task_id":"f918266a-b3e0-4914-865d-4faa564f1aef","question":"What is the final numeric output from the attached Python code?","Level":"1","file_name":"f918266a-b3e0-4914-865d-4faa564f1aef.py"}
|
13 |
+
{"task_id":"3f57289b-8c60-48be-bd80-01f8099ca449","question":"How many at bats did the Yankee with the most walks in the 1977 regular season have that same season?","Level":"1","file_name":""}
|
14 |
+
{"task_id":"1f975693-876d-457b-a649-393859e79bf3","question":"Hi, I was out sick from my classes on Friday, so I'm trying to figure out what I need to study for my Calculus mid-term next week. My friend from class sent me an audio recording of Professor Willowbrook giving out the recommended reading for the test, but my headphones are broken :(\n\nCould you please listen to the recording for me and tell me the page numbers I'm supposed to go over? I've attached a file called Homework.mp3 that has the recording. Please provide just the page numbers as a comma-delimited list. And please provide the list in ascending order.","Level":"1","file_name":"1f975693-876d-457b-a649-393859e79bf3.mp3"}
|
15 |
+
{"task_id":"840bfca7-4f7b-481a-8794-c560c340185d","question":"On June 6, 2023, an article by Carolyn Collins Petersen was published in Universe Today. This article mentions a team that produced a paper about their observations, linked at the bottom of the article. Find this paper. Under what NASA award number was the work performed by R. G. Arendt supported by?","Level":"1","file_name":""}
|
16 |
+
{"task_id":"bda648d7-d618-4883-88f4-3466eabd860e","question":"Where were the Vietnamese specimens described by Kuznetzov in Nedoshivina's 2010 paper eventually deposited? Just give me the city name without abbreviations.","Level":"1","file_name":""}
|
17 |
+
{"task_id":"cf106601-ab4f-4af9-b045-5295fe67b37d","question":"What country had the least number of athletes at the 1928 Summer Olympics? If there's a tie for a number of athletes, return the first in alphabetical order. Give the IOC country code as your answer.","Level":"1","file_name":""}
|
18 |
+
{"task_id":"a0c07678-e491-4bbc-8f0b-07405144218f","question":"Who are the pitchers with the number before and after Taishō Tamai's number as of July 2023? Give them to me in the form Pitcher Before, Pitcher After, use their last names only, in Roman characters.","Level":"1","file_name":""}
|
19 |
+
{"task_id":"7bd855d8-463d-4ed5-93ca-5fe35145f733","question":"The attached Excel file contains the sales of menu items for a local fast-food chain. What were the total sales that the chain made from food (not including drinks)? Express your answer in USD with two decimal places.","Level":"1","file_name":"7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx"}
|
|
|
20 |
{"task_id":"5a0c1adf-205e-4841-a666-7c3ef95def9d","question":"What is the first name of the only Malko Competition recipient from the 20th Century (after 1977) whose nationality on record is a country that no longer exists?","Level":"1","file_name":""}
|
|
results.csv
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Task ID,Question,Submitted Answer
|
2 |
+
8e867cd7-cff9-4e6c-867a-ff5ddc2550be,How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.,3
|
3 |
+
2d83110e-a098-4ebb-9987-066c06fa42d0,".rewsna eht sa ""tfel"" drow eht fo etisoppo eht etirw ,ecnetnes siht dnatsrednu uoy fI",right
|
4 |
+
4fc2f1ae-8625-45b5-ab34-ad4433bc21f8,Who nominated the only Featured Article on English Wikipedia about a dinosaur that was promoted in November 2016?,FunkMonk
|
5 |
+
cabe07ed-9eca-40ea-8ead-410ef5e83f91,What is the surname of the equine veterinarian mentioned in 1.E Exercises from the chemistry materials licensed by Marisa Alviar-Agnew & Henry Agnew under the CK-12 license in LibreText's Introductory Chemistry materials as compiled 08/21/2023?,not found in materials
|
6 |
+
3cef3a44-215e-4aed-8e3b-b1e3f08063b7,"I'm making a grocery list for my mom, but she's a professor of botany and she's a real stickler when it comes to categorizing things. I need to add different foods to different categories on the grocery list, but if I make a mistake, she won't buy anything inserted in the wrong category. Here's the list I have so far:
|
7 |
+
|
8 |
+
milk, eggs, flour, whole bean coffee, Oreos, sweet potatoes, fresh basil, plums, green beans, rice, corn, bell pepper, whole allspice, acorns, broccoli, celery, zucchini, lettuce, peanuts
|
9 |
+
|
10 |
+
I need to make headings for the fruits and vegetables. Could you please create a list of just the vegetables from my list? If you could do that, then I can figure out how to categorize the rest of the list into the appropriate categories. But remember that my mom is a real stickler, so make sure that no botanical fruits end up on the vegetable list, or she won't get them when she's at the store. Please alphabetize the list of vegetables, and place each item in a comma separated list.","broccoli, celery, green beans, lettuce, sweet potatoes, zucchini"
|
11 |
+
305ac316-eef6-4446-960a-92d80d542f82,Who did the actor who played Ray in the Polish-language version of Everybody Loves Raymond play in Magda M.? Give only the first name.,Wojciech
|
12 |
+
3f57289b-8c60-48be-bd80-01f8099ca449,How many at bats did the Yankee with the most walks in the 1977 regular season have that same season?,519
|
13 |
+
cf106601-ab4f-4af9-b045-5295fe67b37d,"What country had the least number of athletes at the 1928 Summer Olympics? If there's a tie for a number of athletes, return the first in alphabetical order. Give the IOC country code as your answer.",CUB
|
14 |
+
a0c07678-e491-4bbc-8f0b-07405144218f,"Who are the pitchers with the number before and after Taishō Tamai's number as of July 2023? Give them to me in the form Pitcher Before, Pitcher After, use their last names only, in Roman characters.","Yamasaki, Uehara"
|
15 |
+
5a0c1adf-205e-4841-a666-7c3ef95def9d,What is the first name of the only Malko Competition recipient from the 20th Century (after 1977) whose nationality on record is a country that no longer exists?,Claus Peter
|