Class OpenAiChatOptions

java.lang.Object
org.springframework.ai.openai.AbstractOpenAiOptions
org.springframework.ai.openai.OpenAiChatOptions
All Implemented Interfaces:
ChatOptions, ModelOptions, StructuredOutputChatOptions, ToolCallingChatOptions

public class OpenAiChatOptions extends AbstractOpenAiOptions 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
  • Field Details

    • DEFAULT_CHAT_MODEL

      public static final String DEFAULT_CHAT_MODEL
  • Constructor Details

  • Method Details

    • getFrequencyPenalty

      public @Nullable Double getFrequencyPenalty()
      Gets the frequency penalty parameter.
      Specified by:
      getFrequencyPenalty in interface ChatOptions
      Returns:
      the frequency penalty
    • setFrequencyPenalty

      public void setFrequencyPenalty(@Nullable Double frequencyPenalty)
      Sets the frequency penalty parameter.
      Parameters:
      frequencyPenalty - the frequency penalty to set
    • getLogitBias

      public @Nullable Map<String,Integer> getLogitBias()
      Gets the logit bias map.
      Returns:
      the logit bias map
    • setLogitBias

      public void setLogitBias(@Nullable Map<String,Integer> logitBias)
      Sets the logit bias map.
      Parameters:
      logitBias - the logit bias map to set
    • getLogprobs

      public @Nullable Boolean getLogprobs()
      Gets whether to return log probabilities.
      Returns:
      true if log probabilities should be returned
    • setLogprobs

      public void setLogprobs(@Nullable Boolean logprobs)
      Sets whether to return log probabilities.
      Parameters:
      logprobs - whether to return log probabilities
    • getTopLogprobs

      public @Nullable Integer getTopLogprobs()
      Gets the number of top log probabilities to return.
      Returns:
      the number of top log probabilities
    • setTopLogprobs

      public void setTopLogprobs(@Nullable Integer topLogprobs)
      Sets the number of top log probabilities to return.
      Parameters:
      topLogprobs - the number of top log probabilities
    • getMaxTokens

      public @Nullable Integer getMaxTokens()
      Description copied from interface: ChatOptions
      Returns the maximum number of tokens to use for the chat.
      Specified by:
      getMaxTokens in interface ChatOptions
      Returns:
      the maximum number of tokens to use for the chat
    • setMaxTokens

      public void setMaxTokens(@Nullable Integer maxTokens)
      Sets the maximum number of tokens to generate.
      Parameters:
      maxTokens - the maximum number of tokens
    • getMaxCompletionTokens

      public @Nullable Integer getMaxCompletionTokens()
      Gets the maximum number of completion tokens.
      Returns:
      the maximum number of completion tokens
    • setMaxCompletionTokens

      public void setMaxCompletionTokens(@Nullable Integer maxCompletionTokens)
      Sets the maximum number of completion tokens.
      Parameters:
      maxCompletionTokens - the maximum number of completion tokens
    • getN

      public @Nullable Integer getN()
      Gets the number of completions to generate.
      Returns:
      the number of completions
    • setN

      public void setN(@Nullable Integer n)
      Sets the number of completions to generate.
      Parameters:
      n - the number of completions
    • getOutputModalities

      public @Nullable List<String> getOutputModalities()
      Gets the output modalities.
      Returns:
      the output modalities
    • setOutputModalities

      public void setOutputModalities(@Nullable List<String> outputModalities)
      Sets the output modalities.
      Parameters:
      outputModalities - the output modalities
    • getOutputAudio

      public @Nullable OpenAiChatOptions.AudioParameters getOutputAudio()
      Gets the output audio parameters.
      Returns:
      the output audio parameters
    • setOutputAudio

      public void setOutputAudio(@Nullable OpenAiChatOptions.AudioParameters outputAudio)
      Sets the output audio parameters.
      Parameters:
      outputAudio - the output audio parameters
    • getPresencePenalty

      public @Nullable Double getPresencePenalty()
      Description copied from interface: ChatOptions
      Returns the presence penalty to use for the chat.
      Specified by:
      getPresencePenalty in interface ChatOptions
      Returns:
      the presence penalty to use for the chat
    • setPresencePenalty

      public void setPresencePenalty(@Nullable Double presencePenalty)
      Sets the presence penalty parameter.
      Parameters:
      presencePenalty - the presence penalty to set
    • getResponseFormat

      public @Nullable OpenAiChatModel.ResponseFormat getResponseFormat()
      Gets the response format configuration.
      Returns:
      the response format
    • setResponseFormat

      public void setResponseFormat(@Nullable OpenAiChatModel.ResponseFormat responseFormat)
      Sets the response format configuration.
      Parameters:
      responseFormat - the response format to set
    • getStreamOptions

      public @Nullable OpenAiChatOptions.StreamOptions getStreamOptions()
      Gets the stream options.
      Returns:
      the stream options
    • setStreamOptions

      public void setStreamOptions(@Nullable OpenAiChatOptions.StreamOptions streamOptions)
      Sets the stream options.
      Parameters:
      streamOptions - the stream options to set
    • getSeed

      public @Nullable Integer getSeed()
      Gets the random seed for deterministic generation.
      Returns:
      the random seed
    • setSeed

      public void setSeed(@Nullable Integer seed)
      Sets the random seed for deterministic generation.
      Parameters:
      seed - the random seed
    • getStop

      public @Nullable List<String> getStop()
      Gets the stop sequences.
      Returns:
      the list of stop sequences
    • setStop

      public void setStop(@Nullable List<String> stop)
      Sets the stop sequences.
      Parameters:
      stop - the list of stop sequences
    • getStopSequences

      public @Nullable List<String> getStopSequences()
      Description copied from interface: ChatOptions
      Returns the stop sequences to use for the chat.
      Specified by:
      getStopSequences in interface ChatOptions
      Returns:
      the stop sequences to use for the chat
    • setStopSequences

      public void setStopSequences(@Nullable List<String> stopSequences)
      Sets the stop sequences.
      Parameters:
      stopSequences - the list of stop sequences
    • getTemperature

      public @Nullable Double getTemperature()
      Description copied from interface: ChatOptions
      Returns the temperature to use for the chat.
      Specified by:
      getTemperature in interface ChatOptions
      Returns:
      the temperature to use for the chat
    • setTemperature

      public void setTemperature(@Nullable Double temperature)
      Sets the temperature for sampling.
      Parameters:
      temperature - the temperature value
    • getTopP

      public @Nullable Double getTopP()
      Description copied from interface: ChatOptions
      Returns the top P to use for the chat.
      Specified by:
      getTopP in interface ChatOptions
      Returns:
      the top P to use for the chat
    • setTopP

      public void setTopP(@Nullable Double topP)
      Sets the top-p nucleus sampling parameter.
      Parameters:
      topP - the top-p value
    • getToolChoice

      public @Nullable Object getToolChoice()
      Gets the tool choice configuration.
      Returns:
      the tool choice option
    • setToolChoice

      public void setToolChoice(@Nullable Object toolChoice)
      Sets the tool choice configuration.
      Parameters:
      toolChoice - the tool choice option
    • getUser

      public @Nullable String getUser()
      Gets the user identifier.
      Returns:
      the user identifier
    • setUser

      public void setUser(@Nullable String user)
      Sets the user identifier.
      Parameters:
      user - the user identifier
    • getParallelToolCalls

      public @Nullable Boolean getParallelToolCalls()
      Gets whether to enable parallel tool calls.
      Returns:
      true if parallel tool calls are enabled
    • setParallelToolCalls

      public void setParallelToolCalls(@Nullable Boolean parallelToolCalls)
      Sets whether to enable parallel tool calls.
      Parameters:
      parallelToolCalls - whether to enable parallel tool calls
    • getStore

      public @Nullable Boolean getStore()
      Gets whether to store the conversation.
      Returns:
      true if the conversation should be stored
    • setStore

      public void setStore(@Nullable Boolean store)
      Sets whether to store the conversation.
      Parameters:
      store - whether to store the conversation
    • getMetadata

      public @Nullable Map<String,String> getMetadata()
      Gets the metadata map.
      Returns:
      the metadata map
    • setMetadata

      public void setMetadata(@Nullable Map<String,String> metadata)
      Sets the metadata map.
      Parameters:
      metadata - the metadata map
    • getReasoningEffort

      public @Nullable String getReasoningEffort()
      Gets the reasoning effort level.
      Returns:
      the reasoning effort level
    • setReasoningEffort

      public void setReasoningEffort(@Nullable String reasoningEffort)
      Sets the reasoning effort level.
      Parameters:
      reasoningEffort - the reasoning effort level
    • getVerbosity

      public @Nullable String getVerbosity()
      Gets the verbosity level.
      Returns:
      the verbosity level
    • setVerbosity

      public void setVerbosity(@Nullable String verbosity)
      Sets the verbosity level.
      Parameters:
      verbosity - the verbosity level
    • getServiceTier

      public @Nullable String getServiceTier()
      Gets the service tier.
      Returns:
      the service tier
    • setServiceTier

      public void setServiceTier(@Nullable String serviceTier)
      Sets the service tier.
      Parameters:
      serviceTier - the service tier
    • getExtraBody

      public @Nullable Map<String,Object> getExtraBody()
    • setExtraBody

      public void setExtraBody(@Nullable Map<String,Object> extraBody)
    • addExtraBodyProperty

      public void addExtraBodyProperty(String key, Object value)
    • getToolCallbacks

      public List<ToolCallback> getToolCallbacks()
      Description copied from interface: ToolCallingChatOptions
      ToolCallbacks to be registered with the ChatModel.
      Specified by:
      getToolCallbacks in interface ToolCallingChatOptions
    • setToolCallbacks

      public void setToolCallbacks(List<ToolCallback> toolCallbacks)
      Description copied from interface: ToolCallingChatOptions
      Set the ToolCallbacks to be registered with the ChatModel.
      Specified by:
      setToolCallbacks in interface ToolCallingChatOptions
    • getToolNames

      public Set<String> getToolNames()
      Description copied from interface: ToolCallingChatOptions
      Names of the tools to register with the ChatModel.
      Specified by:
      getToolNames in interface ToolCallingChatOptions
    • setToolNames

      public void setToolNames(Set<String> toolNames)
      Description copied from interface: ToolCallingChatOptions
      Set the names of the tools to register with the ChatModel.
      Specified by:
      setToolNames in interface ToolCallingChatOptions
    • getInternalToolExecutionEnabled

      public @Nullable Boolean getInternalToolExecutionEnabled()
      Description copied from interface: ToolCallingChatOptions
      Whether the ChatModel is responsible for executing the tools requested by the model or if the tools should be executed directly by the caller.
      Specified by:
      getInternalToolExecutionEnabled in interface ToolCallingChatOptions
    • setInternalToolExecutionEnabled

      public void setInternalToolExecutionEnabled(@Nullable Boolean internalToolExecutionEnabled)
      Description copied from interface: ToolCallingChatOptions
      Set whether the ChatModel is responsible for executing the tools requested by the model or if the tools should be executed directly by the caller.
      Specified by:
      setInternalToolExecutionEnabled in interface ToolCallingChatOptions
    • getToolContext

      public Map<String,Object> getToolContext()
      Description copied from interface: ToolCallingChatOptions
      Get the configured tool context.
      Specified by:
      getToolContext in interface ToolCallingChatOptions
      Returns:
      the tool context map.
    • setToolContext

      public void setToolContext(Map<String,Object> toolContext)
      Description copied from interface: ToolCallingChatOptions
      Set the tool context values as map.
      Specified by:
      setToolContext in interface ToolCallingChatOptions
      Parameters:
      toolContext - as map
    • getTopK

      public @Nullable Integer getTopK()
      Description copied from interface: ChatOptions
      Returns the top K to use for the chat.
      Specified by:
      getTopK in interface ChatOptions
      Returns:
      the top K to use for the chat
    • getOutputSchema

      public @Nullable String getOutputSchema()
      Specified by:
      getOutputSchema in interface StructuredOutputChatOptions
    • setOutputSchema

      public void setOutputSchema(@Nullable String outputSchema)
      Specified by:
      setOutputSchema in interface StructuredOutputChatOptions
    • builder

      public static OpenAiChatOptions.Builder builder()
    • fromOptions

      public static OpenAiChatOptions fromOptions(OpenAiChatOptions fromOptions)
    • copy

      public OpenAiChatOptions copy()
      Description copied from interface: ChatOptions
      Returns a copy of this ChatOptions.
      Specified by:
      copy in interface ChatOptions
      Returns:
      a copy of this ChatOptions
    • mutate

      public OpenAiChatOptions.Builder mutate()
      Description copied from interface: ChatOptions
      Returns a new ChatOptions.Builder initialized with the values of this ChatOptions. Concrete ChatOptions classes must override this to return the most concrete builder implementation.
      Specified by:
      mutate in interface ChatOptions
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object