[Feature][Parser] Support include_reasoning param for non-Harmony models (#44301)

Signed-off-by: Alberto Perdomo <aperdomo@redhat.com>
Co-authored-by: Chauncey <chaunceyjiang@gmail.com>
This commit is contained in:
alberto
2026-07-10 15:34:02 +08:00
committed by GitHub
co-authored by Chauncey
parent e5588e49bc
commit 5715fde12c
13 changed files with 765 additions and 26 deletions
@@ -600,19 +600,8 @@ class OpenAIServingChat(GenerateBaseServing):
prompt_token_ids=res.prompt_token_ids,
finished=output.finish_reason is not None,
)
if delta_message is not None:
if delta_message.tool_calls:
tools_streamed[i] = True
if (
delta_message.reasoning
and not request.include_reasoning
):
delta_message.reasoning = None
if not (
delta_message.content or delta_message.tool_calls
):
delta_message = None
if delta_message is not None and delta_message.tool_calls:
tools_streamed[i] = True
# handle streaming just a content delta (no parsers)
else:
@@ -627,13 +616,22 @@ class OpenAIServingChat(GenerateBaseServing):
# "control token" for tool calls or the parser otherwise
# wasn't ready to send a token, then
# get the next token without streaming a chunk
# When reasoning is hidden, suppress per-token
# metadata (logprobs, token_ids) on every chunk to
# prevent leaking reasoning tokens through decoded
# token text in logprob entries or raw token IDs.
hide_stream_metadata = (
not request.include_reasoning and parser is not None
)
if hide_stream_metadata:
logprobs = None
if delta_message is None:
# NOTE: If return_token_ids is enabled, we still need to
# send a chunk with token_ids even if delta_message is None
# to ensure all tokens are included in the response
if (
output.finish_reason is None
and not request.return_token_ids
if output.finish_reason is None and (
not request.return_token_ids or hide_stream_metadata
):
continue
delta_message = DeltaMessage()
@@ -666,6 +664,10 @@ class OpenAIServingChat(GenerateBaseServing):
delta=True,
)
include_token_ids = (
request.return_token_ids and not hide_stream_metadata
)
if output.finish_reason is None:
# Send token-by-token response for each request.n
choice_data = ChatCompletionResponseStreamChoice(
@@ -674,9 +676,7 @@ class OpenAIServingChat(GenerateBaseServing):
logprobs=logprobs,
finish_reason=None,
token_ids=(
as_list(output.token_ids)
if request.return_token_ids
else None
as_list(output.token_ids) if include_token_ids else None
),
)
@@ -704,9 +704,7 @@ class OpenAIServingChat(GenerateBaseServing):
finish_reason=finish_reason_,
stop_reason=output.stop_reason,
token_ids=(
as_list(output.token_ids)
if request.return_token_ids
else None
as_list(output.token_ids) if include_token_ids else None
),
)
@@ -883,12 +881,16 @@ class OpenAIServingChat(GenerateBaseServing):
enable_auto_tools=self.enable_auto_tools,
model_output_token_ids=token_ids,
)
suppress_metadata = not request.include_reasoning and parser is not None
if not request.include_reasoning:
reasoning = None
if suppress_metadata:
logprobs = None
else:
reasoning = None
content = output.text
tool_calls = []
suppress_metadata = False
auto_tools_called = False
is_named_tool_choice = (
@@ -982,7 +984,9 @@ class OpenAIServingChat(GenerateBaseServing):
else "stop",
stop_reason=output.stop_reason,
token_ids=(
as_list(output.token_ids) if request.return_token_ids else None
as_list(output.token_ids)
if request.return_token_ids and not suppress_metadata
else None
),
routed_experts=routed_experts_b64,
)