Fix GLM45 tool call multi-turn bug (#9500)

This commit is contained in:
Binyao Jiang
2025-08-25 13:46:13 -07:00
committed by GitHub
parent ea0696b924
commit 3affa9dcc3

View File

@@ -207,6 +207,25 @@ class OpenAIServingChat(OpenAIServingBase):
audio_data,
modalities,
)
# per the Transformers docs & maintainers, tool call arguments in
# assistant-role messages with tool_calls need to be dicts not JSON str -
# this is how tool-use chat templates will expect them moving forwards
# so, for messages that have tool_calls, parse the string (which we get
# from openAI format) to dict
if (
processed_msg["role"] == "assistant"
and "tool_calls" in processed_msg
and isinstance(processed_msg["tool_calls"], list)
):
for item in processed_msg["tool_calls"]:
if "arguments" in item["function"] and isinstance(
item["function"]["arguments"], str
):
item["function"]["arguments"] = json.loads(
item["function"]["arguments"]
)
openai_compatible_messages.append(processed_msg)
# Handle assistant prefix for continue_final_message