[Frontend] Fix Kimi K2 tool call IDs for required tool choice (#46344)

Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
This commit is contained in:
Chauncey
2026-06-24 19:59:40 +00:00
committed by GitHub
parent 49f2104c53
commit 84c2f9f0fb
11 changed files with 406 additions and 178 deletions
@@ -301,7 +301,6 @@ class ParsableContext(ConversationContext):
chat_template_content_format: ChatTemplateContentFormatOption,
response_parser: Parser | None = None,
enable_auto_tools: bool = False,
tool_call_id_type: str = "random",
):
self.num_prompt_tokens = 0
self.num_output_tokens = 0
@@ -314,20 +313,8 @@ class ParsableContext(ConversationContext):
self.num_init_messages = len(response_messages)
self.finish_reason: str | None = None
self.enable_auto_tools = enable_auto_tools
self.tool_call_id_type = tool_call_id_type
self.response_parser = response_parser
if self.response_parser is None and parser_cls is not None:
chat_template_kwargs = request.build_chat_params(
default_template=chat_template,
default_template_content_format=chat_template_content_format,
).chat_template_kwargs
self.response_parser = parser_cls(
tokenizer,
tools=request.tools,
chat_template_kwargs=chat_template_kwargs,
)
self.parser_cls = parser_cls
self.request = request
@@ -365,7 +352,6 @@ class ParsableContext(ConversationContext):
reasoning=reasoning,
content=content,
tool_calls=tool_calls,
tool_call_id_type=self.tool_call_id_type,
)
)
elif completion.text:
+1 -6
View File
@@ -30,7 +30,6 @@ from vllm.engine.protocol import EngineClient
from vllm.entrypoints.chat_utils import (
ChatCompletionMessageParam,
ChatTemplateContentFormatOption,
get_tool_call_id_type,
)
from vllm.entrypoints.mcp.tool_server import ToolServer
from vllm.entrypoints.openai.engine.protocol import (
@@ -222,9 +221,6 @@ class OpenAIServingResponses(OpenAIServing):
"For gpt-oss, we ignore --enable-auto-tool-choice "
"and always enable tool use."
)
self.tool_call_id_type = get_tool_call_id_type(self.model_config)
self.enable_auto_tools = enable_auto_tools
# HACK(woosuk): This is a hack. We should use a better store.
# FIXME: If enable_store=True, this may cause a memory leak since we
@@ -272,6 +268,7 @@ class OpenAIServingResponses(OpenAIServing):
tokenizer,
request.tools,
chat_template_kwargs=chat_template_kwargs,
model_config=self.model_config,
)
def _validate_generator_input(
@@ -493,7 +490,6 @@ class OpenAIServingResponses(OpenAIServing):
chat_template=self.chat_template,
chat_template_content_format=self.chat_template_content_format,
enable_auto_tools=self.enable_auto_tools,
tool_call_id_type=self.tool_call_id_type,
)
else:
context = SimpleContext(
@@ -1073,7 +1069,6 @@ class OpenAIServingResponses(OpenAIServing):
content=content,
tool_calls=tool_calls,
logprobs=logprobs,
tool_call_id_type=self.tool_call_id_type,
)
# Fallback when no parser is configured
+1 -7
View File
@@ -45,7 +45,6 @@ def build_response_output_items(
content: str | None,
tool_calls: list[FunctionCall] | None,
logprobs: list[Logprob] | None = None,
tool_call_id_type: str = "random",
) -> list[ResponseOutputItem]:
outputs: list[ResponseOutputItem] = []
@@ -86,12 +85,7 @@ def build_response_output_items(
ResponseFunctionToolCall(
id=f"fc_{random_uuid()}",
call_id=tool_call.id
if tool_call.id
else make_tool_call_id(
id_type=tool_call_id_type,
func_name=tool_call.name,
idx=idx,
),
or make_tool_call_id(func_name=tool_call.name, idx=idx),
type="function_call",
status="completed",
name=tool_call.name,