Interface ModelProvider.Custom

All Superinterfaces:
ModelProvider
Enclosing interface:
ModelProvider

public static non-sealed interface ModelProvider.Custom extends ModelProvider
Custom models can be added by implementing this interface and, and the underlying implementations of dev.langchain4j.model.chat.ChatModel and (optionally) dev.langchain4j.model.chat.StreamingChatModel.

Refer to the Langchain4j documentation or reference implementations for how to implement the ChatModel and StreamingChatModel.

  • Method Details

    • createChatModel

      Object createChatModel()
      Returns:
      an instance of dev.langchain4j.model.chat.ChatModel
    • createStreamingChatModel

      Object createStreamingChatModel()
      If you don't need streaming you can throw an exception from this method.
      Returns:
      an instance of dev.langchain4j.model.chat.StreamingChatModel
    • modelName

      default String modelName()
      Override this method to provide a meaningful model name for your custom provider.
      Returns:
      the model name, defaults to 'custom'.
    • withAdditionalModelRequestHeaders

      default ModelProvider withAdditionalModelRequestHeaders(List<akka.http.javadsl.model.HttpHeader> additionalModelRequestHeaders)
      A custom provider builds its own chat model, so the SDK cannot attach headers to its requests. Override this method to keep the given headers, and add them in createChatModel() and createStreamingChatModel(). The given list is the one stated in code. The SDK does not merge it with headers the provider already holds.
      Specified by:
      withAdditionalModelRequestHeaders in interface ModelProvider
      Parameters:
      additionalModelRequestHeaders - the headers to add to each model request
      Returns:
      a copy of this provider carrying the given headers
      Throws:
      UnsupportedOperationException - unless this method is overridden