3131import org .springframework .ai .openai .api .OpenAiApi .LogProbs ;
3232import org .springframework .ai .openai .api .OpenAiApi .Usage ;
3333import org .springframework .util .CollectionUtils ;
34+ import org .springframework .util .StringUtils ;
3435
3536/**
3637 * Helper class to support Streaming function calling.
@@ -111,7 +112,7 @@ private ChatCompletionMessage merge(ChatCompletionMessage previous, ChatCompleti
111112 throw new IllegalStateException ("Currently only one tool call is supported per message!" );
112113 }
113114 var currentToolCall = current .toolCalls ().iterator ().next ();
114- if (currentToolCall .id () != null ) {
115+ if (StringUtils . hasText ( currentToolCall .id ()) ) {
115116 if (lastPreviousTooCall != null ) {
116117 toolCalls .add (lastPreviousTooCall );
117118 }
@@ -133,7 +134,7 @@ private ToolCall merge(ToolCall previous, ToolCall current) {
133134 if (previous == null ) {
134135 return current ;
135136 }
136- String id = (current .id () != null ? current .id () : previous .id ());
137+ String id = (StringUtils . hasText ( current .id ()) ? current .id () : previous .id ());
137138 String type = (current .type () != null ? current .type () : previous .type ());
138139 ChatCompletionFunction function = merge (previous .function (), current .function ());
139140 return new ToolCall (id , type , function );
@@ -143,7 +144,7 @@ private ChatCompletionFunction merge(ChatCompletionFunction previous, ChatComple
143144 if (previous == null ) {
144145 return current ;
145146 }
146- String name = (current .name () != null ? current .name () : previous .name ());
147+ String name = (StringUtils . hasText ( current .name ()) ? current .name () : previous .name ());
147148 StringBuilder arguments = new StringBuilder ();
148149 if (previous .arguments () != null ) {
149150 arguments .append (previous .arguments ());
0 commit comments