Class OpenAiChatModel

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

public final class OpenAiChatModel extends Object implements org.springframework.ai.chat.model.ChatModel
Chat Model implementation using the OpenAI Java SDK.
Author:
Julien Dubois, Christian Tzolov, Soby Chacko, Ilayaperumal Gopinathan, Thomas Vitale, Eric Bottard
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Builder for creating OpenAiChatModel instances.
    static class 
    Response format (text, json_object, json_schema) for OpenAiChatModel responses.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new builder for OpenAiChatModel.
    org.springframework.ai.chat.model.ChatResponse
    call(org.springframework.ai.chat.prompt.Prompt prompt)
     
    org.springframework.ai.chat.prompt.ChatOptions
    Deprecated, for removal: This API element is subject to removal in a future version.
    use getOptions() instead.
    Gets the chat options for this model.
    static com.openai.models.chat.completions.ChatCompletionToolChoiceOption
    parseToolChoice(tools.jackson.databind.JsonNode node)
     
    void
    setObservationConvention(org.springframework.ai.chat.observation.ChatModelObservationConvention observationConvention)
    Use the provided convention for reporting observation data
    reactor.core.publisher.Flux<org.springframework.ai.chat.model.ChatResponse>
    stream(org.springframework.ai.chat.prompt.Prompt prompt)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.ai.chat.model.ChatModel

    buildRequestPrompt, call, call

    Methods inherited from interface org.springframework.ai.chat.model.StreamingChatModel

    stream, stream
  • 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 org.springframework.ai.chat.model.ChatModel
      Returns:
      the chat options
      Since:
      2.0.0
    • getDefaultOptions

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

      public org.springframework.ai.chat.model.ChatResponse call(org.springframework.ai.chat.prompt.Prompt prompt)
      Specified by:
      call in interface org.springframework.ai.chat.model.ChatModel
      Specified by:
      call in interface org.springframework.ai.model.Model<org.springframework.ai.chat.prompt.Prompt,org.springframework.ai.chat.model.ChatResponse>
    • stream

      public reactor.core.publisher.Flux<org.springframework.ai.chat.model.ChatResponse> stream(org.springframework.ai.chat.prompt.Prompt prompt)
      Specified by:
      stream in interface org.springframework.ai.chat.model.ChatModel
      Specified by:
      stream in interface org.springframework.ai.chat.model.StreamingChatModel
      Specified by:
      stream in interface org.springframework.ai.model.StreamingModel<org.springframework.ai.chat.prompt.Prompt,org.springframework.ai.chat.model.ChatResponse>
    • parseToolChoice

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

      public void setObservationConvention(org.springframework.ai.chat.observation.ChatModelObservationConvention observationConvention)
      Use the provided convention for reporting observation data
      Parameters:
      observationConvention - The provided convention