Package org.springframework.ai.openai
Class OpenAiChatOptions
java.lang.Object
org.springframework.ai.openai.OpenAiChatOptions
- All Implemented Interfaces:
ChatOptions,ModelOptions,StructuredOutputChatOptions,ToolCallingChatOptions
public class OpenAiChatOptions
extends Object
implements ToolCallingChatOptions, StructuredOutputChatOptions
Configuration information for the Chat Model implementation using the OpenAI Java SDK.
- Author:
- Julien Dubois, Christian Tzolov, Thomas Vitale, Mariusz Bernacki, lambochen, Ilayaperumal Gopinathan, Sebastien Deleuze, guan xu
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classstatic final recordstatic classstatic final record -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedOpenAiChatOptions(@Nullable String baseUrl, @Nullable String apiKey, @Nullable com.openai.credential.Credential credential, @Nullable String model, @Nullable String microsoftDeploymentName, @Nullable com.openai.azure.AzureOpenAIServiceVersion microsoftFoundryServiceVersion, @Nullable String organizationId, @Nullable Boolean isMicrosoftFoundry, @Nullable Boolean isGitHubModels, @Nullable Duration timeout, @Nullable Integer maxRetries, @Nullable Proxy proxy, @Nullable Map<String, String> customHeaders, @Nullable Double frequencyPenalty, @Nullable Integer maxTokens, @Nullable Double presencePenalty, @Nullable List<String> stop, @Nullable Double temperature, @Nullable Double topP, @Nullable List<ToolCallback> toolCallbacks, @Nullable Map<String, Object> toolContext, @Nullable Map<String, Integer> logitBias, @Nullable Boolean logprobs, @Nullable Integer topLogprobs, @Nullable Integer maxCompletionTokens, @Nullable Integer n, @Nullable List<String> outputModalities, @Nullable OpenAiChatOptions.AudioParameters outputAudio, @Nullable OpenAiChatModel.ResponseFormat responseFormat, @Nullable OpenAiChatOptions.StreamOptions streamOptions, @Nullable Integer seed, @Nullable Object toolChoice, @Nullable String user, @Nullable Boolean parallelToolCalls, @Nullable Boolean store, @Nullable Map<String, String> metadata, @Nullable String reasoningEffort, @Nullable String verbosity, @Nullable String serviceTier, @Nullable String promptCacheKey, @Nullable Map<String, Object> extraBody) -
Method Summary
Modifier and TypeMethodDescriptionstatic OpenAiChatOptions.Builderbuilder()A builder to create a newToolCallingChatOptionsinstance.boolean@Nullable String@Nullable StringGets the frequency penalty parameter.@Nullable com.openai.credential.Credential@Nullable StringAlias for getAzureDeploymentName()@Nullable DoubleReturns the frequency penalty to use for the chat.Gets the logit bias map.@Nullable BooleanGets whether to return log probabilities.@Nullable IntegerGets the maximum number of completion tokens.int@Nullable IntegerReturns the maximum number of tokens to use for the chat.Gets the metadata map.@Nullable String@Nullable com.openai.azure.AzureOpenAIServiceVersiongetModel()Returns the model to use for the chat.@Nullable IntegergetN()Gets the number of completions to generate.@Nullable String@Nullable OpenAiChatOptions.AudioParametersGets the output audio parameters.Gets the output modalities.@Nullable String@Nullable BooleanGets whether to enable parallel tool calls.@Nullable DoubleReturns the presence penalty to use for the chat.@Nullable StringGets the prompt cache key.@Nullable ProxygetProxy()@Nullable StringGets the reasoning effort level.@Nullable OpenAiChatModel.ResponseFormatGets the response format configuration.@Nullable IntegergetSeed()Gets the random seed for deterministic generation.@Nullable StringGets the service tier.getStop()Gets the stop sequences.Returns the stop sequences to use for the chat.@Nullable BooleangetStore()Gets whether to store the conversation.@Nullable OpenAiChatOptions.StreamOptionsGets the stream options.@Nullable DoubleReturns the temperature to use for the chat.@Nullable List<ToolCallback>ToolCallbacks to be registered with the ChatModel.@Nullable ObjectGets the tool choice configuration.Get the configured tool context.@Nullable IntegergetTopK()Returns the top K to use for the chat.@Nullable IntegerGets the number of top log probabilities to return.@Nullable DoublegetTopP()Returns the top P to use for the chat.@Nullable StringgetUser()Gets the user identifier.@Nullable StringGets the verbosity level.inthashCode()booleanbooleanmutate()Returns a newToolCallingChatOptions.Builderinitialized with the values of thisToolCallingChatOptions.
-
Field Details
-
DEFAULT_CHAT_MODEL
-
-
Constructor Details
-
OpenAiChatOptions
protected OpenAiChatOptions(@Nullable String baseUrl, @Nullable String apiKey, @Nullable com.openai.credential.Credential credential, @Nullable String model, @Nullable String microsoftDeploymentName, @Nullable com.openai.azure.AzureOpenAIServiceVersion microsoftFoundryServiceVersion, @Nullable String organizationId, @Nullable Boolean isMicrosoftFoundry, @Nullable Boolean isGitHubModels, @Nullable Duration timeout, @Nullable Integer maxRetries, @Nullable Proxy proxy, @Nullable Map<String, String> customHeaders, @Nullable Double frequencyPenalty, @Nullable Integer maxTokens, @Nullable Double presencePenalty, @Nullable List<String> stop, @Nullable Double temperature, @Nullable Double topP, @Nullable List<ToolCallback> toolCallbacks, @Nullable Map<String, Object> toolContext, @Nullable Map<String, Integer> logitBias, @Nullable Boolean logprobs, @Nullable Integer topLogprobs, @Nullable Integer maxCompletionTokens, @Nullable Integer n, @Nullable List<String> outputModalities, @Nullable OpenAiChatOptions.AudioParameters outputAudio, @Nullable OpenAiChatModel.ResponseFormat responseFormat, @Nullable OpenAiChatOptions.StreamOptions streamOptions, @Nullable Integer seed, @Nullable Object toolChoice, @Nullable String user, @Nullable Boolean parallelToolCalls, @Nullable Boolean store, @Nullable Map<String, String> metadata, @Nullable String reasoningEffort, @Nullable String verbosity, @Nullable String serviceTier, @Nullable String promptCacheKey, @Nullable Map<String, Object> extraBody)
-
-
Method Details
-
getBaseUrl
Gets the frequency penalty parameter.- Returns:
- the frequency penalty
-
getApiKey
-
getCredential
public @Nullable com.openai.credential.Credential getCredential() -
getModel
Description copied from interface:ChatOptionsReturns the model to use for the chat.- Specified by:
getModelin interfaceChatOptions- Returns:
- the model to use for the chat
-
getMicrosoftDeploymentName
-
getDeploymentName
Alias for getAzureDeploymentName() -
getMicrosoftFoundryServiceVersion
public @Nullable com.openai.azure.AzureOpenAIServiceVersion getMicrosoftFoundryServiceVersion() -
getOrganizationId
-
isMicrosoftFoundry
public boolean isMicrosoftFoundry() -
isGitHubModels
public boolean isGitHubModels() -
getTimeout
-
getMaxRetries
public int getMaxRetries() -
getProxy
-
getCustomHeaders
-
getFrequencyPenalty
Description copied from interface:ChatOptionsReturns the frequency penalty to use for the chat.- Specified by:
getFrequencyPenaltyin interfaceChatOptions- Returns:
- the frequency penalty to use for the chat
-
getLogitBias
Gets the logit bias map.- Returns:
- the logit bias map
-
getLogprobs
Gets whether to return log probabilities.- Returns:
- true if log probabilities should be returned
-
getTopLogprobs
Gets the number of top log probabilities to return.- Returns:
- the number of top log probabilities
-
getMaxTokens
Description copied from interface:ChatOptionsReturns the maximum number of tokens to use for the chat.- Specified by:
getMaxTokensin interfaceChatOptions- Returns:
- the maximum number of tokens to use for the chat
-
getMaxCompletionTokens
Gets the maximum number of completion tokens.- Returns:
- the maximum number of completion tokens
-
getN
Gets the number of completions to generate.- Returns:
- the number of completions
-
getOutputModalities
Gets the output modalities.- Returns:
- the output modalities
-
getOutputAudio
Gets the output audio parameters.- Returns:
- the output audio parameters
-
getPresencePenalty
Description copied from interface:ChatOptionsReturns the presence penalty to use for the chat.- Specified by:
getPresencePenaltyin interfaceChatOptions- Returns:
- the presence penalty to use for the chat
-
getResponseFormat
Gets the response format configuration.- Returns:
- the response format
-
getStreamOptions
Gets the stream options.- Returns:
- the stream options
-
getSeed
Gets the random seed for deterministic generation.- Returns:
- the random seed
-
getStop
Gets the stop sequences.- Returns:
- the list of stop sequences
-
getStopSequences
Description copied from interface:ChatOptionsReturns the stop sequences to use for the chat.- Specified by:
getStopSequencesin interfaceChatOptions- Returns:
- the stop sequences to use for the chat
-
getTemperature
Description copied from interface:ChatOptionsReturns the temperature to use for the chat.- Specified by:
getTemperaturein interfaceChatOptions- Returns:
- the temperature to use for the chat
-
getTopP
Description copied from interface:ChatOptionsReturns the top P to use for the chat.- Specified by:
getTopPin interfaceChatOptions- Returns:
- the top P to use for the chat
-
getToolChoice
Gets the tool choice configuration.- Returns:
- the tool choice option
-
getUser
Gets the user identifier.- Returns:
- the user identifier
-
getParallelToolCalls
Gets whether to enable parallel tool calls.- Returns:
- true if parallel tool calls are enabled
-
getStore
Gets whether to store the conversation.- Returns:
- true if the conversation should be stored
-
getMetadata
Gets the metadata map.- Returns:
- the metadata map
-
getReasoningEffort
Gets the reasoning effort level.- Returns:
- the reasoning effort level
-
getVerbosity
Gets the verbosity level.- Returns:
- the verbosity level
-
getServiceTier
Gets the service tier.- Returns:
- the service tier
-
getPromptCacheKey
Gets the prompt cache key.- Returns:
- the prompt cache key
-
getExtraBody
-
getToolCallbacks
Description copied from interface:ToolCallingChatOptionsToolCallbacks to be registered with the ChatModel.- Specified by:
getToolCallbacksin interfaceToolCallingChatOptions
-
getToolContext
Description copied from interface:ToolCallingChatOptionsGet the configured tool context.- Specified by:
getToolContextin interfaceToolCallingChatOptions- Returns:
- the tool context map.
-
getTopK
Description copied from interface:ChatOptionsReturns the top K to use for the chat.- Specified by:
getTopKin interfaceChatOptions- Returns:
- the top K to use for the chat
-
getOutputSchema
- Specified by:
getOutputSchemain interfaceStructuredOutputChatOptions
-
builder
Description copied from interface:ToolCallingChatOptionsA builder to create a newToolCallingChatOptionsinstance.- Returns:
- Returns a new
ChatOptions.Builder.
-
mutate
Description copied from interface:ToolCallingChatOptionsReturns a newToolCallingChatOptions.Builderinitialized with the values of thisToolCallingChatOptions. Narrows the return type ofChatOptions.mutate()so generic tool calling code can chain methods without casting.- Specified by:
mutatein interfaceChatOptions- Specified by:
mutatein interfaceStructuredOutputChatOptions- Specified by:
mutatein interfaceToolCallingChatOptions
-
equals
-
hashCode
public int hashCode()
-