ekabaruh commited on
Commit
ea70d9a
·
verified ·
1 Parent(s): bbfe866

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -26
app.py CHANGED
@@ -39,12 +39,12 @@ class BasicAgent:
39
  FINAL ANSWER: [YOUR FINAL ANSWER]"
40
  """
41
 
42
- def __init__(self, model_name: str = "gpt-3.5-turbo", api_key: str = None):
43
  """
44
  Initialize the BasicAgent with the specified LLM.
45
 
46
  Args:
47
- model_name: The name of the model to use (defaults to gpt-3.5-turbo)
48
  api_key: OpenAI API key (defaults to environment variable)
49
  """
50
  # Use the provided API key or fall back to the environment variable
@@ -144,34 +144,30 @@ class BasicAgent:
144
  Reasoning:
145
  {all_thoughts}
146
 
147
- Format your FINAL ANSWER following these strict rules:
148
  - For numbers: No commas in large numbers, no units unless explicitly requested.
149
  - For strings: Minimal, no articles, no abbreviations.
150
  - For lists: Comma-separated values.
151
  - Use digits in words unless otherwise stated.
152
 
153
- IMPORTANT: Your answer must be concise and precise. Do not include explanations in your final answer.
 
154
 
155
- Your response must follow this exact format:
156
- FINAL ANSWER: [concise answer following the formatting rules above]
157
  """)
158
  ]
159
 
160
  try:
161
  response = self.llm.invoke(prompt)
 
162
 
163
- # Extract the final answer using regex
164
- final_answer_match = re.search(r'FINAL ANSWER:\s*(.*?)(?:\n|$)', response.content)
165
- if final_answer_match:
166
- return final_answer_match.group(1).strip()
167
- elif "FINAL ANSWER:" in response.content:
168
- parts = response.content.split("FINAL ANSWER:")
169
- if len(parts) > 1:
170
- return parts[1].strip()
171
- else:
172
- return "Error: Malformed answer format."
173
- else:
174
- return response.content.strip()
175
  except Exception as e:
176
  return f"Error formatting answer: {str(e)}"
177
 
@@ -215,17 +211,12 @@ class BasicAgent:
215
  # Step 4: Format final answer
216
  final_answer = self.format_answer(question, thoughts)
217
 
218
- # Format the response according to Gaia requirements
219
- formatted_response = "You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template:\nFINAL ANSWER: [YOUR FINAL ANSWER]\n\n"
220
- formatted_response += "\n\n".join(thoughts)
221
- formatted_response += f"\n\nFINAL ANSWER: {final_answer}"
222
-
223
- print(f"Agent returning answer with final part: {final_answer}")
224
  return final_answer
225
  except Exception as e:
226
  print(f"Error running agent workflow: {e}")
227
- # Fallback response
228
- return "An error occurred while processing the question. FINAL ANSWER: Error"
229
 
230
  def run_and_submit_all( profile: gr.OAuthProfile | None):
231
  """
 
39
  FINAL ANSWER: [YOUR FINAL ANSWER]"
40
  """
41
 
42
+ def __init__(self, model_name: str = "gpt-4.1", api_key: str = None):
43
  """
44
  Initialize the BasicAgent with the specified LLM.
45
 
46
  Args:
47
+ model_name: The name of the model to use (defaults to gpt-4.1)
48
  api_key: OpenAI API key (defaults to environment variable)
49
  """
50
  # Use the provided API key or fall back to the environment variable
 
144
  Reasoning:
145
  {all_thoughts}
146
 
147
+ Format your answer following these strict rules:
148
  - For numbers: No commas in large numbers, no units unless explicitly requested.
149
  - For strings: Minimal, no articles, no abbreviations.
150
  - For lists: Comma-separated values.
151
  - Use digits in words unless otherwise stated.
152
 
153
+ IMPORTANT: Your answer must be concise, precise and EXACT. Do not include explanations.
154
+ Do not include a prefix like "FINAL ANSWER:" in your response. Just provide the exact answer.
155
 
156
+ For example, if the answer is "5", just respond with "5".
157
+ If the answer is "New York", just respond with "New York".
158
  """)
159
  ]
160
 
161
  try:
162
  response = self.llm.invoke(prompt)
163
+ answer = response.content.strip()
164
 
165
+ # Remove any "FINAL ANSWER:" prefix if it exists
166
+ if "FINAL ANSWER:" in answer:
167
+ parts = answer.split("FINAL ANSWER:")
168
+ answer = parts[1].strip()
169
+
170
+ return answer
 
 
 
 
 
 
171
  except Exception as e:
172
  return f"Error formatting answer: {str(e)}"
173
 
 
211
  # Step 4: Format final answer
212
  final_answer = self.format_answer(question, thoughts)
213
 
214
+ print(f"Agent returning answer: {final_answer}")
 
 
 
 
 
215
  return final_answer
216
  except Exception as e:
217
  print(f"Error running agent workflow: {e}")
218
+ # Fallback response - return just the error message without the prefix
219
+ return "Error"
220
 
221
  def run_and_submit_all( profile: gr.OAuthProfile | None):
222
  """