Skip to content

Commit e94e6e2

Browse files
committed
1
1 parent 58ee212 commit e94e6e2

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

models/spring-ai-minimax/src/main/java/org/springframework/ai/minimax/MiniMaxChatModel.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,8 @@ public Flux<ChatResponse> stream(Prompt prompt) {
360360
* @return true if the generation is a tool call
361361
*/
362362
@Override
363-
protected boolean isToolCall(Generation generation, Set<String> toolCallFinishReasons) {
364-
if (!super.isToolCall(generation, toolCallFinishReasons)) {
363+
protected boolean isToolCall(Generation generation, Set<String> toolCallFinishReasons, ChatResponse chatResponse) {
364+
if (!super.isToolCall(generation, toolCallFinishReasons, chatResponse)) {
365365
return false;
366366
}
367367
return generation.getOutput()

spring-ai-core/src/main/java/org/springframework/ai/chat/model/AbstractToolCallSupport.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.springframework.ai.chat.messages.Message;
2929
import org.springframework.ai.chat.messages.ToolResponseMessage;
3030
import org.springframework.ai.chat.metadata.ChatGenerationMetadata;
31+
import org.springframework.ai.chat.metadata.Usage;
3132
import org.springframework.ai.chat.prompt.Prompt;
3233
import org.springframework.ai.model.function.FunctionCallback;
3334
import org.springframework.ai.model.function.FunctionCallbackContext;
@@ -228,24 +229,25 @@ protected boolean isToolCall(ChatResponse chatResponse, Set<String> toolCallFini
228229
return false;
229230
}
230231

231-
return generations.stream().anyMatch(g -> isToolCall(g, toolCallFinishReasons));
232+
return generations.stream().anyMatch(g -> isToolCall(g, toolCallFinishReasons, chatResponse));
232233
}
233234

234235
/**
235236
* Check if the generation is a tool call. The tool call finish reasons are used to
236237
* determine if the generation is a tool call.
237238
* @param generation the generation to check.
238239
* @param toolCallFinishReasons the tool call finish reasons to check.
240+
* @param chatResponse the chat response to check.
239241
* @return true if the generation is a tool call, false otherwise.
240242
*/
241-
protected boolean isToolCall(Generation generation, Set<String> toolCallFinishReasons) {
243+
protected boolean isToolCall(Generation generation, Set<String> toolCallFinishReasons, ChatResponse chatResponse) {
242244
var finishReason = (generation.getMetadata().getFinishReason() != null)
243245
? generation.getMetadata().getFinishReason() : "";
244-
ChatGenerationMetadata metadata = generation.getMetadata();
246+
Usage usage = chatResponse.getMetadata().getUsage();
245247
return generation.getOutput().hasToolCalls() && (toolCallFinishReasons.stream()
246248
.map(s -> s.toLowerCase())
247249
.toList()
248-
.contains(finishReason.toLowerCase()) || metadata != null);
250+
.contains(finishReason.toLowerCase()) || usage != null);
249251
}
250252

251253
/**

0 commit comments

Comments
 (0)