diff --git a/models/spring-ai-deepseek/src/main/java/org/springframework/ai/deepseek/api/DeepSeekStreamFunctionCallingHelper.java b/models/spring-ai-deepseek/src/main/java/org/springframework/ai/deepseek/api/DeepSeekStreamFunctionCallingHelper.java index 68cbe2a4b93..063808c2a1d 100644 --- a/models/spring-ai-deepseek/src/main/java/org/springframework/ai/deepseek/api/DeepSeekStreamFunctionCallingHelper.java +++ b/models/spring-ai-deepseek/src/main/java/org/springframework/ai/deepseek/api/DeepSeekStreamFunctionCallingHelper.java @@ -27,6 +27,7 @@ import org.springframework.ai.deepseek.api.DeepSeekApi.ChatCompletionMessage.Role; import org.springframework.ai.deepseek.api.DeepSeekApi.ChatCompletionMessage.ToolCall; import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; /** * Helper class to support Streaming function calling. It can merge the streamed @@ -95,7 +96,7 @@ private ChatCompletionMessage merge(ChatCompletionMessage previous, ChatCompleti throw new IllegalStateException("Currently only one tool call is supported per message!"); } var currentToolCall = current.toolCalls().iterator().next(); - if (currentToolCall.id() != null) { + if (StringUtils.hasText(currentToolCall.id())) { if (lastPreviousTooCall != null) { toolCalls.add(lastPreviousTooCall); } @@ -117,7 +118,7 @@ private ToolCall merge(ToolCall previous, ToolCall current) { if (previous == null) { return current; } - String id = (current.id() != null ? current.id() : previous.id()); + String id = (StringUtils.hasText(current.id()) ? current.id() : previous.id()); String type = (current.type() != null ? current.type() : previous.type()); ChatCompletionFunction function = merge(previous.function(), current.function()); return new ToolCall(id, type, function); @@ -127,7 +128,7 @@ private ChatCompletionFunction merge(ChatCompletionFunction previous, ChatComple if (previous == null) { return current; } - String name = (current.name() != null ? current.name() : previous.name()); + String name = (StringUtils.hasText(current.name()) ? current.name() : previous.name()); StringBuilder arguments = new StringBuilder(); if (previous.arguments() != null) { arguments.append(previous.arguments());