27
27
import org .springframework .ai .deepseek .api .DeepSeekApi .ChatCompletionMessage .Role ;
28
28
import org .springframework .ai .deepseek .api .DeepSeekApi .ChatCompletionMessage .ToolCall ;
29
29
import org .springframework .util .CollectionUtils ;
30
+ import org .springframework .util .StringUtils ;
30
31
31
32
/**
32
33
* Helper class to support Streaming function calling. It can merge the streamed
@@ -95,7 +96,7 @@ private ChatCompletionMessage merge(ChatCompletionMessage previous, ChatCompleti
95
96
throw new IllegalStateException ("Currently only one tool call is supported per message!" );
96
97
}
97
98
var currentToolCall = current .toolCalls ().iterator ().next ();
98
- if (currentToolCall .id () != null ) {
99
+ if (StringUtils . hasText ( currentToolCall .id ()) ) {
99
100
if (lastPreviousTooCall != null ) {
100
101
toolCalls .add (lastPreviousTooCall );
101
102
}
@@ -117,7 +118,7 @@ private ToolCall merge(ToolCall previous, ToolCall current) {
117
118
if (previous == null ) {
118
119
return current ;
119
120
}
120
- String id = (current .id () != null ? current .id () : previous .id ());
121
+ String id = (StringUtils . hasText ( current .id ()) ? current .id () : previous .id ());
121
122
String type = (current .type () != null ? current .type () : previous .type ());
122
123
ChatCompletionFunction function = merge (previous .function (), current .function ());
123
124
return new ToolCall (id , type , function );
@@ -127,7 +128,7 @@ private ChatCompletionFunction merge(ChatCompletionFunction previous, ChatComple
127
128
if (previous == null ) {
128
129
return current ;
129
130
}
130
- String name = (current .name () != null ? current .name () : previous .name ());
131
+ String name = (StringUtils . hasText ( current .name ()) ? current .name () : previous .name ());
131
132
StringBuilder arguments = new StringBuilder ();
132
133
if (previous .arguments () != null ) {
133
134
arguments .append (previous .arguments ());
0 commit comments