diff --git a/spring-ai-alibaba-core/src/main/java/com/alibaba/cloud/ai/dashscope/api/DashScopeAiStreamFunctionCallingHelper.java b/spring-ai-alibaba-core/src/main/java/com/alibaba/cloud/ai/dashscope/api/DashScopeAiStreamFunctionCallingHelper.java index 831250f3bb32bb5563fd896cab31605dc7778871..d640a300e9bd811da4d89c3f7ddadc5836a8b72b 100644 --- a/spring-ai-alibaba-core/src/main/java/com/alibaba/cloud/ai/dashscope/api/DashScopeAiStreamFunctionCallingHelper.java +++ b/spring-ai-alibaba-core/src/main/java/com/alibaba/cloud/ai/dashscope/api/DashScopeAiStreamFunctionCallingHelper.java @@ -109,7 +109,7 @@ public class DashScopeAiStreamFunctionCallingHelper { toolCalls.addAll(previous.toolCalls().subList(0, previous.toolCalls().size() - 1)); } } - if (current.toolCalls() != null) { + if (current.toolCalls() != null && !current.toolCalls().isEmpty()) { if (current.toolCalls().size() > 1) { throw new IllegalStateException("Currently only one tool call is supported per message!"); } @@ -163,7 +163,7 @@ public class DashScopeAiStreamFunctionCallingHelper { */ public boolean isStreamingToolFunctionCall(ChatCompletionChunk chatCompletion) { - if (chatCompletion == null || CollectionUtils.isEmpty(chatCompletion.output().choices())) { + if (chatCompletion == null || chatCompletion.output()==null || CollectionUtils.isEmpty(chatCompletion.output().choices())) { return false; } @@ -181,7 +181,7 @@ public class DashScopeAiStreamFunctionCallingHelper { */ public boolean isStreamingToolFunctionCallFinish(ChatCompletionChunk chatCompletion) { - if (chatCompletion == null || CollectionUtils.isEmpty(chatCompletion.output().choices())) { + if (chatCompletion == null || chatCompletion.output()==null || CollectionUtils.isEmpty(chatCompletion.output().choices())) { return false; }