Fix Qwen3 streaming content routing (#40820)

Signed-off-by: xy3 <120182408@qq.com>
Signed-off-by: sfeng33 <4florafeng@gmail.com>
Co-authored-by: sfeng33 <4florafeng@gmail.com>
This commit is contained in:
xy3
2026-05-06 17:22:01 -04:00
committed by GitHub
co-authored by sfeng33
parent deb737e323
commit 50acdc5b5c
4 changed files with 220 additions and 7 deletions
+9 -7
View File
@@ -636,15 +636,11 @@ class DelegatingParser(Parser):
def _in_reasoning_phase(self, state: StreamState) -> bool:
if self._reasoning_parser is None:
return False
if self._tool_parser is None:
return True
return not state.reasoning_ended
def _in_tool_call_phase(self, state: StreamState) -> bool:
if self._tool_parser is None:
return False
if self._reasoning_parser is None:
return True
return state.reasoning_ended
def parse_delta(
@@ -658,7 +654,9 @@ class DelegatingParser(Parser):
if not state.prompt_reasoning_checked and prompt_token_ids is not None:
state.prompt_reasoning_checked = True
if self.is_reasoning_end(prompt_token_ids):
if self._reasoning_parser is None or self.is_reasoning_end(
prompt_token_ids
):
state.reasoning_ended = True
current_text = state.previous_text + delta_text
@@ -709,8 +707,12 @@ class DelegatingParser(Parser):
)
)
# No parsers: pass through as content
if self._reasoning_parser is None and self._tool_parser is None:
# No phase active: pass through as content
if (
delta_message is None
and not self._in_reasoning_phase(state)
and not self._in_tool_call_phase(state)
):
delta_message = DeltaMessage(content=delta_text)
state.previous_text = current_text