Skip to content

Conversation

@thisishwan2
Copy link
Contributor

Fixes #5116

Description

This PR fixes a compatibility issue with strict OpenAI-compatible models (e.g., Qwen) where tool_calls requests failed due to a missing function.arguments field.
Previously, when arguments was null, the field was omitted during serialization due to the @JsonInclude(Include.NON_NULL) annotation. While the official OpenAI API is lenient, strict providers reject this as invalid protocol usage, returning 400 Bad Request.

Changes

Updated the ChatCompletionFunction record in OpenAiApi by adding a compact constructor. This ensures that arguments defaults to "{}" (empty JSON object string) when null, guaranteeing the field is always present in the serialized JSON.

Verification

  • I have verified that the code compiles successfully.
  • Added a new unit test nullArgumentsDefaultsToEmpty in OpenAiApiT.java to verify that null arguments are correctly converted to "{}" and that the serialized JSON explicitly contains "arguments": "{}".

Signed-off-by: Pilhwan Choi <[email protected]>
Signed-off-by: Pilhwan Choi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Streaming tool_calls with Qwen models cause function.arguments Field required in Spring AI 2.0.0

3 participants