Class ChatCompletionRequest.ChatCompletionRequestBuilder
java.lang.Object
nl.dannyj.mistral.models.completion.ChatCompletionRequest.ChatCompletionRequestBuilder
- Enclosing class:
- ChatCompletionRequest
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
frequencyPenalty
(Double frequencyPenalty) Number between -2.0 and 2.0.The maximum number of tokens to generate in the completion.messages
(List<ChatMessage> messages) The prompt(s) to generate completions for, encoded as a list of dict with role and content.ID of the model to use.How many chat completion choices to generate for each input message.parallelToolCalls
(Boolean parallelToolCalls) Whether to allow parallel function calls.prediction
(Prediction prediction) Provides predicted output to optimize response time.presencePenalty
(Double presencePenalty) Number between -2.0 and 2.0.randomSeed
(Long randomSeed) The seed to use for random sampling.responseFormat
(ResponseFormat responseFormat) An object specifying the format that the model must output.safePrompt
(boolean safePrompt) Whether to inject a safety prompt before all conversations.Stop generation if this token is detected.Whether to stream back partial progress.temperature
(Double temperature) What sampling temperature to use, Mistral recommends this to be between 0.0 and 0.7.toolChoice
(ToolChoiceOption toolChoice) Controls which function call(s) are made, if any.A list of tools the model may call.Nucleus sampling, where the model considers the results of the tokens with top_p probability mass.toString()
-
Method Details
-
model
ID of the model to use. You can use the List Available Models API (MistralClient.listModels()
) to see all of your available models.- Parameters:
model
- The model's ID. Can't be null or empty.- Returns:
this
.
-
temperature
What sampling temperature to use, Mistral recommends this to be between 0.0 and 0.7. Higher values like 0.7 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. Mistral generally recommends altering this or top_p but not both. The default value varies depending on the model you are targeting.- Parameters:
temperature
- The sampling temperature to use. Has to be between 0.0 and 1.5. Null will default to the model's default value.- Returns:
this
.
-
topP
Nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both. Defaults to 1.0 (i.e., no nucleus sampling).- Parameters:
topP
- the top p value to use. Has to be between 0.0 and 1.0.- Returns:
this
.
-
maxTokens
The maximum number of tokens to generate in the completion. The token count of your prompt plus max_tokens cannot exceed the model's context length.- Parameters:
maxTokens
- The maximum number of tokens to generate in the completion. Has to be positive or zero. Null for the model's default value.- Returns:
this
.
-
stream
Whether to stream back partial progress. When set to true, theMistralClient.createChatCompletionStream(ChatCompletionRequest, ChatCompletionChunkCallback)
method has to be used.- Parameters:
stream
- Whether to stream back partial progress. Setting to null will default to false.- Returns:
this
.
-
stop
Stop generation if this token is detected. Or if one of these tokens is detected when providing an array- Parameters:
stop
- The stop sequence(s) to use. Use an empty List (default value) for no stop sequence.- Returns:
this
.
-
randomSeed
The seed to use for random sampling. If set, different calls will generate deterministic results.- Parameters:
randomSeed
- The seed to use for random sampling. Set to null for a random seed.- Returns:
this
.
-
messages
The prompt(s) to generate completions for, encoded as a list of dict with role and content. Must contain at least one message and the first prompt role should be user or system.- Parameters:
messages
- The list of messages representing the conversation history. Must contain at least one message.- Returns:
this
.
-
responseFormat
public ChatCompletionRequest.ChatCompletionRequestBuilder responseFormat(ResponseFormat responseFormat) An object specifying the format that the model must output. Setting to JSON_OBJECT enables JSON mode, which guarantees the message the model generates is in JSON. When using JSON mode you MUST also instruct the model to produce JSON yourself with a system or a user message.- Parameters:
responseFormat
- The response format of the completion request. Currently only available when using mistral small and mistral large models. For other models, this MUST be set to null.- Returns:
this
.
-
safePrompt
Whether to inject a safety prompt before all conversations. Toggling the safe prompt will prepend your messages with the following system prompt: Always assist with care, respect, and truth. Respond with utmost utility yet securely. Avoid harmful, unethical, prejudiced, or negative content. Ensure replies promote fairness and positivity.- Parameters:
safePrompt
- Whether to inject a safety prompt before all conversations.- Returns:
this
.
-
tools
A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for. Set to null or an empty list if no tools should be available.- Parameters:
tools
- The list of tools.- Returns:
this
.
-
toolChoice
Controls which function call(s) are made, if any. 'none' means the model will not call a function and instead generates a message. 'auto' means the model can pick between generating a message or calling a function. 'any' forces the model to call a function. Specifying a particular function viaSpecificToolChoice
forces the model to call that function. Defaults to 'auto'.- Parameters:
toolChoice
- The tool choice option (can beToolChoiceEnum
orSpecificToolChoice
).- Returns:
this
.
-
presencePenalty
public ChatCompletionRequest.ChatCompletionRequestBuilder presencePenalty(@Nullable Double presencePenalty) Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics. Defaults to 0.0.- Parameters:
presencePenalty
- The presence penalty.- Returns:
this
.
-
frequencyPenalty
public ChatCompletionRequest.ChatCompletionRequestBuilder frequencyPenalty(@Nullable Double frequencyPenalty) Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim. Defaults to 0.0.- Parameters:
frequencyPenalty
- The frequency penalty.- Returns:
this
.
-
n
How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Defaults to 1.- Parameters:
n
- The number of choices to generate.- Returns:
this
.
-
prediction
public ChatCompletionRequest.ChatCompletionRequestBuilder prediction(@Nullable Prediction prediction) Provides predicted output to optimize response time. See the Predicted Outputs guide for more details. API might have its own default object if null.- Parameters:
prediction
- The prediction object.- Returns:
this
.
-
parallelToolCalls
public ChatCompletionRequest.ChatCompletionRequestBuilder parallelToolCalls(Boolean parallelToolCalls) Whether to allow parallel function calls. Defaults to true.- Parameters:
parallelToolCalls
- Whether parallel tool calls are allowed.- Returns:
this
.
-
build
-
toString
-