Mistral AI streaming function API change fix

This commit is contained in:
Christian Tzolov
2024-04-26 21:04:48 +02:00
parent 773b7bd3ca
commit 7e03a15cf5
3 changed files with 12 additions and 9 deletions

View File

@@ -285,7 +285,13 @@ public class MistralAiChatClient extends
@SuppressWarnings("null")
@Override
protected ChatCompletionMessage doGetToolResponseMessage(ResponseEntity<ChatCompletion> chatCompletion) {
return chatCompletion.getBody().choices().iterator().next().message();
ChatCompletionMessage msg = chatCompletion.getBody().choices().iterator().next().message();
if (msg.role() == null) {
// add missing role
msg = new ChatCompletionMessage(msg.content(), ChatCompletionMessage.Role.ASSISTANT, msg.name(),
msg.toolCalls());
}
return msg;
}
@Override

View File

@@ -535,14 +535,12 @@ public class MistralAiApi {
*/
@JsonProperty("model_length") MODEL_LENGTH,
/**
* The model called a tool.
*
*/
@JsonProperty("tool_call") TOOL_CALL,
// anticipation of future changes. Based on:
// https://github.com/mistralai/client-python/blob/main/src/mistralai/models/chat_completion.py
@JsonProperty("error") ERROR,
/**
* The model requested a tool call.
*/
@JsonProperty("tool_calls") TOOL_CALLS
// @formatter:on

View File

@@ -190,8 +190,7 @@ public class MistralAiStreamFunctionCallingHelper {
}
var choice = choices.get(0);
return choice.finishReason() == ChatCompletionFinishReason.TOOL_CALL
|| choice.finishReason() == ChatCompletionFinishReason.TOOL_CALLS;
return choice.finishReason() == ChatCompletionFinishReason.TOOL_CALLS;
}
}