Skip to content

Commit dd331a3

Browse files
authored
fix(spring-ai-openai): Prevent out-of-range errors when merging tool calls.
Signed-off-by: xfl12345 <[email protected]>
1 parent 36a97d3 commit dd331a3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ 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().size() > 0) {
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));
@@ -138,6 +138,7 @@ private ChatCompletionMessage merge(ChatCompletionMessage previous, ChatCompleti
138138
toolCalls.add(lastPreviousTooCall);
139139
}
140140
}
141+
141142
return new ChatCompletionMessage(content, role, name, toolCallId, toolCalls, refusal, audioOutput, annotations);
142143
}
143144

0 commit comments

Comments
 (0)