diff --git a/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/api/OpenAiStreamFunctionCallingHelper.java b/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/api/OpenAiStreamFunctionCallingHelper.java index 5c4132077..6110cc7cf 100644 --- a/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/api/OpenAiStreamFunctionCallingHelper.java +++ b/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/api/OpenAiStreamFunctionCallingHelper.java @@ -63,8 +63,8 @@ public class OpenAiStreamFunctionCallingHelper { ChunkChoice currentChoice0 = (CollectionUtils.isEmpty(current.choices()) ? null : current.choices().get(0)); ChunkChoice choice = merge(previousChoice0, currentChoice0); - - return new ChatCompletionChunk(id, List.of(choice), created, model, systemFingerprint, object); + List chunkChoices = choice == null ? List.of() : List.of(choice); + return new ChatCompletionChunk(id, chunkChoices, created, model, systemFingerprint, object); } private ChunkChoice merge(ChunkChoice previous, ChunkChoice current) { @@ -198,4 +198,4 @@ public class OpenAiStreamFunctionCallingHelper { } } -// --- \ No newline at end of file +// ---