Spaces:
Running
Running
Fix: Separate thinking and summary fields during streaming
Browse filesPreviously:
- Thinking field accumulated ALL tokens (thinking + summary)
- Summary field showed parsed summary
- Result: Both fields showed overlapping content
Now:
- Thinking field shows ONLY thinking blocks (content inside tags)
- Summary field shows ONLY summary (content outside tags)
- Both fields update in real-time during streaming
Changes:
- Remove token accumulation in thinking field (line 162)
- Parse and update both fields on every token
- Always update both fields (not just when truthy)
- Ensures clean separation of thinking vs summary content
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
app.py
CHANGED
|
@@ -157,25 +157,24 @@ def summarize_streaming(file_obj, max_tokens: int = 2048, temperature: float = 0
|
|
| 157 |
# Convert to Traditional Chinese (Taiwan)
|
| 158 |
converted = converter.convert(content)
|
| 159 |
full_response += converted
|
| 160 |
-
|
| 161 |
-
#
|
| 162 |
-
current_thinking += converted
|
| 163 |
-
|
| 164 |
-
# Try to extract summary (content outside thinking tags)
|
| 165 |
thinking_blocks, summary = parse_thinking_blocks(full_response)
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
# Yield both fields on every token
|
| 170 |
yield (current_thinking, current_summary)
|
| 171 |
|
| 172 |
-
# Final parse
|
| 173 |
final_thinking, final_summary = parse_thinking_blocks(full_response)
|
| 174 |
-
if final_thinking
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
current_summary = warning_msg + final_summary
|
| 178 |
-
|
| 179 |
# Final yield
|
| 180 |
yield (current_thinking, current_summary)
|
| 181 |
|
|
|
|
| 157 |
# Convert to Traditional Chinese (Taiwan)
|
| 158 |
converted = converter.convert(content)
|
| 159 |
full_response += converted
|
| 160 |
+
|
| 161 |
+
# Parse thinking blocks and summary from accumulated response
|
|
|
|
|
|
|
|
|
|
| 162 |
thinking_blocks, summary = parse_thinking_blocks(full_response)
|
| 163 |
+
|
| 164 |
+
# Update thinking field (only show thinking blocks, not raw stream)
|
| 165 |
+
current_thinking = thinking_blocks if thinking_blocks else ""
|
| 166 |
+
|
| 167 |
+
# Update summary field (only show summary, not thinking blocks)
|
| 168 |
+
current_summary = warning_msg + summary if summary else warning_msg
|
| 169 |
+
|
| 170 |
# Yield both fields on every token
|
| 171 |
yield (current_thinking, current_summary)
|
| 172 |
|
| 173 |
+
# Final parse to ensure consistency (redundant but safe)
|
| 174 |
final_thinking, final_summary = parse_thinking_blocks(full_response)
|
| 175 |
+
current_thinking = final_thinking if final_thinking else ""
|
| 176 |
+
current_summary = warning_msg + final_summary if final_summary else warning_msg
|
| 177 |
+
|
|
|
|
|
|
|
| 178 |
# Final yield
|
| 179 |
yield (current_thinking, current_summary)
|
| 180 |
|