Class OpenAiChatModel

java.lang.Object
org.springframework.ai.openai.OpenAiChatModel
All Implemented Interfaces:
ChatModel, StreamingChatModel, Model<Prompt,ChatResponse>, StreamingModel<Prompt,ChatResponse>

public final class OpenAiChatModel extends Object implements ChatModel
Chat Model implementation using the OpenAI Java SDK.
Author:
Julien Dubois, Christian Tzolov, Soby Chacko, Ilayaperumal Gopinathan, Thomas Vitale, Eric Bottard, Taewoong Kim
  • Method Details

    • builder

      public static OpenAiChatModel.Builder builder()
      Creates a new builder for OpenAiChatModel.
      Returns:
      a new builder instance
    • getOptions

      public OpenAiChatOptions getOptions()
      Gets the chat options for this model.
      Specified by:
      getOptions in interface ChatModel
      Returns:
      the chat options
      Since:
      2.0.0
    • getDefaultOptions

      @Deprecated(forRemoval=true) public ChatOptions getDefaultOptions()
      Deprecated, for removal: This API element is subject to removal in a future version.
      use getOptions() instead.
      Specified by:
      getDefaultOptions in interface ChatModel
    • call

      public ChatResponse call(Prompt prompt)
      Description copied from interface: Model
      Executes a method call to the AI model.
      Specified by:
      call in interface ChatModel
      Specified by:
      call in interface Model<Prompt,ChatResponse>
      Parameters:
      prompt - the request object to be sent to the AI model
      Returns:
      the response from the AI model
    • stream

      public reactor.core.publisher.Flux<ChatResponse> stream(Prompt prompt)
      Description copied from interface: StreamingModel
      Executes a method call to the AI model.
      Specified by:
      stream in interface ChatModel
      Specified by:
      stream in interface StreamingChatModel
      Specified by:
      stream in interface StreamingModel<Prompt,ChatResponse>
      Parameters:
      prompt - the request object to be sent to the AI model
      Returns:
      the streaming response from the AI model
    • parseToolChoice

      public static com.openai.models.chat.completions.ChatCompletionToolChoiceOption parseToolChoice(tools.jackson.databind.JsonNode node)
    • setObservationConvention

      public void setObservationConvention(ChatModelObservationConvention observationConvention)
      Use the provided convention for reporting observation data
      Parameters:
      observationConvention - The provided convention