Spaces:
Sleeping
Sleeping
Update Gradio_UI.py
Browse files- Gradio_UI.py +13 -18
Gradio_UI.py
CHANGED
|
@@ -153,25 +153,20 @@ def stream_to_gradio(
|
|
| 153 |
):
|
| 154 |
yield message
|
| 155 |
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
#
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 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 |
-
|
|
|
|
| 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 |
|