Class WatsonxDeploymentChatModel.Builder

java.lang.Object
dev.langchain4j.model.watsonx.WatsonxDeploymentChatModel.Builder
Enclosing class:
WatsonxDeploymentChatModel

public static class WatsonxDeploymentChatModel.Builder extends Object
Builder class for constructing WatsonxDeploymentChatModel instances with configurable parameters.
  • Field Details

    • deploymentId

      protected String deploymentId
    • thinking

      protected com.ibm.watsonx.ai.chat.model.Thinking thinking
    • guidedChoice

      protected Set<String> guidedChoice
    • guidedRegex

      protected String guidedRegex
    • guidedGrammar

      protected String guidedGrammar
    • repetitionPenalty

      protected Double repetitionPenalty
    • lengthPenalty

      protected Double lengthPenalty
    • modelName

      protected String modelName
    • temperature

      protected Double temperature
    • topP

      protected Double topP
    • frequencyPenalty

      protected Double frequencyPenalty
    • presencePenalty

      protected Double presencePenalty
    • maxOutputTokens

      protected Integer maxOutputTokens
    • stopSequences

      protected List<String> stopSequences
    • toolChoice

      protected ToolChoice toolChoice
    • responseFormat

      protected ResponseFormat responseFormat
    • strictJsonSchema

      protected Boolean strictJsonSchema
    • toolSpecifications

      protected List<ToolSpecification> toolSpecifications
    • listeners

      protected List<ChatModelListener> listeners
    • defaultRequestParameters

      protected ChatRequestParameters defaultRequestParameters
    • supportedCapabilities

      protected Set<Capability> supportedCapabilities
    • logitBias

      protected Map<String,Integer> logitBias
    • logprobs

      protected Boolean logprobs
    • topLogprobs

      protected Integer topLogprobs
    • seed

      protected Integer seed
    • toolChoiceName

      protected String toolChoiceName
    • baseUrl

      protected URI baseUrl
    • version

      protected String version
    • apiKey

      protected String apiKey
    • logRequests

      protected Boolean logRequests
    • logResponses

      protected Boolean logResponses
    • timeout

      protected Duration timeout
    • authenticator

      protected com.ibm.watsonx.ai.core.auth.Authenticator authenticator
    • httpClient

      protected HttpClient httpClient
    • verifySsl

      protected boolean verifySsl
  • Method Details

    • build

    • deploymentId

      public WatsonxDeploymentChatModel.Builder deploymentId(String deploymentId)
      Sets the id of the on-demand model to call.
      Parameters:
      deploymentId - the deployment id
      Returns:
      this
    • thinking

      public WatsonxDeploymentChatModel.Builder thinking(boolean enabled)
      Enables or disables thinking.
      Parameters:
      enabled - true to enable thinking
      Returns:
      this
    • thinking

      public WatsonxDeploymentChatModel.Builder thinking(com.ibm.watsonx.ai.chat.model.ExtractionTags tags)
      Configures thinking with custom extraction tags for parsing the thinking block.
      Parameters:
      tags - the extraction tags
      Returns:
      this
    • thinking

      public WatsonxDeploymentChatModel.Builder thinking(com.ibm.watsonx.ai.chat.model.ThinkingEffort thinkingEffort)
      Configures thinking with a specific effort level.
      Parameters:
      thinkingEffort - the thinking effort level
      Returns:
      this
    • thinking

      public WatsonxDeploymentChatModel.Builder thinking(com.ibm.watsonx.ai.chat.model.Thinking thinking)
      Sets a fully configured Thinking object for thinking.
      Parameters:
      thinking - the thinking configuration
      Returns:
      this
    • guidedChoice

      public WatsonxDeploymentChatModel.Builder guidedChoice(String... guidedChoice)
      Constrains the model output to one of the given string choices (guided decoding).
      Parameters:
      guidedChoice - the allowed output values
      Returns:
      this
    • guidedChoice

      public WatsonxDeploymentChatModel.Builder guidedChoice(Set<String> guidedChoices)
      Constrains the model output to one of the given string choices (guided decoding).
      Parameters:
      guidedChoices - the set of allowed output values
      Returns:
      this
    • guidedRegex

      public WatsonxDeploymentChatModel.Builder guidedRegex(String guidedRegex)
      Constrains the model output to match the given regular expression (guided decoding).
      Parameters:
      guidedRegex - the regular expression pattern
      Returns:
      this
    • guidedGrammar

      public WatsonxDeploymentChatModel.Builder guidedGrammar(String guidedGrammar)
      Constrains the model output to conform to the given EBNF grammar (guided decoding).
      Parameters:
      guidedGrammar - the EBNF grammar string
      Returns:
      this
    • repetitionPenalty

      public WatsonxDeploymentChatModel.Builder repetitionPenalty(Double repetitionPenalty)
      Sets the repetition penalty. Values greater than 1.0 discourage repetition; values less than 1.0 encourage it.
      Parameters:
      repetitionPenalty - the repetition penalty
      Returns:
      this
    • lengthPenalty

      public WatsonxDeploymentChatModel.Builder lengthPenalty(Double lengthPenalty)
      Sets the length penalty applied to the sequence score during beam search. Values greater than 1.0 favor longer sequences.
      Parameters:
      lengthPenalty - the length penalty
      Returns:
      this
    • temperature

      public WatsonxDeploymentChatModel.Builder temperature(Double temperature)
      Sets the sampling temperature in the range [0.0, 2.0].
      Parameters:
      temperature - the sampling temperature
      Returns:
      this
    • topP

      Sets the nucleus sampling probability in the range (0.0, 1.0]
      Parameters:
      topP - the nucleus sampling threshold
      Returns:
      this
    • frequencyPenalty

      public WatsonxDeploymentChatModel.Builder frequencyPenalty(Double frequencyPenalty)
      Sets the frequency penalty in the range [-2.0, 2.0].
      Parameters:
      frequencyPenalty - the frequency penalty
      Returns:
      this
    • presencePenalty

      public WatsonxDeploymentChatModel.Builder presencePenalty(Double presencePenalty)
      Sets the presence penalty in the range [-2.0, 2.0].
      Parameters:
      presencePenalty - the presence penalty
      Returns:
      this
    • maxOutputTokens

      public WatsonxDeploymentChatModel.Builder maxOutputTokens(Integer maxOutputTokens)
      Sets the maximum number of tokens to generate in the response.
      Parameters:
      maxOutputTokens - the maximum number of output tokens
      Returns:
      this
    • stopSequences

      public WatsonxDeploymentChatModel.Builder stopSequences(List<String> stopSequences)
      Sets the sequences that will stop generation when encountered.
      Parameters:
      stopSequences - the stop sequences
      Returns:
      this
    • stopSequences

      public WatsonxDeploymentChatModel.Builder stopSequences(String... stopSequences)
      Sets the sequences that will stop generation when encountered.
      Parameters:
      stopSequences - the stop sequences
      Returns:
      this
    • toolChoice

      public WatsonxDeploymentChatModel.Builder toolChoice(ToolChoice toolChoice)
      Sets how the model selects tools. Controls whether tool use is automatic, forced, or disabled.
      Parameters:
      toolChoice - the tool choice mode
      Returns:
      this
    • responseFormat

      public WatsonxDeploymentChatModel.Builder responseFormat(ResponseFormat responseFormat)
      Sets the response format to control structured output, e.g. JSON mode.
      Parameters:
      responseFormat - the response format
      Returns:
      this
    • strictJsonSchema

      public WatsonxDeploymentChatModel.Builder strictJsonSchema(Boolean strictJsonSchema)
      Enables the strict mode for the JSON Schema used by structured outputs. Defaults to true.

      In strict mode the model is required to adhere to the schema, every property is marked as required and additionalProperties is set to false. Set it to false to let the model treat the schema as a hint instead of a constraint.

      Parameters:
      strictJsonSchema - true to enable the strict mode
      Returns:
      this
    • toolSpecifications

      public WatsonxDeploymentChatModel.Builder toolSpecifications(List<ToolSpecification> toolSpecifications)
      Sets the tool definitions available to the model for function calling.
      Parameters:
      toolSpecifications - the list of tool specifications
      Returns:
      this
    • toolSpecifications

      public WatsonxDeploymentChatModel.Builder toolSpecifications(ToolSpecification... toolSpecifications)
      Sets the tool definitions available to the model for function calling.
      Parameters:
      toolSpecifications - the tool specifications
      Returns:
      this
    • listeners

      Sets the list of ChatModelListener instances for observing chat model interactions.
      Parameters:
      listeners - the listeners to register
      Returns:
      this
    • defaultRequestParameters

      public WatsonxDeploymentChatModel.Builder defaultRequestParameters(ChatRequestParameters defaultRequestParameters)
      Sets default request parameters that are merged into every chat request.
      Parameters:
      defaultRequestParameters - the default request parameters
      Returns:
      this
    • supportedCapabilities

      public WatsonxDeploymentChatModel.Builder supportedCapabilities(Set<Capability> supportedCapabilities)
      Declares the capabilities supported by this model instance.
      Parameters:
      supportedCapabilities - the set of supported capabilities
      Returns:
      this
    • supportedCapabilities

      public WatsonxDeploymentChatModel.Builder supportedCapabilities(Capability... supportedCapabilities)
      Declares the capabilities supported by this model instance.
      Parameters:
      supportedCapabilities - the supported capabilities
      Returns:
      this
    • logitBias

      public WatsonxDeploymentChatModel.Builder logitBias(Map<String,Integer> logitBias)
      Sets per-token logit biases to increase or decrease the likelihood of specific tokens. Keys are token IDs; values are bias offsets in the range [-100, 100].
      Parameters:
      logitBias - the logit bias map
      Returns:
      this
    • logprobs

      public WatsonxDeploymentChatModel.Builder logprobs(Boolean logprobs)
      Enables returning log probabilities of the output tokens.
      Parameters:
      logprobs - true to include log probabilities in the response
      Returns:
      this
    • topLogprobs

      public WatsonxDeploymentChatModel.Builder topLogprobs(Integer topLogprobs)
      Sets the number of most likely tokens to return log probabilities for at each position. Requires logprobs to be true. Value must be between 0 and 20.
      Parameters:
      topLogprobs - the number of top log probabilities to return
      Returns:
      this
    • seed

      Sets the random seed for deterministic sampling. Using the same seed and parameters should produce the same output across calls.
      Parameters:
      seed - the random seed
      Returns:
      this
    • toolChoiceName

      public WatsonxDeploymentChatModel.Builder toolChoiceName(String toolChoiceName)
      Sets the name of the specific tool to force when toolChoice is set to force a particular tool.
      Parameters:
      toolChoiceName - the tool name to force
      Returns:
      this
    • baseUrl

      public WatsonxDeploymentChatModel.Builder baseUrl(com.ibm.watsonx.ai.CloudRegion baseUrl)
      Sets the IBM watsonx.ai endpoint from a predefined CloudRegion.
      Parameters:
      baseUrl - the IBM Cloud region whose ML endpoint will be used
      Returns:
      this
    • baseUrl

      Sets the base URL of the IBM watsonx.ai API.
      Parameters:
      url - the base URL string, e.g. "https://us-south.ml.cloud.ibm.com"
      Returns:
      this
    • baseUrl

      Sets the base URL of the IBM watsonx.ai API as a URI.
      Parameters:
      url - the base URL URI
      Returns:
      this
    • version

      public WatsonxDeploymentChatModel.Builder version(String version)
      Sets the watsonx.ai API version date, e.g. "2024-05-31".
      Parameters:
      version - the API version date string
      Returns:
      this
    • apiKey

      Sets the IBM Cloud API key used to generate IAM access tokens for authentication.
      Parameters:
      apiKey - the IBM Cloud API key
      Returns:
      this
    • logRequests

      public WatsonxDeploymentChatModel.Builder logRequests(Boolean logRequests)
      Enables debug logging of request bodies sent to the watsonx.ai API.
      Parameters:
      logRequests - true to enable request logging
      Returns:
      this
    • logResponses

      public WatsonxDeploymentChatModel.Builder logResponses(Boolean logResponses)
      Enables debug logging of response bodies received from the watsonx.ai API.
      Parameters:
      logResponses - true to enable response logging
      Returns:
      this
    • timeout

      public WatsonxDeploymentChatModel.Builder timeout(Duration timeout)
      Sets the HTTP request timeout. Defaults to 60 seconds.
      Parameters:
      timeout - the request timeout
      Returns:
      this
    • authenticator

      public WatsonxDeploymentChatModel.Builder authenticator(com.ibm.watsonx.ai.core.auth.Authenticator authenticator)
      Sets a custom Authenticator for generating bearer tokens.
      Parameters:
      authenticator - the authenticator
      Returns:
      this
    • httpClient

      public WatsonxDeploymentChatModel.Builder httpClient(HttpClient httpClient)
      Sets a custom HttpClient to use for all API calls.
      Parameters:
      httpClient - the HTTP client
      Returns:
      this
    • verifySsl

      public WatsonxDeploymentChatModel.Builder verifySsl(boolean verifySsl)
      Controls whether SSL certificate verification is performed. Defaults to true.
      Parameters:
      verifySsl - false to disable SSL verification
      Returns:
      this