jcleee commited on
Commit
ba48c4c
·
verified ·
1 Parent(s): d6fece8

Update Gradio_UI.py

Browse files
Files changed (1) hide show
  1. Gradio_UI.py +13 -18
Gradio_UI.py CHANGED
@@ -153,25 +153,20 @@ def stream_to_gradio(
153
  ):
154
  yield message
155
 
156
- final_step = step_log # Final ActionStep
157
-
158
- # Debugging tool calls to inspect final_answer structure
159
- print("DEBUG TOOL CALLS:", final_step.tool_calls)
160
-
161
- # Attempt to get the direct tool_output
162
- final_output = getattr(final_step, "tool_output", None)
163
-
164
- # Fallback if tool_output is missing
165
- if not final_output and getattr(final_step, "tool_calls", None):
166
- for call in final_step.tool_calls:
167
- if call.name == "final_answer":
168
- print("DEBUG FINAL ANSWER TOOL CALL:", call)
169
- # Try the `output` field if present (some agents set this explicitly)
170
- final_output = getattr(call, "output", None)
171
- if final_output is None:
172
- # Fallback to arguments dict
173
  final_output = call.arguments.get("answer")
174
- break
 
175
 
176
  final_output = handle_agent_output_types(final_output)
177
 
 
153
  ):
154
  yield message
155
 
156
+ from smolagents.agents import FinalAnswerStep
157
+
158
+ # Safely extract the final output from the last step
159
+ if isinstance(step_log, FinalAnswerStep):
160
+ final_output = step_log.final_answer
161
+ else:
162
+ # If not a FinalAnswerStep, fallback to tool_output or tool_calls
163
+ final_output = getattr(step_log, "tool_output", None)
164
+ if not final_output and hasattr(step_log, "tool_calls"):
165
+ for call in step_log.tool_calls:
166
+ if call.name == "final_answer":
 
 
 
 
 
 
167
  final_output = call.arguments.get("answer")
168
+ break
169
+
170
 
171
  final_output = handle_agent_output_types(final_output)
172