A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 14, 05:30 UTC
Fix a robust parsing issue in KimiK2ToolParser that causes IndexError (#27565)
Signed-off-by: wangln19 <wanglinian@dev.wanglinian.msh-dev.svc.cluster.local> Co-authored-by: wangln19 <wanglinian@dev.wanglinian.msh-dev.svc.cluster.local>
wangln19 committed
Oct 28, 2025 at 19:11 UTC
2fa90bda27870467c7922547b826c3065bfad556
2 files changed
+7
-7
tests/tool_use/test_kimi_k2_tool_parser.py
+3
-3
@@ -37,11 +37,11 @@ def assert_tool_calls(
37
assert actual_tool_call.type == "function"
38
assert actual_tool_call.function == expected_tool_call.function
39
40
- # assert tool call id format
41
- assert actual_tool_call.id.startswith("functions.")
40
+ # assert tool call id format: should contain function name and numeric index
41
+ # Format can be either "functions.func_name:0" or "func_name:0"
42
assert actual_tool_call.id.split(":")[-1].isdigit()
43
assert (
44
- actual_tool_call.id.split(".")[1].split(":")[0]
44
+ actual_tool_call.id.split(":")[0].split(".")[-1]
45
== expected_tool_call.function.name
46
)
47
vllm/entrypoints/openai/tool_parsers/kimi_k2_tool_parser.py
+4
-4
@@ -96,8 +96,8 @@ class KimiK2ToolParser(ToolParser):
96
tool_calls = []
97
for match in function_call_tuples:
98
function_id, function_args = match
99
- # function_id: functions.get_weather:0
100
- function_name = function_id.split(".")[1].split(":")[0]
99
+ # function_id: functions.get_weather:0 or get_weather:0
100
+ function_name = function_id.split(":")[0].split(".")[-1]
101
tool_calls.append(
102
ToolCall(
103
id=function_id,
@@ -254,7 +254,7 @@ class KimiK2ToolParser(ToolParser):
254
)
255
if current_tool_call_matches:
256
tool_id, tool_args = current_tool_call_matches.groups()
257
- tool_name = tool_id.split(".")[1].split(":")[0]
257
+ tool_name = tool_id.split(":")[0].split(".")[-1]
258
current_tool_call["id"] = tool_id
259
current_tool_call["name"] = tool_name
260
current_tool_call["arguments"] = tool_args
@@ -264,7 +264,7 @@ class KimiK2ToolParser(ToolParser):
264
)
265
if current_tool_call_name_matches:
266
(tool_id_str,) = current_tool_call_name_matches.groups()
267
- tool_name = tool_id_str.split(".")[1].split(":")[0]
267
+ tool_name = tool_id_str.split(":")[0].split(".")[-1]
268
current_tool_call["id"] = tool_id_str
269
current_tool_call["name"] = tool_name
270
current_tool_call["arguments"] = ""