31
31
import org .springframework .ai .openai .api .OpenAiApi .LogProbs ;
32
32
import org .springframework .ai .openai .api .OpenAiApi .Usage ;
33
33
import org .springframework .util .CollectionUtils ;
34
+ import org .springframework .util .StringUtils ;
34
35
35
36
/**
36
37
* Helper class to support Streaming function calling.
@@ -111,7 +112,7 @@ private ChatCompletionMessage merge(ChatCompletionMessage previous, ChatCompleti
111
112
throw new IllegalStateException ("Currently only one tool call is supported per message!" );
112
113
}
113
114
var currentToolCall = current .toolCalls ().iterator ().next ();
114
- if (currentToolCall .id () != null ) {
115
+ if (StringUtils . hasText ( currentToolCall .id ()) ) {
115
116
if (lastPreviousTooCall != null ) {
116
117
toolCalls .add (lastPreviousTooCall );
117
118
}
@@ -133,7 +134,7 @@ private ToolCall merge(ToolCall previous, ToolCall current) {
133
134
if (previous == null ) {
134
135
return current ;
135
136
}
136
- String id = (current .id () != null ? current .id () : previous .id ());
137
+ String id = (StringUtils . hasText ( current .id ()) ? current .id () : previous .id ());
137
138
String type = (current .type () != null ? current .type () : previous .type ());
138
139
ChatCompletionFunction function = merge (previous .function (), current .function ());
139
140
return new ToolCall (id , type , function );
@@ -143,7 +144,7 @@ private ChatCompletionFunction merge(ChatCompletionFunction previous, ChatComple
143
144
if (previous == null ) {
144
145
return current ;
145
146
}
146
- String name = (current .name () != null ? current .name () : previous .name ());
147
+ String name = (StringUtils . hasText ( current .name ()) ? current .name () : previous .name ());
147
148
StringBuilder arguments = new StringBuilder ();
148
149
if (previous .arguments () != null ) {
149
150
arguments .append (previous .arguments ());
0 commit comments