Class OpenAiStreamingChatModel

java.lang.Object
dev.langchain4j.model.openai.OpenAiStreamingChatModel
All Implemented Interfaces:
dev.langchain4j.model.chat.StreamingChatLanguageModel, dev.langchain4j.model.chat.TokenCountEstimator

public class OpenAiStreamingChatModel extends Object implements dev.langchain4j.model.chat.StreamingChatLanguageModel, dev.langchain4j.model.chat.TokenCountEstimator
Represents an OpenAI language model with a chat completion interface, such as gpt-3.5-turbo and gpt-4. The model's response is streamed token by token and should be handled with StreamingResponseHandler. You can find description of parameters here.
  • Constructor Details

  • Method Details

    • modelName

      public String modelName()
    • generate

      public void generate(List<dev.langchain4j.data.message.ChatMessage> messages, dev.langchain4j.model.StreamingResponseHandler<dev.langchain4j.data.message.AiMessage> handler)
      Specified by:
      generate in interface dev.langchain4j.model.chat.StreamingChatLanguageModel
    • generate

      public void generate(List<dev.langchain4j.data.message.ChatMessage> messages, List<dev.langchain4j.agent.tool.ToolSpecification> toolSpecifications, dev.langchain4j.model.StreamingResponseHandler<dev.langchain4j.data.message.AiMessage> handler)
      Specified by:
      generate in interface dev.langchain4j.model.chat.StreamingChatLanguageModel
    • generate

      public void generate(List<dev.langchain4j.data.message.ChatMessage> messages, dev.langchain4j.agent.tool.ToolSpecification toolSpecification, dev.langchain4j.model.StreamingResponseHandler<dev.langchain4j.data.message.AiMessage> handler)
      Specified by:
      generate in interface dev.langchain4j.model.chat.StreamingChatLanguageModel
    • estimateTokenCount

      public int estimateTokenCount(List<dev.langchain4j.data.message.ChatMessage> messages)
      Specified by:
      estimateTokenCount in interface dev.langchain4j.model.chat.TokenCountEstimator
    • withApiKey

      @Deprecated public static OpenAiStreamingChatModel withApiKey(String apiKey)
      Deprecated.
      use builder() instead and explicitly set the model name and, if required, other parameters.
    • builder