Class OpenAiChatModel

java.lang.Object
dev.langchain4j.model.openai.OpenAiChatModel
All Implemented Interfaces:
dev.langchain4j.model.chat.ChatLanguageModel, dev.langchain4j.model.chat.TokenCountEstimator

public class OpenAiChatModel extends Object implements dev.langchain4j.model.chat.ChatLanguageModel, dev.langchain4j.model.chat.TokenCountEstimator
Represents an OpenAI language model with a chat completion interface, such as gpt-3.5-turbo and gpt-4. You can find description of parameters here.
  • Nested Class Summary

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

    Constructors
    Constructor
    Description
    OpenAiChatModel(String baseUrl, String apiKey, String organizationId, String modelName, Double temperature, Double topP, List<String> stop, Integer maxTokens, Integer maxCompletionTokens, Double presencePenalty, Double frequencyPenalty, Map<String,Integer> logitBias, String responseFormat, Boolean strictJsonSchema, Integer seed, String user, Boolean strictTools, Boolean parallelToolCalls, Duration timeout, Integer maxRetries, Proxy proxy, Boolean logRequests, Boolean logResponses, dev.langchain4j.model.Tokenizer tokenizer, Map<String,String> customHeaders, List<dev.langchain4j.model.chat.listener.ChatModelListener> listeners)
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
    dev.langchain4j.model.chat.response.ChatResponse
    chat(dev.langchain4j.model.chat.request.ChatRequest request)
     
    int
    estimateTokenCount(List<dev.langchain4j.data.message.ChatMessage> messages)
     
    dev.langchain4j.model.output.Response<dev.langchain4j.data.message.AiMessage>
    generate(List<dev.langchain4j.data.message.ChatMessage> messages)
     
    dev.langchain4j.model.output.Response<dev.langchain4j.data.message.AiMessage>
    generate(List<dev.langchain4j.data.message.ChatMessage> messages, dev.langchain4j.agent.tool.ToolSpecification toolSpecification)
     
    dev.langchain4j.model.output.Response<dev.langchain4j.data.message.AiMessage>
    generate(List<dev.langchain4j.data.message.ChatMessage> messages, List<dev.langchain4j.agent.tool.ToolSpecification> toolSpecifications)
     
     
    Set<dev.langchain4j.model.chat.Capability>
     
    Deprecated.
    use builder() instead and explicitly set the model name and, if required, other parameters.

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface dev.langchain4j.model.chat.ChatLanguageModel

    generate, generate

    Methods inherited from interface dev.langchain4j.model.chat.TokenCountEstimator

    estimateTokenCount, estimateTokenCount, estimateTokenCount, estimateTokenCount
  • Constructor Details

  • Method Details

    • modelName

      public String modelName()
    • supportedCapabilities

      public Set<dev.langchain4j.model.chat.Capability> supportedCapabilities()
      Specified by:
      supportedCapabilities in interface dev.langchain4j.model.chat.ChatLanguageModel
    • generate

      public dev.langchain4j.model.output.Response<dev.langchain4j.data.message.AiMessage> generate(List<dev.langchain4j.data.message.ChatMessage> messages)
      Specified by:
      generate in interface dev.langchain4j.model.chat.ChatLanguageModel
    • generate

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

      public dev.langchain4j.model.output.Response<dev.langchain4j.data.message.AiMessage> generate(List<dev.langchain4j.data.message.ChatMessage> messages, dev.langchain4j.agent.tool.ToolSpecification toolSpecification)
      Specified by:
      generate in interface dev.langchain4j.model.chat.ChatLanguageModel
    • chat

      public dev.langchain4j.model.chat.response.ChatResponse chat(dev.langchain4j.model.chat.request.ChatRequest request)
      Specified by:
      chat in interface dev.langchain4j.model.chat.ChatLanguageModel
    • 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 OpenAiChatModel withApiKey(String apiKey)
      Deprecated.
      use builder() instead and explicitly set the model name and, if required, other parameters.
    • builder

      public static OpenAiChatModel.OpenAiChatModelBuilder builder()