From f34410715f9758a2ee2d45acd56179f9c1c06fc3 Mon Sep 17 00:00:00 2001 From: Reid <61492567+reidliu41@users.noreply.github.com> Date: Tue, 22 Apr 2025 23:40:24 +0800 Subject: [PATCH] [frontend] enhance tool_calls type check (#16882) Signed-off-by: reidliu41 Co-authored-by: reidliu41 --- vllm/entrypoints/chat_utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vllm/entrypoints/chat_utils.py b/vllm/entrypoints/chat_utils.py index 0b662f1a7e..2e19ebcdd6 100644 --- a/vllm/entrypoints/chat_utils.py +++ b/vllm/entrypoints/chat_utils.py @@ -1095,7 +1095,11 @@ def _parse_chat_message_content( if role == 'assistant': parsed_msg = _AssistantParser(message) - if "tool_calls" in parsed_msg: + # The 'tool_calls' is not None check ensures compatibility. + # It's needed only if downstream code doesn't strictly + # follow the OpenAI spec. + if ("tool_calls" in parsed_msg + and parsed_msg["tool_calls"] is not None): result_msg["tool_calls"] = list(parsed_msg["tool_calls"]) elif role == "tool": parsed_msg = _ToolParser(message)