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