mirror of
https://git.datalinker.icu/vllm-project/vllm.git
synced 2025-12-22 06:15:02 +08:00
[Bugfix] Drop empty tool_calls lists to keep assistant replies in chat template (#30648)
Signed-off-by: Seokhyun An <iamseokhyun@gmail.com>
This commit is contained in:
parent
a524d1ba0a
commit
b337647aa0
@ -1629,12 +1629,17 @@ def _postprocess_messages(messages: list[ConversationMessage]) -> None:
|
||||
# so, for messages that have tool_calls, parse the string (which we get
|
||||
# from openAI format) to dict
|
||||
for message in messages:
|
||||
if (
|
||||
message["role"] == "assistant"
|
||||
and "tool_calls" in message
|
||||
and isinstance(message["tool_calls"], list)
|
||||
):
|
||||
for item in message["tool_calls"]:
|
||||
if message["role"] == "assistant" and "tool_calls" in message:
|
||||
tool_calls = message.get("tool_calls")
|
||||
if not isinstance(tool_calls, list):
|
||||
continue
|
||||
|
||||
if len(tool_calls) == 0:
|
||||
# Drop empty tool_calls to keep templates on the normal assistant path.
|
||||
message.pop("tool_calls", None)
|
||||
continue
|
||||
|
||||
for item in tool_calls:
|
||||
# if arguments is None or empty string, set to {}
|
||||
if content := item["function"].get("arguments"):
|
||||
if not isinstance(content, (dict, list)):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user