Luigi Claude Sonnet 4.5 commited on
Commit
7b4eca1
·
1 Parent(s): 62499af

Fix: Separate thinking and summary fields during streaming

Browse files

Previously:
- 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>

Files changed (1) hide show
  1. app.py +13 -14
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
- # Show raw output in thinking field (token by token)
162
- current_thinking += converted
163
-
164
- # Try to extract summary (content outside thinking tags)
165
  thinking_blocks, summary = parse_thinking_blocks(full_response)
166
- if summary:
167
- current_summary = warning_msg + summary
168
-
 
 
 
 
169
  # Yield both fields on every token
170
  yield (current_thinking, current_summary)
171
 
172
- # Final parse at the end
173
  final_thinking, final_summary = parse_thinking_blocks(full_response)
174
- if final_thinking:
175
- current_thinking = final_thinking
176
- if final_summary:
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