Spaces:
Sleeping
Sleeping
add answerdatamanager usage
Browse files- simuGAIA.py +23 -30
simuGAIA.py
CHANGED
@@ -16,6 +16,7 @@ import traceback
|
|
16 |
|
17 |
# Import our agent
|
18 |
from agent import QAgent
|
|
|
19 |
|
20 |
# (Keep Constants as is)
|
21 |
# --- Constants ---
|
@@ -229,6 +230,10 @@ def run_simuGAIA_all( profile: gr.OAuthProfile | None, submit: Optional[bool] =
|
|
229 |
print(f"An unexpected error occurred fetching questions: {e}")
|
230 |
return f"An unexpected error occurred fetching questions: {e}", None
|
231 |
|
|
|
|
|
|
|
|
|
232 |
# 3. Run your Agent
|
233 |
results_log = []
|
234 |
answers_payload = []
|
@@ -237,41 +242,29 @@ def run_simuGAIA_all( profile: gr.OAuthProfile | None, submit: Optional[bool] =
|
|
237 |
for item in questions_data:
|
238 |
task_id = item.get("task_id")
|
239 |
question_text = item.get("question")
|
|
|
240 |
if not task_id or question_text is None:
|
241 |
print(f"Skipping item with missing task_id or question: {item}")
|
242 |
continue
|
243 |
try:
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
try:
|
258 |
-
with open(json_path, "r", encoding="utf-8") as f:
|
259 |
-
data = json.load(f)
|
260 |
-
if not isinstance(data, list):
|
261 |
-
data = []
|
262 |
-
except (json.JSONDecodeError, ValueError):
|
263 |
-
data = []
|
264 |
-
else:
|
265 |
-
data = []
|
266 |
-
data.append(record)
|
267 |
-
with open(json_path, "w", encoding="utf-8") as f:
|
268 |
-
json.dump(data, f, ensure_ascii=False, indent=2)
|
269 |
-
except Exception as e:
|
270 |
-
print(f"Error saving to {json_path}: {e}")
|
271 |
-
|
272 |
-
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
273 |
else:
|
274 |
-
|
|
|
|
|
|
|
275 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
276 |
|
277 |
|
|
|
16 |
|
17 |
# Import our agent
|
18 |
from agent import QAgent
|
19 |
+
from answer_data_manager import AnswerDataManager
|
20 |
|
21 |
# (Keep Constants as is)
|
22 |
# --- Constants ---
|
|
|
230 |
print(f"An unexpected error occurred fetching questions: {e}")
|
231 |
return f"An unexpected error occurred fetching questions: {e}", None
|
232 |
|
233 |
+
# 2.5 Awaken the AnswerDataManager to get and store already answerd questions
|
234 |
+
manager = AnswerDataManager(already_answered.json")
|
235 |
+
manager.load_data()
|
236 |
+
|
237 |
# 3. Run your Agent
|
238 |
results_log = []
|
239 |
answers_payload = []
|
|
|
242 |
for item in questions_data:
|
243 |
task_id = item.get("task_id")
|
244 |
question_text = item.get("question")
|
245 |
+
submitted_answer = "NO ANSWER YET"
|
246 |
if not task_id or question_text is None:
|
247 |
print(f"Skipping item with missing task_id or question: {item}")
|
248 |
continue
|
249 |
try:
|
250 |
+
existing_answer = manager.get_answer_by_task_id(task_id)
|
251 |
+
if not existing_answer:
|
252 |
+
# then we call the agent
|
253 |
+
if question_text.startswith(".rewsna eht sa"): # ("How many studio albums"): <--- REMOVE THAT FOR ALL QUESTIONS
|
254 |
+
print(f"First question detected. INVOKING AGENT! Be careful!")
|
255 |
+
submitted_answer = agent.invoke(question_text)
|
256 |
+
|
257 |
+
# Save answer, task_id, and question_text to already_answered.json
|
258 |
+
manager.add_answer(task_id, question_text, submitted_answer)
|
259 |
+
|
260 |
+
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
261 |
+
else:
|
262 |
+
submitted_answer = "NO AGENT INVOKED"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
263 |
else:
|
264 |
+
# then we get answer already found from archive
|
265 |
+
submitted_answer = existing_answer['submitted_answer']
|
266 |
+
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
267 |
+
|
268 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
269 |
|
270 |
|