Skip to content

Commit

Permalink
Add Mistral AI tool_call_id to ChatCompletionMessage.
Browse files Browse the repository at this point in the history
  The tool call ID that this message is responding to, applicable for the TOOL role.
  • Loading branch information
tzolov committed May 18, 2024
1 parent 2751899 commit 09e122d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ protected ChatCompletionRequest doCreateToolResponseRequest(ChatCompletionReques
// 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)) {
Expand All @@ -260,8 +261,8 @@ protected ChatCompletionRequest doCreateToolResponseRequest(ChatCompletionReques
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,24 +452,39 @@ public record ResponseFormat(@JsonProperty("type") String type) {
* 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(
// @formatter:off
@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.
* @param content The contents of the message.
* @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);
}

/**
Expand Down

0 comments on commit 09e122d

Please sign in to comment.