Class WatsonxDeploymentChatModel

java.lang.Object
dev.langchain4j.model.watsonx.WatsonxDeploymentChatModel
All Implemented Interfaces:
ChatModel

public class WatsonxDeploymentChatModel extends Object implements ChatModel
A ChatModel implementation that integrates the IBM watsonx.ai Deployment with LangChain4j.

Example usage:

ChatModel chatModel = WatsonxDeploymentChatModel.builder()
    .baseUrl("https://...") // or use CloudRegion
    .apiKey("...")
    .deploymentId("...")
    .maxOutputTokens(0)
    .temperature(0.7)
    .build();
  • Field Details

    • deploymentService

      protected final com.ibm.watsonx.ai.deployment.DeploymentService deploymentService
    • deploymentId

      protected final String deploymentId
    • listeners

      protected final List<ChatModelListener> listeners
    • defaultRequestParameters

      protected final ChatRequestParameters defaultRequestParameters
    • supportedCapabilities

      protected final Set<Capability> supportedCapabilities
    • strictJsonSchema

      protected final boolean strictJsonSchema
  • Method Details

    • doChat

      public ChatResponse doChat(ChatRequest chatRequest)
      Specified by:
      doChat in interface ChatModel
    • builder

      public static WatsonxDeploymentChatModel.Builder builder()
      Returns a new WatsonxDeploymentChatModel.Builder instance.

      Example usage:

      ChatModel chatModel = WatsonxDeploymentChatModel.builder()
          .baseUrl("https://...") // or use CloudRegion
          .apiKey("...")
          .deploymentId("...")
          .maxOutputTokens(0)
          .temperature(0.7)
          .build();
      
      Returns:
      WatsonxDeploymentChatModel.Builder instance.
    • buildChatRequest

      protected com.ibm.watsonx.ai.deployment.DeploymentChatRequest buildChatRequest(List<com.ibm.watsonx.ai.chat.model.ChatMessage> messages, List<com.ibm.watsonx.ai.chat.model.Tool> tools, ChatRequestParameters parameters)
    • chatProvider

      protected com.ibm.watsonx.ai.chat.ChatProvider<com.ibm.watsonx.ai.deployment.DeploymentChatRequest, com.ibm.watsonx.ai.chat.TextChatResponse> chatProvider()
    • applyTextChatParameters

      protected static void applyTextChatParameters(WatsonxChatRequestParameters.Builder target, dev.langchain4j.model.watsonx.WatsonxTextChatBase.Builder<?> builder)
      Merges into target the builder values and the default request parameters that both services accept.
      Parameters:
      target - the parameters builder to fill
      builder - the model builder holding the values set by the caller
    • listeners

      public List<ChatModelListener> listeners()
    • defaultRequestParameters

      public ChatRequestParameters defaultRequestParameters()
    • supportedCapabilities

      public Set<Capability> supportedCapabilities()
    • provider

      public ModelProvider provider()
    • executeChat

      protected final ChatResponse executeChat(ChatRequest chatRequest)
    • executeChatStreaming

      protected final void executeChatStreaming(ChatRequest chatRequest, StreamingChatResponseHandler handler)
    • applyCommonParameters

      protected static final void applyCommonParameters(DefaultChatRequestParameters.Builder<?> target, dev.langchain4j.model.watsonx.WatsonxChatBase.Builder<?> builder)