From ea79a4fbbac64a59fb09350e071192f25c22269c Mon Sep 17 00:00:00 2001 From: GuangxiaoLong <33345078+lgxisbb@users.noreply.github.com> Date: Mon, 18 Mar 2024 17:48:56 +0800 Subject: [PATCH] Update OpenAiStreamFunctionCallingHelper.java preventing the occurrence of null pointers. --- .../ai/openai/api/OpenAiStreamFunctionCallingHelper.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 +// ---