2727import org .springframework .ai .deepseek .api .DeepSeekApi .ChatCompletionMessage .Role ;
2828import org .springframework .ai .deepseek .api .DeepSeekApi .ChatCompletionMessage .ToolCall ;
2929import org .springframework .util .CollectionUtils ;
30+ import org .springframework .util .StringUtils ;
3031
3132/**
3233 * Helper class to support Streaming function calling. It can merge the streamed
@@ -95,7 +96,7 @@ private ChatCompletionMessage merge(ChatCompletionMessage previous, ChatCompleti
9596 throw new IllegalStateException ("Currently only one tool call is supported per message!" );
9697 }
9798 var currentToolCall = current .toolCalls ().iterator ().next ();
98- if (currentToolCall .id () != null ) {
99+ if (StringUtils . hasText ( currentToolCall .id ()) ) {
99100 if (lastPreviousTooCall != null ) {
100101 toolCalls .add (lastPreviousTooCall );
101102 }
@@ -117,7 +118,7 @@ private ToolCall merge(ToolCall previous, ToolCall current) {
117118 if (previous == null ) {
118119 return current ;
119120 }
120- String id = (current .id () != null ? current .id () : previous .id ());
121+ String id = (StringUtils . hasText ( current .id ()) ? current .id () : previous .id ());
121122 String type = (current .type () != null ? current .type () : previous .type ());
122123 ChatCompletionFunction function = merge (previous .function (), current .function ());
123124 return new ToolCall (id , type , function );
@@ -127,7 +128,7 @@ private ChatCompletionFunction merge(ChatCompletionFunction previous, ChatComple
127128 if (previous == null ) {
128129 return current ;
129130 }
130- String name = (current .name () != null ? current .name () : previous .name ());
131+ String name = (StringUtils . hasText ( current .name ()) ? current .name () : previous .name ());
131132 StringBuilder arguments = new StringBuilder ();
132133 if (previous .arguments () != null ) {
133134 arguments .append (previous .arguments ());
0 commit comments