Record Class OpenAiApi.ChatCompletionRequest

java.lang.Object
java.lang.Record
org.springframework.ai.openai.api.OpenAiApi.ChatCompletionRequest
Record Components:
messages - A list of messages comprising the conversation so far.
model - ID of the model to use.
store - Whether to store the output of this chat completion request for use in OpenAI's model distillation or evals products.
metadata - Developer-defined tags and values used for filtering completions in the OpenAI's dashboard.
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.
logitBias - Modify the likelihood of specified tokens appearing in the completion. Accepts a JSON object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.
logprobs - 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'.
topLogprobs - 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.
maxTokens - The maximum number of tokens that can be generated in the chat completion. This value can be used to control costs for text generated via API. This value is now deprecated in favor of max_completion_tokens, and is not compatible with o1 series models. The field is retained for use with other openai models and openai compatible models.
maxCompletionTokens - An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens.
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 the choices. Keep n as 1 to minimize costs.
outputModalities - 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"].
audioParameters - Parameters for audio output. Required when audio output is requested with outputModalities: ["audio"].
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.
responseFormat - An object specifying the format that the model must output. Setting to { "type": "json_object" } enables JSON mode, which guarantees the message the model generates is valid JSON.
seed - This feature is in Beta. If specified, our 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.
serviceTier - Specifies the latency tier to use for processing the request. This parameter is relevant for customers subscribed to the scale tier service. When this parameter is set, the response body will include the service_tier utilized.
stop - Up to 4 sequences where the API will stop generating further tokens.
stream - If set, partial message deltas will be sent.Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message.
streamOptions - Options for streaming response. Only set this when you set.
temperature - What sampling temperature to use, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or top_p but not both.
topP - An alternative to sampling with temperature, called 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.
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.
toolChoice - Controls which (if any) function is called by the model. 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. Specifying a particular function via {"type: "function", "function": {"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. Use the OpenAiApi.ChatCompletionRequest.ToolChoiceBuilder to create the tool choice value.
user - A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
parallelToolCalls - If set to true, the model will call all functions in the tools list in parallel. Otherwise, the model will call the functions in the tools list in the order they are provided.
reasoningEffort - Constrains effort on reasoning for reasoning models. 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.
webSearchOptions - Options for web search.
verbosity - Controls the verbosity of the model's response.
Enclosing class:
OpenAiApi

public static record OpenAiApi.ChatCompletionRequest(List<OpenAiApi.ChatCompletionMessage> messages, String model, Boolean store, Map<String,String> metadata, Double frequencyPenalty, Map<String,Integer> logitBias, Boolean logprobs, Integer topLogprobs, Integer maxTokens, Integer maxCompletionTokens, Integer n, List<OpenAiApi.OutputModality> outputModalities, OpenAiApi.ChatCompletionRequest.AudioParameters audioParameters, Double presencePenalty, ResponseFormat responseFormat, Integer seed, String serviceTier, List<String> stop, Boolean stream, OpenAiApi.ChatCompletionRequest.StreamOptions streamOptions, Double temperature, Double topP, List<OpenAiApi.FunctionTool> tools, Object toolChoice, Boolean parallelToolCalls, String user, String reasoningEffort, OpenAiApi.ChatCompletionRequest.WebSearchOptions webSearchOptions, String verbosity) extends Record
Creates a model request for the given chat conversation.
  • Constructor Details

    • ChatCompletionRequest

      public ChatCompletionRequest(List<OpenAiApi.ChatCompletionMessage> messages, String model, Double temperature)
      Shortcut constructor for a chat completion request with the given messages, model and temperature.
      Parameters:
      messages - A list of messages comprising the conversation so far.
      model - ID of the model to use.
      temperature - What sampling temperature to use, between 0 and 1.
    • ChatCompletionRequest

      public ChatCompletionRequest(List<OpenAiApi.ChatCompletionMessage> messages, String model, OpenAiApi.ChatCompletionRequest.AudioParameters audio, boolean stream)
      Shortcut constructor for a chat completion request with text and audio output.
      Parameters:
      messages - A list of messages comprising the conversation so far.
      model - ID of the model to use.
      audio - Parameters for audio output. Required when audio output is requested with outputModalities: ["audio"].
    • ChatCompletionRequest

      public ChatCompletionRequest(List<OpenAiApi.ChatCompletionMessage> messages, String model, Double temperature, boolean stream)
      Shortcut constructor for a chat completion request with the given messages, model, temperature and control for streaming.
      Parameters:
      messages - A list of messages comprising the conversation so far.
      model - ID of the model to use.
      temperature - What sampling temperature to use, between 0 and 1.
      stream - If set, partial message deltas will be sent.Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message.
    • ChatCompletionRequest

      public ChatCompletionRequest(List<OpenAiApi.ChatCompletionMessage> messages, String model, List<OpenAiApi.FunctionTool> tools, Object toolChoice)
      Shortcut constructor for a chat completion request with the given messages, model, tools and tool choice. Streaming is set to false, temperature to 0.8 and all other parameters are null.
      Parameters:
      messages - A list of messages comprising the conversation so far.
      model - ID of the model to use.
      tools - A list of tools the model may call. Currently, only functions are supported as a tool.
      toolChoice - Controls which (if any) function is called by the model.
    • ChatCompletionRequest

      public ChatCompletionRequest(List<OpenAiApi.ChatCompletionMessage> messages, Boolean stream)
      Shortcut constructor for a chat completion request with the given messages for streaming.
      Parameters:
      messages - A list of messages comprising the conversation so far.
      stream - If set, partial message deltas will be sent.Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message.
    • ChatCompletionRequest

      public ChatCompletionRequest(List<OpenAiApi.ChatCompletionMessage> messages, String model, Boolean store, Map<String,String> metadata, Double frequencyPenalty, Map<String,Integer> logitBias, Boolean logprobs, Integer topLogprobs, Integer maxTokens, Integer maxCompletionTokens, Integer n, List<OpenAiApi.OutputModality> outputModalities, OpenAiApi.ChatCompletionRequest.AudioParameters audioParameters, Double presencePenalty, ResponseFormat responseFormat, Integer seed, String serviceTier, List<String> stop, Boolean stream, OpenAiApi.ChatCompletionRequest.StreamOptions streamOptions, Double temperature, Double topP, List<OpenAiApi.FunctionTool> tools, Object toolChoice, Boolean parallelToolCalls, String user, String reasoningEffort, OpenAiApi.ChatCompletionRequest.WebSearchOptions webSearchOptions, String verbosity)
      Creates an instance of a ChatCompletionRequest record class.
      Parameters:
      messages - the value for the messages record component
      model - the value for the model record component
      store - the value for the store record component
      metadata - the value for the metadata record component
      frequencyPenalty - the value for the frequencyPenalty record component
      logitBias - the value for the logitBias record component
      logprobs - the value for the logprobs record component
      topLogprobs - the value for the topLogprobs record component
      maxTokens - the value for the maxTokens record component
      maxCompletionTokens - the value for the maxCompletionTokens record component
      n - the value for the n record component
      outputModalities - the value for the outputModalities record component
      audioParameters - the value for the audioParameters record component
      presencePenalty - the value for the presencePenalty record component
      responseFormat - the value for the responseFormat record component
      seed - the value for the seed record component
      serviceTier - the value for the serviceTier record component
      stop - the value for the stop record component
      stream - the value for the stream record component
      streamOptions - the value for the streamOptions record component
      temperature - the value for the temperature record component
      topP - the value for the topP record component
      tools - the value for the tools record component
      toolChoice - the value for the toolChoice record component
      parallelToolCalls - the value for the parallelToolCalls record component
      user - the value for the user record component
      reasoningEffort - the value for the reasoningEffort record component
      webSearchOptions - the value for the webSearchOptions record component
      verbosity - the value for the verbosity record component
  • Method Details