Unverified Commit 3affa9dc authored by Binyao Jiang's avatar Binyao Jiang Committed by GitHub
Browse files

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

parent ea0696b9
...@@ -207,6 +207,25 @@ class OpenAIServingChat(OpenAIServingBase): ...@@ -207,6 +207,25 @@ class OpenAIServingChat(OpenAIServingBase):
audio_data, audio_data,
modalities, 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) openai_compatible_messages.append(processed_msg)
# Handle assistant prefix for continue_final_message # Handle assistant prefix for continue_final_message
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment