From dd9e57409292f94bad93d837dc1cf5079d4415f6 Mon Sep 17 00:00:00 2001 From: ogirardot Date: Thu, 13 Feb 2025 21:37:47 +0100 Subject: [PATCH] fix(spring-ai-azure-openai): last chat completions can have null deltas Signed-off-by: ogirardot --- .../ai/azure/openai/AzureOpenAiChatModel.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/AzureOpenAiChatModel.java b/models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/AzureOpenAiChatModel.java index 060c8f305..7222d6b9f 100644 --- a/models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/AzureOpenAiChatModel.java +++ b/models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/AzureOpenAiChatModel.java @@ -353,7 +353,11 @@ public class AzureOpenAiChatModel extends AbstractToolCallSupport implements Cha || chatCompletions.getUsage() != null) .map(chatCompletions -> { if (!chatCompletions.getChoices().isEmpty()) { - final var toolCalls = chatCompletions.getChoices().get(0).getDelta().getToolCalls(); + ChatChoice chatChoice = chatCompletions.getChoices().get(0); + List toolCalls = null; + if (chatChoice.getDelta() != null) { + toolCalls = chatChoice.getDelta().getToolCalls(); + } isFunctionCall.set(toolCalls != null && !toolCalls.isEmpty()); } return chatCompletions;