diff --git a/tests/tool_use/test_kimi_k2_tool_parser.py b/tests/tool_use/test_kimi_k2_tool_parser.py index 43feae4d865e..43b8c70acbfc 100644 --- a/tests/tool_use/test_kimi_k2_tool_parser.py +++ b/tests/tool_use/test_kimi_k2_tool_parser.py @@ -37,11 +37,11 @@ def assert_tool_calls( assert actual_tool_call.type == "function" assert actual_tool_call.function == expected_tool_call.function - # assert tool call id format - assert actual_tool_call.id.startswith("functions.") + # assert tool call id format: should contain function name and numeric index + # Format can be either "functions.func_name:0" or "func_name:0" assert actual_tool_call.id.split(":")[-1].isdigit() assert ( - actual_tool_call.id.split(".")[1].split(":")[0] + actual_tool_call.id.split(":")[0].split(".")[-1] == expected_tool_call.function.name ) diff --git a/vllm/entrypoints/openai/tool_parsers/kimi_k2_tool_parser.py b/vllm/entrypoints/openai/tool_parsers/kimi_k2_tool_parser.py index 98a52ddd60d6..3fff3b371dbe 100644 --- a/vllm/entrypoints/openai/tool_parsers/kimi_k2_tool_parser.py +++ b/vllm/entrypoints/openai/tool_parsers/kimi_k2_tool_parser.py @@ -96,8 +96,8 @@ def extract_tool_calls( tool_calls = [] for match in function_call_tuples: function_id, function_args = match - # function_id: functions.get_weather:0 - function_name = function_id.split(".")[1].split(":")[0] + # function_id: functions.get_weather:0 or get_weather:0 + function_name = function_id.split(":")[0].split(".")[-1] tool_calls.append( ToolCall( id=function_id, @@ -254,7 +254,7 @@ def extract_tool_calls_streaming( ) if current_tool_call_matches: tool_id, tool_args = current_tool_call_matches.groups() - tool_name = tool_id.split(".")[1].split(":")[0] + tool_name = tool_id.split(":")[0].split(".")[-1] current_tool_call["id"] = tool_id current_tool_call["name"] = tool_name current_tool_call["arguments"] = tool_args @@ -264,7 +264,7 @@ def extract_tool_calls_streaming( ) if current_tool_call_name_matches: (tool_id_str,) = current_tool_call_name_matches.groups() - tool_name = tool_id_str.split(".")[1].split(":")[0] + tool_name = tool_id_str.split(":")[0].split(".")[-1] current_tool_call["id"] = tool_id_str current_tool_call["name"] = tool_name current_tool_call["arguments"] = ""