yoshizen commited on
Commit
90346c1
·
verified ·
1 Parent(s): 51a187d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -69,10 +69,11 @@ class LLMGAIAAgent:
69
  # Clean up the response if needed
70
  response = self._clean_response(response)
71
 
72
- return response
 
73
  except Exception as e:
74
  print(f"Error generating response: {e}")
75
- return self._fallback_response(question)
76
 
77
  def _prepare_prompt(self, question: str) -> str:
78
  """Prepare an appropriate prompt based on the question type."""
@@ -160,7 +161,10 @@ class GAIAAgent:
160
  question_type = self._classify_question(question)
161
 
162
  # Use the appropriate handler
163
- return self.handlers[question_type](question)
 
 
 
164
 
165
  def _classify_question(self, question: str) -> str:
166
  """Classify the question into one of the supported types."""
@@ -340,9 +344,15 @@ class EvaluationRunner:
340
  try:
341
  # Call agent with task_id parameter if supported
342
  if hasattr(agent, '__code__') and 'task_id' in agent.__code__.co_varnames:
343
- submitted_answer = agent(question_text, task_id)
344
  else:
345
- submitted_answer = agent(question_text)
 
 
 
 
 
 
346
 
347
  answers_payload.append({
348
  "task_id": task_id,
@@ -351,7 +361,8 @@ class EvaluationRunner:
351
  results_log.append({
352
  "Task ID": task_id,
353
  "Question": question_text,
354
- "Submitted Answer": submitted_answer
 
355
  })
356
  except Exception as e:
357
  print(f"Error running agent on task {task_id}: {e}")
 
69
  # Clean up the response if needed
70
  response = self._clean_response(response)
71
 
72
+ # Return JSON with final_answer key
73
+ return json.dumps({"final_answer": response})
74
  except Exception as e:
75
  print(f"Error generating response: {e}")
76
+ return json.dumps({"final_answer": self._fallback_response(question)})
77
 
78
  def _prepare_prompt(self, question: str) -> str:
79
  """Prepare an appropriate prompt based on the question type."""
 
161
  question_type = self._classify_question(question)
162
 
163
  # Use the appropriate handler
164
+ answer = self.handlers[question_type](question)
165
+
166
+ # Return JSON with final_answer key
167
+ return json.dumps({"final_answer": answer})
168
 
169
  def _classify_question(self, question: str) -> str:
170
  """Classify the question into one of the supported types."""
 
344
  try:
345
  # Call agent with task_id parameter if supported
346
  if hasattr(agent, '__code__') and 'task_id' in agent.__code__.co_varnames:
347
+ json_response = agent(question_text, task_id)
348
  else:
349
+ json_response = agent(question_text)
350
+
351
+ # Parse the JSON response
352
+ response_obj = json.loads(json_response)
353
+
354
+ # Extract the final_answer for submission
355
+ submitted_answer = response_obj.get("final_answer", "")
356
 
357
  answers_payload.append({
358
  "task_id": task_id,
 
361
  results_log.append({
362
  "Task ID": task_id,
363
  "Question": question_text,
364
+ "Submitted Answer": submitted_answer,
365
+ "Full Response": json_response
366
  })
367
  except Exception as e:
368
  print(f"Error running agent on task {task_id}: {e}")