Skip to content

Commit 6697589

Browse files
xfl12345ilayaperumalg
authored andcommitted
fix(spring-ai-openai): Prevent out-of-range errors when merging tool calls.
Auto-cherry-pick to 1.0.x Fixes spring-projects#4229 Signed-off-by: xfl12345 <[email protected]>
1 parent d1133dc commit 6697589

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)