Add Mistral AI tool_call_id to ChatCompletionMessage.
The tool call ID that this message is responding to, applicable for the TOOL role.
This commit is contained in:
@@ -250,7 +250,8 @@ public class MistralAiChatClient extends
|
||||
// message.
|
||||
for (ToolCall toolCall : responseMessage.toolCalls()) {
|
||||
|
||||
var functionName = toolCall.function().name();
|
||||
String id = toolCall.id();
|
||||
String functionName = toolCall.function().name();
|
||||
String functionArguments = toolCall.function().arguments();
|
||||
|
||||
if (!this.functionCallbackRegister.containsKey(functionName)) {
|
||||
@@ -260,8 +261,8 @@ public class MistralAiChatClient extends
|
||||
String functionResponse = this.functionCallbackRegister.get(functionName).call(functionArguments);
|
||||
|
||||
// Add the function response to the conversation.
|
||||
conversationHistory
|
||||
.add(new ChatCompletionMessage(functionResponse, ChatCompletionMessage.Role.TOOL, functionName, null));
|
||||
conversationHistory.add(new ChatCompletionMessage(functionResponse, ChatCompletionMessage.Role.TOOL,
|
||||
functionName, null, id));
|
||||
}
|
||||
|
||||
// Recursively call chatCompletionWithTools until the model doesn't call a
|
||||
|
||||
@@ -452,6 +452,8 @@ public class MistralAiApi {
|
||||
* types.
|
||||
* @param toolCalls The tool calls generated by the model, such as function calls.
|
||||
* Applicable only for {@link Role#ASSISTANT} role and null otherwise.
|
||||
* @param toolCallId Tool call that this message is responding to. Only applicable for
|
||||
* the {@link Role#TOOL} role and null otherwise.
|
||||
*/
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
public record ChatCompletionMessage(
|
||||
@@ -459,9 +461,22 @@ public class MistralAiApi {
|
||||
@JsonProperty("content") String content,
|
||||
@JsonProperty("role") Role role,
|
||||
@JsonProperty("name") String name,
|
||||
@JsonProperty("tool_calls") List<ToolCall> toolCalls) {
|
||||
@JsonProperty("tool_calls") List<ToolCall> toolCalls,
|
||||
@JsonProperty("tool_call_id") String toolCallId) {
|
||||
// @formatter:on
|
||||
|
||||
/**
|
||||
* Message comprising the conversation.
|
||||
* @param content The contents of the message.
|
||||
* @param role The role of the messages author. Could be one of the {@link Role}
|
||||
* types.
|
||||
* @param toolCalls The tool calls generated by the model, such as function calls.
|
||||
* Applicable only for {@link Role#ASSISTANT} role and null otherwise.
|
||||
*/
|
||||
public ChatCompletionMessage(String content, Role role, String name, List<ToolCall> toolCalls) {
|
||||
this(content, role, name, toolCalls, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a chat completion message with the given content and role. All other
|
||||
* fields are null.
|
||||
@@ -469,7 +484,7 @@ public class MistralAiApi {
|
||||
* @param role The role of the author of this message.
|
||||
*/
|
||||
public ChatCompletionMessage(String content, Role role) {
|
||||
this(content, role, null, null);
|
||||
this(content, role, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user