ChatCompletionsOptions Class
- java.
lang. Object - com.
azure. ai. openai. models. ChatCompletionsOptions
- com.
Implements
public final class ChatCompletionsOptions
implements JsonSerializable<ChatCompletionsOptions>
The configuration information for a chat completions request. Completions support a wide variety of tasks and generate text that continues from or "completes" provided prompt data.
Constructor Summary
Constructor | Description |
---|---|
ChatCompletionsOptions(List<ChatRequestMessage> messages) |
Creates an instance of Chat |
Method Summary
Modifier and Type | Method and Description |
---|---|
static
Chat |
fromJson(JsonReader jsonReader)
Reads an instance of Chat |
Audio |
getAudio()
Get the audio property: Parameters for audio output. |
List<Azure |
getDataSources()
Get the data |
Azure |
getEnhancements()
Get the enhancements property: If provided, the configuration options for available Azure OpenAI chat enhancements. |
Double |
getFrequencyPenalty()
Get the frequency |
Function |
getFunctionCall()
Get the function |
List<Function |
getFunctions()
Get the functions property: A list of functions the model may generate JSON inputs for. |
Map<String,Integer> |
getLogitBias()
Get the logit |
Integer |
getMaxCompletionTokens()
Get the max |
Integer |
getMaxTokens()
Get the max |
List<Chat |
getMessages()
Get the messages property: The collection of context messages associated with this chat completions request. |
Map<String,String> |
getMetadata()
Get the metadata property: Developer-defined tags and values used for filtering completions in the stored completions dashboard. |
List<Chat |
getModalities()
Get the modalities property: Output types that you would like the model to generate for this request. |
String |
getModel()
Get the model property: The model name to provide as part of this completions request. |
Integer |
getN()
Get the n property: The number of chat completions choices that should be generated for a chat completions response. |
Prediction |
getPrediction()
Get the prediction property: Configuration for a Predicted Output, which can greatly improve response times when large parts of the model response are known ahead of time. |
Double |
getPresencePenalty()
Get the presence |
Reasoning |
getReasoningEffort()
Get the reasoning |
Chat |
getResponseFormat()
Get the response |
Long |
getSeed()
Get the seed property: If specified, the system will make a best effort to sample deterministically such that repeated requests with the same seed and parameters should return the same result. |
Service |
getServiceTierOptions()
Get the ServiceTierOptions for this request. |
List<String> |
getStop()
Get the stop property: A collection of textual sequences that will end completions generation. |
Chat |
getStreamOptions()
Get the stream |
Double |
getTemperature()
Get the temperature property: The sampling temperature to use that controls the apparent creativity of generated completions. |
Chat |
getToolChoice()
Get the tool |
List<Chat |
getTools()
Get the tools property: The available tool definitions that the chat completions request can use, including caller-defined functions. |
Integer |
getTopLogprobs()
Get the top |
Double |
getTopP()
Get the topP property: An alternative to sampling with temperature called nucleus sampling. |
String |
getUser()
Get the user property: An identifier for the caller or end user of the operation. |
User |
getUserSecurityContext()
Get the user |
Boolean |
isLogprobs()
Get the logprobs property: Whether to return log probabilities of the output tokens or not. |
Boolean |
isParallelToolCalls()
Get the parallel |
Boolean |
isStore()
Get the store property: Whether or not to store the output of this chat completion request for use in our model distillation or evaluation products. |
Boolean |
isStream()
Get the stream property: A value indicating whether chat completions should be streamed for this request. |
Chat |
setAudio(AudioOutputParameters audio)
Set the audio property: Parameters for audio output. |
Chat |
setDataSources(List<AzureChatExtensionConfiguration> dataSources)
Set the data |
Chat |
setEnhancements(AzureChatEnhancementConfiguration enhancements)
Set the enhancements property: If provided, the configuration options for available Azure OpenAI chat enhancements. |
Chat |
setFrequencyPenalty(Double frequencyPenalty)
Set the frequency |
Chat |
setFunctionCall(FunctionCallConfig functionCallConfig)
Set the function |
Chat |
setFunctions(List<FunctionDefinition> functions)
Set the functions property: A list of functions the model may generate JSON inputs for. |
Chat |
setLogitBias(Map<String,Integer> logitBias)
Set the logit |
Chat |
setLogprobs(Boolean logprobs)
Set the logprobs property: Whether to return log probabilities of the output tokens or not. |
Chat |
setMaxCompletionTokens(Integer maxCompletionTokens)
Set the max |
Chat |
setMaxTokens(Integer maxTokens)
Set the max |
Chat |
setMetadata(Map<String,String> metadata)
Set the metadata property: Developer-defined tags and values used for filtering completions in the stored completions dashboard. |
Chat |
setModalities(List<ChatCompletionModality> modalities)
Set the modalities property: Output types that you would like the model to generate for this request. |
Chat |
setModel(String model)
Set the model property: The model name to provide as part of this completions request. |
Chat |
setN(Integer n)
Set the n property: The number of chat completions choices that should be generated for a chat completions response. |
Chat |
setParallelToolCalls(Boolean parallelToolCalls)
Set the parallel |
Chat |
setPrediction(PredictionContent prediction)
Set the prediction property: Configuration for a Predicted Output, which can greatly improve response times when large parts of the model response are known ahead of time. |
Chat |
setPresencePenalty(Double presencePenalty)
Set the presence |
Chat |
setReasoningEffort(ReasoningEffortValue reasoningEffort)
Set the reasoning |
Chat |
setResponseFormat(ChatCompletionsResponseFormat responseFormat)
Set the response |
Chat |
setSeed(Long seed)
Set the seed property: If specified, the system will make a best effort to sample deterministically such that repeated requests with the same seed and parameters should return the same result. |
Chat |
setServiceTierOptions(ServiceTierOptions serviceTierOptions)
Set the ServiceTierOptions for this request. |
Chat |
setStop(List<String> stop)
Set the stop property: A collection of textual sequences that will end completions generation. |
Chat |
setStore(Boolean store)
Set the store property: Whether or not to store the output of this chat completion request for use in our model distillation or evaluation products. |
Chat |
setTemperature(Double temperature)
Set the temperature property: The sampling temperature to use that controls the apparent creativity of generated completions. |
Chat |
setToolChoice(ChatCompletionsToolSelection toolChoice)
Set the tool |
Chat |
setTools(List<ChatCompletionsToolDefinition> tools)
Set the tools property: The available tool definitions that the chat completions request can use, including caller-defined functions. |
Chat |
setTopLogprobs(Integer topLogprobs)
Set the top |
Chat |
setTopP(Double topP)
Set the topP property: An alternative to sampling with temperature called nucleus sampling. |
Chat |
setUser(String user)
Set the user property: An identifier for the caller or end user of the operation. |
Chat |
setUserSecurityContext(UserSecurityContext userSecurityContext)
Set the user |
Json |
toJson(JsonWriter jsonWriter) |
Methods inherited from java.lang.Object
Constructor Details
ChatCompletionsOptions
public ChatCompletionsOptions(List<ChatRequestMessage> messages)
Creates an instance of ChatCompletionsOptions class.
Parameters:
Method Details
fromJson
public static ChatCompletionsOptions fromJson(JsonReader jsonReader)
Reads an instance of ChatCompletionsOptions from the JsonReader.
Parameters:
Returns:
Throws:
getAudio
public AudioOutputParameters getAudio()
Get the audio property: Parameters for audio output. Required when audio output is requested with `modalities: ["audio"]`.
Returns:
getDataSources
public List<AzureChatExtensionConfiguration> getDataSources()
Get the dataSources property: The configuration entries for Azure OpenAI chat extensions that use them. This additional specification is only compatible with Azure OpenAI.
Returns:
getEnhancements
public AzureChatEnhancementConfiguration getEnhancements()
Get the enhancements property: If provided, the configuration options for available Azure OpenAI chat enhancements.
Returns:
getFrequencyPenalty
public Double getFrequencyPenalty()
Get the frequencyPenalty property: A value that influences the probability of generated tokens appearing based on their cumulative frequency in generated text. Positive values will make tokens less likely to appear as their frequency increases and decrease the likelihood of the model repeating the same statements verbatim.
Returns:
getFunctionCall
public FunctionCallConfig getFunctionCall()
Get the functionCall property: Controls how the model responds to function calls. "none" means the model does not call a function, and responds to the end-user. "auto" means the model can pick between an end-user or calling a function. Specifying a particular function via `{"name": "my_function"}` forces the model to call that function. "none" is the default when no functions are present. "auto" is the default if functions are present.
Returns:
getFunctions
public List<FunctionDefinition> getFunctions()
Get the functions property: A list of functions the model may generate JSON inputs for.
Returns:
getLogitBias
public Map<String,Integer> getLogitBias()
Get the logitBias property: A map between GPT token IDs and bias scores that influences the probability of specific tokens appearing in a completions response. Token IDs are computed via external tokenizer tools, while bias scores reside in the range of -100 to 100 with minimum and maximum values corresponding to a full ban or exclusive selection of a token, respectively. The exact behavior of a given bias score varies by model.
Returns:
getMaxCompletionTokens
public Integer getMaxCompletionTokens()
Get the maxCompletionTokens property: An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens.
Returns:
getMaxTokens
public Integer getMaxTokens()
Get the maxTokens property: The maximum number of tokens allowed for the generated answer. By default, the number of tokens the model can return will be (4096 - prompt tokens). This value is now deprecated in favor of `max_completion_tokens`, and is not compatible with o1 series models.
Returns:
getMessages
public List<ChatRequestMessage> getMessages()
Get the messages property: The collection of context messages associated with this chat completions request. Typical usage begins with a chat message for the System role that provides instructions for the behavior of the assistant, followed by alternating messages between the User and Assistant roles.
Returns:
getMetadata
public Map<String,String> getMetadata()
Get the metadata property: Developer-defined tags and values used for filtering completions in the stored completions dashboard.
Returns:
getModalities
public List<ChatCompletionModality> getModalities()
Get the modalities property: Output types that you would like the model to generate for this request. Most models are capable of generating text, which is the default: `["text"]` The `gpt-4o-audio-preview` model can also be used to generate audio. To request that this model generate both text and audio responses, you can use: `["text", "audio"]`.
Returns:
getModel
public String getModel()
Get the model property: The model name to provide as part of this completions request. Not applicable to Azure OpenAI, where deployment information should be included in the Azure resource URI that's connected to.
Returns:
getN
public Integer getN()
Get the n property: The number of chat completions choices that should be generated for a chat completions response. Because this setting can generate many completions, it may quickly consume your token quota. Use carefully and ensure reasonable settings for max_tokens and stop.
Returns:
getPrediction
public PredictionContent getPrediction()
Get the prediction property: Configuration for a Predicted Output, which can greatly improve response times when large parts of the model response are known ahead of time. This is most common when you are regenerating a file with only minor changes to most of the content.
Returns:
getPresencePenalty
public Double getPresencePenalty()
Get the presencePenalty property: A value that influences the probability of generated tokens appearing based on their existing presence in generated text. Positive values will make tokens less likely to appear when they already exist and increase the model's likelihood to output new topics.
Returns:
getReasoningEffort
public ReasoningEffortValue getReasoningEffort()
Get the reasoningEffort property: This option is only valid for o1 models, Constrains effort on reasoning for reasoning models (see https://platform.openai.com/docs/guides/reasoning). Currently supported values are `low`, `medium`, and `high`. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.
Returns:
getResponseFormat
public ChatCompletionsResponseFormat getResponseFormat()
Get the responseFormat property: An object specifying the format that the model must output. Used to enable JSON mode.
Returns:
getSeed
public Long getSeed()
Get the seed property: If specified, the system will make a best effort to sample deterministically such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor changes in the backend.".
Returns:
getServiceTierOptions
public ServiceTierOptions getServiceTierOptions()
Get the ServiceTierOptions for this request.
Returns:
getStop
public List<String> getStop()
Get the stop property: A collection of textual sequences that will end completions generation.
Returns:
getStreamOptions
public ChatCompletionStreamOptions getStreamOptions()
Get the streamOptions property: Options for streaming response. Only set this when you set `stream: true`.
Returns:
getTemperature
public Double getTemperature()
Get the temperature property: The sampling temperature to use that controls the apparent creativity of generated completions. Higher values will make output more random while lower values will make results more focused and deterministic. It is not recommended to modify temperature and top_p for the same completions request as the interaction of these two settings is difficult to predict.
Returns:
getToolChoice
public ChatCompletionsToolSelection getToolChoice()
Get the toolChoice property: If specified, the model will configure which of the provided tools it can use for the chat completions response.
Returns:
getTools
public List<ChatCompletionsToolDefinition> getTools()
Get the tools property: The available tool definitions that the chat completions request can use, including caller-defined functions.
Returns:
getTopLogprobs
public Integer getTopLogprobs()
Get the topLogprobs property: An integer between 0 and 5 specifying the number of most likely tokens to return at each token position, each with an associated log probability. `logprobs` must be set to `true` if this parameter is used.
Returns:
getTopP
public Double getTopP()
Get the topP property: An alternative to sampling with temperature called nucleus sampling. This value causes the model to consider the results of tokens with the provided probability mass. As an example, a value of 0.15 will cause only the tokens comprising the top 15% of probability mass to be considered. It is not recommended to modify temperature and top_p for the same completions request as the interaction of these two settings is difficult to predict.
Returns:
getUser
public String getUser()
Get the user property: An identifier for the caller or end user of the operation. This may be used for tracking or rate-limiting purposes.
Returns:
getUserSecurityContext
public UserSecurityContext getUserSecurityContext()
Get the userSecurityContext property: The security context identifies and authenticates users and applications in your multi-tenant AI system, helping security teams investigate and mitigate incidents.
Returns:
isLogprobs
public Boolean isLogprobs()
Get the logprobs property: Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the `content` of `message`. This option is currently not available on the `gpt-4-vision-preview` model.
Returns:
isParallelToolCalls
public Boolean isParallelToolCalls()
Get the parallelToolCalls property: Whether to enable parallel function calling during tool use.
Returns:
isStore
public Boolean isStore()
Get the store property: Whether or not to store the output of this chat completion request for use in our model distillation or evaluation products.
Returns:
isStream
public Boolean isStream()
Get the stream property: A value indicating whether chat completions should be streamed for this request.
Returns:
setAudio
public ChatCompletionsOptions setAudio(AudioOutputParameters audio)
Set the audio property: Parameters for audio output. Required when audio output is requested with `modalities: ["audio"]`.
Parameters:
Returns:
setDataSources
public ChatCompletionsOptions setDataSources(List<AzureChatExtensionConfiguration> dataSources)
Set the dataSources property: The configuration entries for Azure OpenAI chat extensions that use them. This additional specification is only compatible with Azure OpenAI.
Parameters:
Returns:
setEnhancements
public ChatCompletionsOptions setEnhancements(AzureChatEnhancementConfiguration enhancements)
Set the enhancements property: If provided, the configuration options for available Azure OpenAI chat enhancements.
Parameters:
Returns:
setFrequencyPenalty
public ChatCompletionsOptions setFrequencyPenalty(Double frequencyPenalty)
Set the frequencyPenalty property: A value that influences the probability of generated tokens appearing based on their cumulative frequency in generated text. Positive values will make tokens less likely to appear as their frequency increases and decrease the likelihood of the model repeating the same statements verbatim.
Parameters:
Returns:
setFunctionCall
public ChatCompletionsOptions setFunctionCall(FunctionCallConfig functionCallConfig)
Set the functionCall property: Controls how the model responds to function calls. "none" means the model does not call a function, and responds to the end-user. "auto" means the model can pick between an end-user or calling a function. Specifying a particular function via `{"name": "my_function"}` forces the model to call that function. "none" is the default when no functions are present. "auto" is the default if functions are present.
Parameters:
Returns:
setFunctions
public ChatCompletionsOptions setFunctions(List<FunctionDefinition> functions)
Set the functions property: A list of functions the model may generate JSON inputs for.
Parameters:
Returns:
setLogitBias
public ChatCompletionsOptions setLogitBias(Map<String,Integer> logitBias)
Set the logitBias property: A map between GPT token IDs and bias scores that influences the probability of specific tokens appearing in a completions response. Token IDs are computed via external tokenizer tools, while bias scores reside in the range of -100 to 100 with minimum and maximum values corresponding to a full ban or exclusive selection of a token, respectively. The exact behavior of a given bias score varies by model.
Parameters:
Returns:
setLogprobs
public ChatCompletionsOptions setLogprobs(Boolean logprobs)
Set the logprobs property: Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the `content` of `message`. This option is currently not available on the `gpt-4-vision-preview` model.
Parameters:
Returns:
setMaxCompletionTokens
public ChatCompletionsOptions setMaxCompletionTokens(Integer maxCompletionTokens)
Set the maxCompletionTokens property: An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens.
Parameters:
Returns:
setMaxTokens
public ChatCompletionsOptions setMaxTokens(Integer maxTokens)
Set the maxTokens property: The maximum number of tokens allowed for the generated answer. By default, the number of tokens the model can return will be (4096 - prompt tokens). This value is now deprecated in favor of `max_completion_tokens`, and is not compatible with o1 series models.
Parameters:
Returns:
setMetadata
public ChatCompletionsOptions setMetadata(Map<String,String> metadata)
Set the metadata property: Developer-defined tags and values used for filtering completions in the stored completions dashboard.
Parameters:
Returns:
setModalities
public ChatCompletionsOptions setModalities(List<ChatCompletionModality> modalities)
Set the modalities property: Output types that you would like the model to generate for this request. Most models are capable of generating text, which is the default: `["text"]` The `gpt-4o-audio-preview` model can also be used to generate audio. To request that this model generate both text and audio responses, you can use: `["text", "audio"]`.
Parameters:
Returns:
setModel
public ChatCompletionsOptions setModel(String model)
Set the model property: The model name to provide as part of this completions request. Not applicable to Azure OpenAI, where deployment information should be included in the Azure resource URI that's connected to.
Parameters:
Returns:
setN
public ChatCompletionsOptions setN(Integer n)
Set the n property: The number of chat completions choices that should be generated for a chat completions response. Because this setting can generate many completions, it may quickly consume your token quota. Use carefully and ensure reasonable settings for max_tokens and stop.
Parameters:
Returns:
setParallelToolCalls
public ChatCompletionsOptions setParallelToolCalls(Boolean parallelToolCalls)
Set the parallelToolCalls property: Whether to enable parallel function calling during tool use.
Parameters:
Returns:
setPrediction
public ChatCompletionsOptions setPrediction(PredictionContent prediction)
Set the prediction property: Configuration for a Predicted Output, which can greatly improve response times when large parts of the model response are known ahead of time. This is most common when you are regenerating a file with only minor changes to most of the content.
Parameters:
Returns:
setPresencePenalty
public ChatCompletionsOptions setPresencePenalty(Double presencePenalty)
Set the presencePenalty property: A value that influences the probability of generated tokens appearing based on their existing presence in generated text. Positive values will make tokens less likely to appear when they already exist and increase the model's likelihood to output new topics.
Parameters:
Returns:
setReasoningEffort
public ChatCompletionsOptions setReasoningEffort(ReasoningEffortValue reasoningEffort)
Set the reasoningEffort property: This option is only valid for o1 models, Constrains effort on reasoning for reasoning models (see https://platform.openai.com/docs/guides/reasoning). Currently supported values are `low`, `medium`, and `high`. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.
Parameters:
Returns:
setResponseFormat
public ChatCompletionsOptions setResponseFormat(ChatCompletionsResponseFormat responseFormat)
Set the responseFormat property: An object specifying the format that the model must output. Used to enable JSON mode.
Parameters:
Returns:
setSeed
public ChatCompletionsOptions setSeed(Long seed)
Set the seed property: If specified, the system will make a best effort to sample deterministically such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor changes in the backend.".
Parameters:
Returns:
setServiceTierOptions
public ChatCompletionsOptions setServiceTierOptions(ServiceTierOptions serviceTierOptions)
Set the ServiceTierOptions for this request.
Parameters:
Returns:
setStop
public ChatCompletionsOptions setStop(List<String> stop)
Set the stop property: A collection of textual sequences that will end completions generation.
Parameters:
Returns:
setStore
public ChatCompletionsOptions setStore(Boolean store)
Set the store property: Whether or not to store the output of this chat completion request for use in our model distillation or evaluation products.
Parameters:
Returns:
setTemperature
public ChatCompletionsOptions setTemperature(Double temperature)
Set the temperature property: The sampling temperature to use that controls the apparent creativity of generated completions. Higher values will make output more random while lower values will make results more focused and deterministic. It is not recommended to modify temperature and top_p for the same completions request as the interaction of these two settings is difficult to predict.
Parameters:
Returns:
setToolChoice
public ChatCompletionsOptions setToolChoice(ChatCompletionsToolSelection toolChoice)
Set the toolChoice property: If specified, the model will configure which of the provided tools it can use for the chat completions response.
Parameters:
Returns:
setTools
public ChatCompletionsOptions setTools(List<ChatCompletionsToolDefinition> tools)
Set the tools property: The available tool definitions that the chat completions request can use, including caller-defined functions.
Parameters:
Returns:
setTopLogprobs
public ChatCompletionsOptions setTopLogprobs(Integer topLogprobs)
Set the topLogprobs property: An integer between 0 and 5 specifying the number of most likely tokens to return at each token position, each with an associated log probability. `logprobs` must be set to `true` if this parameter is used.
Parameters:
Returns:
setTopP
public ChatCompletionsOptions setTopP(Double topP)
Set the topP property: An alternative to sampling with temperature called nucleus sampling. This value causes the model to consider the results of tokens with the provided probability mass. As an example, a value of 0.15 will cause only the tokens comprising the top 15% of probability mass to be considered. It is not recommended to modify temperature and top_p for the same completions request as the interaction of these two settings is difficult to predict.
Parameters:
Returns:
setUser
public ChatCompletionsOptions setUser(String user)
Set the user property: An identifier for the caller or end user of the operation. This may be used for tracking or rate-limiting purposes.
Parameters:
Returns:
setUserSecurityContext
public ChatCompletionsOptions setUserSecurityContext(UserSecurityContext userSecurityContext)
Set the userSecurityContext property: The security context identifies and authenticates users and applications in your multi-tenant AI system, helping security teams investigate and mitigate incidents.
Parameters:
Returns: