File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3821,6 +3821,10 @@ def set_last_text(out, text):
38213821 before_tag = item_text [: match .start ()]
38223822 after_tag = item_text [match .end () :]
38233823
3824+ # Tag in prose text, skip it.
3825+ if before_tag .strip ():
3826+ continue
3827+
38243828 # Keep only text before the tag in the message
38253829 set_last_text (output , before_tag )
38263830
@@ -4381,6 +4385,14 @@ async def flush_pending_delta_data(threshold: int = 0):
43814385 )
43824386 reasoning_details_chunk = delta .get ('reasoning_details' )
43834387
4388+ # Native counterpart of `before_tag.strip()`: skip reasoning that
4389+ # arrives once the answer has begun.
4390+ if reasoning_content and output and output [- 1 ].get ('type' ) == 'message' and '' .join (
4391+ p .get ('text' , '' ) for p in output [- 1 ].get ('content' , [])
4392+ ).strip ():
4393+ reasoning_content = ''
4394+ reasoning_details_chunk = None
4395+
43844396 # Only create a reasoning item for visible reasoning text.
43854397 # Details-only deltas (e.g. Gemini encrypted blobs) are
43864398 # buffered to avoid splitting the assistant message mid-stream.
You can’t perform that action at this time.
0 commit comments