Class WatsonxTokenCountEstimator.Builder

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

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

    • baseUrl

      protected URI baseUrl
    • version

      protected String version
    • apiKey

      protected String apiKey
    • projectId

      protected String projectId
    • spaceId

      protected String spaceId
    • 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

    • modelName

      public WatsonxTokenCountEstimator.Builder modelName(String modelName)
      Sets the watsonx.ai model ID used for token counting, e.g. "ibm/granite-3-8b-instruct".
      Parameters:
      modelName - the model ID
      Returns:
      this
    • projectId

      public WatsonxTokenCountEstimator.Builder projectId(String projectId)
      Sets the IBM Cloud project ID that owns the watsonx.ai resources. Exactly one of projectId or spaceId must be set.
      Parameters:
      projectId - the IBM Cloud project ID
      Returns:
      this
    • spaceId

      public WatsonxTokenCountEstimator.Builder spaceId(String spaceId)
      Sets the IBM Cloud deployment space ID. Exactly one of projectId or spaceId must be set.
      Parameters:
      spaceId - the IBM Cloud deployment space ID
      Returns:
      this
    • build

    • baseUrl

      public WatsonxTokenCountEstimator.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 WatsonxTokenCountEstimator.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 WatsonxTokenCountEstimator.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 WatsonxTokenCountEstimator.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 WatsonxTokenCountEstimator.Builder timeout(Duration timeout)
      Sets the HTTP request timeout. Defaults to 60 seconds.
      Parameters:
      timeout - the request timeout
      Returns:
      this
    • authenticator

      public WatsonxTokenCountEstimator.Builder authenticator(com.ibm.watsonx.ai.core.auth.Authenticator authenticator)
      Sets a custom Authenticator for generating bearer tokens. Use this instead of apiKey when you need a non-standard authentication flow.
      Parameters:
      authenticator - the authenticator
      Returns:
      this
    • httpClient

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

      public WatsonxTokenCountEstimator.Builder verifySsl(boolean verifySsl)
      Controls whether SSL certificate verification is performed. Defaults to true. Set to false only in non-production environments.
      Parameters:
      verifySsl - false to disable SSL verification
      Returns:
      this