Toumaima commited on
Commit
263bd0b
·
verified ·
1 Parent(s): 7820ce2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -82,9 +82,15 @@ class BasicAgent:
82
  self.tool_chain = build_tool_graph(self.agent_prompt)
83
 
84
  def format_final_answer(self, answer: str) -> str:
85
- cleaned = " ".join(answer.split())
86
- match = re.search(r"FINAL ANSWER:\s*(.*)", cleaned, re.IGNORECASE)
87
- return f"FINAL ANSWER: {match.group(1).strip()}" if match else f"FINAL ANSWER: {cleaned}"
 
 
 
 
 
 
88
 
89
  def query_groq(self, question: str) -> str:
90
  full_prompt = f"{self.agent_prompt}\n\nQuestion: {question}"
 
82
  self.tool_chain = build_tool_graph(self.agent_prompt)
83
 
84
  def format_final_answer(self, answer: str) -> str:
85
+ # Clean up whitespace
86
+ cleaned = " ".join(answer.strip().split())
87
+ # Extract only the final answer after the last occurrence of 'FINAL ANSWER:'
88
+ if "FINAL ANSWER:" in cleaned.upper():
89
+ final = re.split(r"FINAL ANSWER:\s*", cleaned, flags=re.IGNORECASE)[-1]
90
+ else:
91
+ final = cleaned
92
+ return f"FINAL ANSWER: {final.strip()}"
93
+
94
 
95
  def query_groq(self, question: str) -> str:
96
  full_prompt = f"{self.agent_prompt}\n\nQuestion: {question}"