[Bugfix][Frontend] Preserve token IDs in chat derender responses (#61065)
Signed-off-by: Ting Sun <suntcrick@gmail.com>
This commit is contained in:
@@ -160,6 +160,11 @@ class OnlineDerenderer:
|
||||
else {}
|
||||
)
|
||||
|
||||
return_token_ids = (
|
||||
chat_request is not None
|
||||
and chat_request.return_token_ids
|
||||
and (not has_parser or chat_request.include_reasoning)
|
||||
)
|
||||
for choice in generate_response.choices:
|
||||
if not choice.token_ids:
|
||||
raise ValueError(f"choice {choice.index} has empty or null token_ids")
|
||||
@@ -201,6 +206,7 @@ class OnlineDerenderer:
|
||||
message=message,
|
||||
logprobs=resolved_logprobs,
|
||||
finish_reason=choice.finish_reason,
|
||||
token_ids=choice.token_ids if return_token_ids else None,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -432,6 +438,7 @@ class OnlineDerenderer:
|
||||
stream_choices: list[ChatCompletionResponseStreamChoice] = []
|
||||
updated_state = state
|
||||
|
||||
return_token_ids = chat_request is not None and chat_request.return_token_ids
|
||||
for choice in generate_chunk.choices:
|
||||
delta_tids = choice.token_ids or []
|
||||
new_text, updated_state = await self._detokenize_delta_async(
|
||||
@@ -477,6 +484,7 @@ class OnlineDerenderer:
|
||||
delta=delta,
|
||||
logprobs=resolved_logprobs,
|
||||
finish_reason=choice.finish_reason,
|
||||
token_ids=choice.token_ids if return_token_ids else None,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -583,6 +591,10 @@ class OnlineDerenderer:
|
||||
tools_streamed = state.tools_streamed
|
||||
last_tool_call_ids = list(state.last_tool_call_ids)
|
||||
|
||||
return_token_ids = (
|
||||
chat_request.return_token_ids and chat_request.include_reasoning
|
||||
)
|
||||
|
||||
# At most one choice: the caller (derender_chat_stream) already
|
||||
# rejects >1 before dispatching here. role_sent/tools_streamed/
|
||||
# output_token_ids below are updated for that single choice, not
|
||||
@@ -660,6 +672,7 @@ class OnlineDerenderer:
|
||||
index=choice.index,
|
||||
delta=delta_message,
|
||||
finish_reason=finish_reason,
|
||||
token_ids=choice.token_ids if return_token_ids else None,
|
||||
)
|
||||
stream_choices.append(
|
||||
maybe_filter_parallel_tool_calls(stream_choice, chat_request)
|
||||
|
||||
Reference in New Issue
Block a user