Skip to content

Commit a12f0ca

Browse files
xfl12345spring-builds
authored andcommitted
fix(spring-ai-openai): Prevent out-of-range errors when merging tool calls.
Fixes #4229 Signed-off-by: xfl12345 <17960863+xfl12345@users.noreply.github.com> (cherry picked from commit 6697589)
1 parent 8e16f9d commit a12f0ca

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

models/spring-ai-openai/src/main/java/org/springframework/ai/openai/api/OpenAiStreamFunctionCallingHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ private ChatCompletionMessage merge(ChatCompletionMessage previous, ChatCompleti
112112

113113
List<ToolCall> toolCalls = new ArrayList<>();
114114
ToolCall lastPreviousTooCall = null;
115-
if (previous.toolCalls() != null) {
115+
if (previous.toolCalls() != null && !previous.toolCalls().isEmpty()) {
116116
lastPreviousTooCall = previous.toolCalls().get(previous.toolCalls().size() - 1);
117117
if (previous.toolCalls().size() > 1) {
118118
toolCalls.addAll(previous.toolCalls().subList(0, previous.toolCalls().size() - 1));
119119
}
120120
}
121-
if (current.toolCalls() != null && current.toolCalls().size() > 0) {
121+
if (current.toolCalls() != null && !current.toolCalls().isEmpty()) {
122122
if (current.toolCalls().size() > 1) {
123123
throw new IllegalStateException("Currently only one tool call is supported per message!");
124124
}

0 commit comments

Comments
 (0)