Support single object tool_calls in OpenAI vendor APIs
XFY Spark and possibly other vendors implement the OpenAI interface but return tool_calls as a single object rather than an array. Add @JsonFormat annotation to handle both array and single object responses in ChatCompletionMessage, making Spring AI more broadly compatible with OpenAI API implementations. Only ChatCompletionMessage.java required modification to support this alternate format while maintaining backward compatibility with the standard OpenAI API response structure. Co-authored-by: jito <pigberger70@gmail.com>
This commit is contained in:
@@ -22,6 +22,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
@@ -905,7 +906,8 @@ public class OpenAiApi {
|
||||
@JsonProperty("role") Role role,
|
||||
@JsonProperty("name") String name,
|
||||
@JsonProperty("tool_call_id") String toolCallId,
|
||||
@JsonProperty("tool_calls") List<ToolCall> toolCalls,
|
||||
@JsonProperty("tool_calls")
|
||||
@JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY) List<ToolCall> toolCalls,
|
||||
@JsonProperty("refusal") String refusal) { // @formatter:on
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user