Skip to content

Commit 919ac27

Browse files
authored
fix: correctly handle merges when 'current' is null (#4153)
Fixes #4153 Auto-cherry-pick to 1.0.x Signed-off-by: Gareth Evans <[email protected]>
1 parent e5e2f45 commit 919ac27

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public ChatCompletionChunk merge(ChatCompletionChunk previous, ChatCompletionChu
5757
return current;
5858
}
5959

60+
if (current == null) {
61+
return previous;
62+
}
63+
6064
String id = (current.id() != null ? current.id() : previous.id());
6165
Long created = (current.created() != null ? current.created() : previous.created());
6266
String model = (current.model() != null ? current.model() : previous.model());
@@ -79,6 +83,10 @@ private ChunkChoice merge(ChunkChoice previous, ChunkChoice current) {
7983
return current;
8084
}
8185

86+
if (current == null) {
87+
return previous;
88+
}
89+
8290
ChatCompletionFinishReason finishReason = (current.finishReason() != null ? current.finishReason()
8391
: previous.finishReason());
8492
Integer index = (current.index() != null ? current.index() : previous.index());

0 commit comments

Comments
 (0)