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 class OpenAiChatModel extends Object implements org.springframework.ai.chat.model.ChatModel
ChatModel and StreamingChatModel implementation for OpenAI backed by OpenAiApi.
Author:
Mark Pollack, Christian Tzolov, Ueibin Kim, John Blum, Josh Long, Jemin Huh, Grogdunn, Hyunjoon Choi, Mariusz Bernacki, luocongqiu, Thomas Vitale, Ilayaperumal Gopinathan, Alexandros Pappas, Soby Chacko, Jonghoon Park
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    OpenAiChatModel(OpenAiApi openAiApi, OpenAiChatOptions defaultOptions, org.springframework.ai.model.tool.ToolCallingManager toolCallingManager, org.springframework.retry.support.RetryTemplate retryTemplate, io.micrometer.observation.ObservationRegistry observationRegistry)
     
    OpenAiChatModel(OpenAiApi openAiApi, OpenAiChatOptions defaultOptions, org.springframework.ai.model.tool.ToolCallingManager toolCallingManager, org.springframework.retry.support.RetryTemplate retryTemplate, io.micrometer.observation.ObservationRegistry observationRegistry, org.springframework.ai.model.tool.ToolExecutionEligibilityPredicate toolExecutionEligibilityPredicate)
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
    org.springframework.ai.chat.model.ChatResponse
    call(org.springframework.ai.chat.prompt.Prompt prompt)
     
     
    org.springframework.ai.chat.prompt.ChatOptions
     
    org.springframework.ai.chat.model.ChatResponse
    internalCall(org.springframework.ai.chat.prompt.Prompt prompt, org.springframework.ai.chat.model.ChatResponse previousChatResponse)
     
    reactor.core.publisher.Flux<org.springframework.ai.chat.model.ChatResponse>
    internalStream(org.springframework.ai.chat.prompt.Prompt prompt, org.springframework.ai.chat.model.ChatResponse previousChatResponse)
     
    Returns a builder pre-populated with the current configuration for mutation.
    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

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

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

    call, call

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

    stream, stream
  • Constructor Details

    • OpenAiChatModel

      public OpenAiChatModel(OpenAiApi openAiApi, OpenAiChatOptions defaultOptions, org.springframework.ai.model.tool.ToolCallingManager toolCallingManager, org.springframework.retry.support.RetryTemplate retryTemplate, io.micrometer.observation.ObservationRegistry observationRegistry)
    • OpenAiChatModel

      public OpenAiChatModel(OpenAiApi openAiApi, OpenAiChatOptions defaultOptions, org.springframework.ai.model.tool.ToolCallingManager toolCallingManager, org.springframework.retry.support.RetryTemplate retryTemplate, io.micrometer.observation.ObservationRegistry observationRegistry, org.springframework.ai.model.tool.ToolExecutionEligibilityPredicate toolExecutionEligibilityPredicate)
  • Method Details

    • 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>
    • internalCall

      public org.springframework.ai.chat.model.ChatResponse internalCall(org.springframework.ai.chat.prompt.Prompt prompt, org.springframework.ai.chat.model.ChatResponse previousChatResponse)
    • 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>
    • internalStream

      public reactor.core.publisher.Flux<org.springframework.ai.chat.model.ChatResponse> internalStream(org.springframework.ai.chat.prompt.Prompt prompt, org.springframework.ai.chat.model.ChatResponse previousChatResponse)
    • getDefaultOptions

      public org.springframework.ai.chat.prompt.ChatOptions getDefaultOptions()
      Specified by:
      getDefaultOptions in interface org.springframework.ai.chat.model.ChatModel
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • setObservationConvention

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

      public static OpenAiChatModel.Builder builder()
    • mutate

      public OpenAiChatModel.Builder mutate()
      Returns a builder pre-populated with the current configuration for mutation.
    • clone

      public OpenAiChatModel clone()
      Overrides:
      clone in class Object