likki1715 commited on
Commit
43dad42
·
verified ·
1 Parent(s): 238a105

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -170,14 +170,6 @@ Rules for the ANSWER:
170
  response = self.call_llm(conversation)
171
  print(f" LLM [{iteration}]: \n{response[:300]}...\n")
172
 
173
- answer_match = re.search(r'ANSWER:\s*(.+?)(?:\n|$)', response, re.IGNORECASE)
174
- if answer_match:
175
- answer = answer_match.group(1).strip()
176
- print(f" {answer}")
177
- return answer
178
-
179
- tool_result = None
180
-
181
  search_match = re.search(r'SEARCH:\s*(.+?)(?:\n|$)', response)
182
  wiki_match = re.search(r'WIKIPEDIA:\s*(.+?)(?:\n|$)', response)
183
  python_match = re.search(r'PYTHON:\s*```(?:python)?\n?(.*?)```', response, re.DOTALL)
@@ -185,6 +177,9 @@ Rules for the ANSWER:
185
  if not python_match:
186
  python_match = re.search(r'PYTHON:\s*(.+?)(?:\nSEARCH|\nWIKIPEDIA|\nANSWER|$)', response, re.DOTALL)
187
 
 
 
 
188
  if search_match:
189
  query = search_match.group(1).strip()
190
  print(f" Tool: web_search({query})")
@@ -198,6 +193,13 @@ Rules for the ANSWER:
198
  print(f" Tool: python({code[:50]}...)")
199
  tool_result = f"Python output:\n{run_python(code)}"
200
  else:
 
 
 
 
 
 
 
201
  tool_result = "No valid tool call detected. Please use SEARCH, WIKIPEDIA, PYTHON, or ANSWER."
202
 
203
  conversation += f"\n\nAssistant: {response}\n\nTool Result: {tool_result}\n\nNow provide your next THOUGHT and tool, or your ANSWER."
 
170
  response = self.call_llm(conversation)
171
  print(f" LLM [{iteration}]: \n{response[:300]}...\n")
172
 
 
 
 
 
 
 
 
 
173
  search_match = re.search(r'SEARCH:\s*(.+?)(?:\n|$)', response)
174
  wiki_match = re.search(r'WIKIPEDIA:\s*(.+?)(?:\n|$)', response)
175
  python_match = re.search(r'PYTHON:\s*```(?:python)?\n?(.*?)```', response, re.DOTALL)
 
177
  if not python_match:
178
  python_match = re.search(r'PYTHON:\s*(.+?)(?:\nSEARCH|\nWIKIPEDIA|\nANSWER|$)', response, re.DOTALL)
179
 
180
+ tool_result = None
181
+
182
+ # ORCHESTRATION FIX: Check for tools FIRST.
183
  if search_match:
184
  query = search_match.group(1).strip()
185
  print(f" Tool: web_search({query})")
 
193
  print(f" Tool: python({code[:50]}...)")
194
  tool_result = f"Python output:\n{run_python(code)}"
195
  else:
196
+ # ONLY look for an answer if NO tools were called.
197
+ answer_match = re.search(r'ANSWER:\s*(.+?)(?:\n|$)', response, re.IGNORECASE)
198
+ if answer_match:
199
+ answer = answer_match.group(1).strip()
200
+ print(f" {answer}")
201
+ return answer
202
+
203
  tool_result = "No valid tool call detected. Please use SEARCH, WIKIPEDIA, PYTHON, or ANSWER."
204
 
205
  conversation += f"\n\nAssistant: {response}\n\nTool Result: {tool_result}\n\nNow provide your next THOUGHT and tool, or your ANSWER."