mirror of
https://git.datalinker.icu/vllm-project/vllm.git
synced 2025-12-22 10:15:48 +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
|
# so, for messages that have tool_calls, parse the string (which we get
|
||||||
# from openAI format) to dict
|
# from openAI format) to dict
|
||||||
for message in messages:
|
for message in messages:
|
||||||
if (
|
if message["role"] == "assistant" and "tool_calls" in message:
|
||||||
message["role"] == "assistant"
|
tool_calls = message.get("tool_calls")
|
||||||
and "tool_calls" in message
|
if not isinstance(tool_calls, list):
|
||||||
and isinstance(message["tool_calls"], list)
|
continue
|
||||||
):
|
|
||||||
for item in message["tool_calls"]:
|
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 arguments is None or empty string, set to {}
|
||||||
if content := item["function"].get("arguments"):
|
if content := item["function"].get("arguments"):
|
||||||
if not isinstance(content, (dict, list)):
|
if not isinstance(content, (dict, list)):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user