"docs/vscode:/vscode.git/clone" did not exist on "aa1e77a19ce658abcbaa0836f96878a7ae9dea84"
Unverified Commit 17fec3af authored by mondaylord's avatar mondaylord Committed by GitHub
Browse files

[Bugfix] Fix missing first token in tool calls during reasoning-to-tool transition (#30671)


Signed-off-by: default avatarmondaylord <20212010046@fudan.edu.cn>
parent 855b101d
...@@ -964,21 +964,9 @@ class OpenAIServingChat(OpenAIServing): ...@@ -964,21 +964,9 @@ class OpenAIServingChat(OpenAIServing):
assert reasoning_end_arr is not None assert reasoning_end_arr is not None
output_token_ids = as_list(output.token_ids) output_token_ids = as_list(output.token_ids)
if not reasoning_end_arr[i]: if not reasoning_end_arr[i]:
delta_message = (
reasoning_parser.extract_reasoning_streaming(
previous_text,
current_text,
delta_text,
previous_token_ids,
current_token_ids,
output_token_ids,
)
)
# When encountering think end id in prompt_token_ids # When encountering think end id in prompt_token_ids
# i.e {"enable_thinking": False}, # i.e {"enable_thinking": False},
# set reasoning status to end. # set reasoning status to end.
# Remove the text and token ids related
# to 'reasoning'.
if ( if (
res.prompt_token_ids res.prompt_token_ids
and reasoning_parser.is_reasoning_end( and reasoning_parser.is_reasoning_end(
...@@ -987,11 +975,19 @@ class OpenAIServingChat(OpenAIServing): ...@@ -987,11 +975,19 @@ class OpenAIServingChat(OpenAIServing):
): ):
reasoning_end_arr[i] = True reasoning_end_arr[i] = True
current_token_ids = output_token_ids current_token_ids = output_token_ids
if delta_message and delta_message.content: # Don't update current_text, keep it as is from delta
current_text = delta_message.content
delta_message.content = None
else: else:
current_text = "" delta_message = (
reasoning_parser.extract_reasoning_streaming(
previous_text,
current_text,
delta_text,
previous_token_ids,
current_token_ids,
output_token_ids,
)
)
# When encountering think end id in delta_token_ids, # When encountering think end id in delta_token_ids,
# set reasoning status to end. # set reasoning status to end.
# Remove the text and token ids related # Remove the text and token ids related
...@@ -1010,7 +1006,7 @@ class OpenAIServingChat(OpenAIServing): ...@@ -1010,7 +1006,7 @@ class OpenAIServingChat(OpenAIServing):
current_text = "" current_text = ""
# handle tool calls only after reasoning is done, # handle tool calls only after reasoning is done,
else: if reasoning_end_arr[i]:
delta_token_ids = output_token_ids delta_token_ids = output_token_ids
# First time to tool call, # First time to tool call,
# add the remaining text and token ids # add the remaining text and token ids
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment