Class WatsonxDeploymentStreamingChatModel.Builder
java.lang.Object
dev.langchain4j.model.watsonx.WatsonxDeploymentStreamingChatModel.Builder
- Enclosing class:
WatsonxDeploymentStreamingChatModel
Builder class for constructing
WatsonxDeploymentStreamingChatModel instances with configurable parameters.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected com.ibm.watsonx.ai.core.auth.Authenticatorprotected URIprotected ChatRequestParametersprotected Stringprotected Doubleprotected Stringprotected Stringprotected HttpClientprotected Doubleprotected List<ChatModelListener> protected Booleanprotected Booleanprotected Booleanprotected Integerprotected Stringprotected Doubleprotected Doubleprotected ResponseFormatprotected Integerprotected Booleanprotected Set<Capability> protected Doubleprotected com.ibm.watsonx.ai.chat.model.Thinkingprotected Durationprotected ToolChoiceprotected Stringprotected List<ToolSpecification> protected Integerprotected Doubleprotected booleanprotected String -
Method Summary
Modifier and TypeMethodDescriptionSets the IBM Cloud API key used to generate IAM access tokens for authentication.authenticator(com.ibm.watsonx.ai.core.auth.Authenticator authenticator) Sets a customAuthenticatorfor generating bearer tokens.baseUrl(com.ibm.watsonx.ai.CloudRegion baseUrl) Sets the IBM watsonx.ai endpoint from a predefinedCloudRegion.Sets the base URL of the IBM watsonx.ai API.Sets the base URL of the IBM watsonx.ai API as aURI.build()defaultRequestParameters(ChatRequestParameters defaultRequestParameters) Sets default request parameters that are merged into every chat request.deploymentId(String deploymentId) Sets the id of the on-demand model to call.frequencyPenalty(Double frequencyPenalty) Sets the frequency penalty in the range[-2.0, 2.0].guidedChoice(String... guidedChoice) Constrains the model output to one of the given string choices (guided decoding).guidedChoice(Set<String> guidedChoices) Constrains the model output to one of the given string choices (guided decoding).guidedGrammar(String guidedGrammar) Constrains the model output to conform to the given EBNF grammar (guided decoding).guidedRegex(String guidedRegex) Constrains the model output to match the given regular expression (guided decoding).httpClient(HttpClient httpClient) Sets a customHttpClientto use for all API calls.lengthPenalty(Double lengthPenalty) Sets the length penalty applied to the sequence score during beam search.listeners(List<ChatModelListener> listeners) Sets the list ofChatModelListenerinstances for observing chat model interactions.Sets per-token logit biases to increase or decrease the likelihood of specific tokens.Enables returning log probabilities of the output tokens.logRequests(Boolean logRequests) Enables debug logging of request bodies sent to the watsonx.ai API.logResponses(Boolean logResponses) Enables debug logging of response bodies received from the watsonx.ai API.maxOutputTokens(Integer maxOutputTokens) Sets the maximum number of tokens to generate in the response.presencePenalty(Double presencePenalty) Sets the presence penalty in the range[-2.0, 2.0].repetitionPenalty(Double repetitionPenalty) Sets the repetition penalty.responseFormat(ResponseFormat responseFormat) Sets the response format to control structured output, e.g.Sets the random seed for deterministic sampling.stopSequences(String... stopSequences) Sets the sequences that will stop generation when encountered.stopSequences(List<String> stopSequences) Sets the sequences that will stop generation when encountered.strictJsonSchema(Boolean strictJsonSchema) Enables the strict mode for the JSON Schema used by structured outputs.supportedCapabilities(Capability... supportedCapabilities) Declares the capabilities supported by this model instance.supportedCapabilities(Set<Capability> supportedCapabilities) Declares the capabilities supported by this model instance.temperature(Double temperature) Sets the sampling temperature in the range[0.0, 2.0].thinking(boolean enabled) Enables or disables thinking.thinking(com.ibm.watsonx.ai.chat.model.ExtractionTags tags) Configures thinking with custom extraction tags for parsing the thinking block.thinking(com.ibm.watsonx.ai.chat.model.Thinking thinking) Sets a fully configuredThinkingobject for thinking.thinking(com.ibm.watsonx.ai.chat.model.ThinkingEffort thinkingEffort) Configures thinking with a specific effort level.Sets the HTTP request timeout.toolChoice(ToolChoice toolChoice) Sets how the model selects tools.toolChoiceName(String toolChoiceName) Sets the name of the specific tool to force whentoolChoiceis set to force a particular tool.toolSpecifications(ToolSpecification... toolSpecifications) Sets the tool definitions available to the model for function calling.toolSpecifications(List<ToolSpecification> toolSpecifications) Sets the tool definitions available to the model for function calling.topLogprobs(Integer topLogprobs) Sets the number of most likely tokens to return log probabilities for at each position.Sets the nucleus sampling probability in the range(0.0, 1.0]verifySsl(boolean verifySsl) Controls whether SSL certificate verification is performed.Sets the watsonx.ai API version date, e.g.
-
Field Details
-
deploymentId
-
thinking
protected com.ibm.watsonx.ai.chat.model.Thinking thinking -
guidedChoice
-
guidedRegex
-
guidedGrammar
-
repetitionPenalty
-
lengthPenalty
-
modelName
-
temperature
-
topP
-
frequencyPenalty
-
presencePenalty
-
maxOutputTokens
-
stopSequences
-
toolChoice
-
responseFormat
-
strictJsonSchema
-
toolSpecifications
-
listeners
-
defaultRequestParameters
-
supportedCapabilities
-
logitBias
-
logprobs
-
topLogprobs
-
seed
-
toolChoiceName
-
baseUrl
-
version
-
apiKey
-
logRequests
-
logResponses
-
timeout
-
authenticator
protected com.ibm.watsonx.ai.core.auth.Authenticator authenticator -
httpClient
-
verifySsl
protected boolean verifySsl
-
-
Method Details
-
build
-
deploymentId
Sets the id of the on-demand model to call.- Parameters:
deploymentId- the deployment id- Returns:
this
-
thinking
Enables or disables thinking.- Parameters:
enabled-trueto enable thinking- Returns:
this
-
thinking
public WatsonxDeploymentStreamingChatModel.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 WatsonxDeploymentStreamingChatModel.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 WatsonxDeploymentStreamingChatModel.Builder thinking(com.ibm.watsonx.ai.chat.model.Thinking thinking) Sets a fully configuredThinkingobject for thinking.- Parameters:
thinking- the thinking configuration- Returns:
this
-
guidedChoice
Constrains the model output to one of the given string choices (guided decoding).- Parameters:
guidedChoice- the allowed output values- Returns:
this
-
guidedChoice
Constrains the model output to one of the given string choices (guided decoding).- Parameters:
guidedChoices- the set of allowed output values- Returns:
this
-
guidedRegex
Constrains the model output to match the given regular expression (guided decoding).- Parameters:
guidedRegex- the regular expression pattern- Returns:
this
-
guidedGrammar
Constrains the model output to conform to the given EBNF grammar (guided decoding).- Parameters:
guidedGrammar- the EBNF grammar string- Returns:
this
-
repetitionPenalty
Sets the repetition penalty. Values greater than1.0discourage repetition; values less than1.0encourage it.- Parameters:
repetitionPenalty- the repetition penalty- Returns:
this
-
lengthPenalty
Sets the length penalty applied to the sequence score during beam search. Values greater than1.0favor longer sequences.- Parameters:
lengthPenalty- the length penalty- Returns:
this
-
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
Sets the frequency penalty in the range[-2.0, 2.0].- Parameters:
frequencyPenalty- the frequency penalty- Returns:
this
-
presencePenalty
Sets the presence penalty in the range[-2.0, 2.0].- Parameters:
presencePenalty- the presence penalty- Returns:
this
-
maxOutputTokens
Sets the maximum number of tokens to generate in the response.- Parameters:
maxOutputTokens- the maximum number of output tokens- Returns:
this
-
stopSequences
Sets the sequences that will stop generation when encountered.- Parameters:
stopSequences- the stop sequences- Returns:
this
-
stopSequences
Sets the sequences that will stop generation when encountered.- Parameters:
stopSequences- the stop sequences- Returns:
this
-
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
Sets the response format to control structured output, e.g. JSON mode.- Parameters:
responseFormat- the response format- Returns:
this
-
strictJsonSchema
Enables the strict mode for the JSON Schema used by structured outputs. Defaults totrue.In strict mode the model is required to adhere to the schema, every property is marked as
requiredandadditionalPropertiesis set tofalse. Set it tofalseto let the model treat the schema as a hint instead of a constraint.- Parameters:
strictJsonSchema-trueto enable the strict mode- Returns:
this
-
toolSpecifications
public WatsonxDeploymentStreamingChatModel.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 WatsonxDeploymentStreamingChatModel.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 ofChatModelListenerinstances for observing chat model interactions.- Parameters:
listeners- the listeners to register- Returns:
this
-
defaultRequestParameters
public WatsonxDeploymentStreamingChatModel.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 WatsonxDeploymentStreamingChatModel.Builder supportedCapabilities(Set<Capability> supportedCapabilities) Declares the capabilities supported by this model instance.- Parameters:
supportedCapabilities- the set of supported capabilities- Returns:
this
-
supportedCapabilities
public WatsonxDeploymentStreamingChatModel.Builder supportedCapabilities(Capability... supportedCapabilities) Declares the capabilities supported by this model instance.- Parameters:
supportedCapabilities- the supported capabilities- Returns:
this
-
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
Enables returning log probabilities of the output tokens.- Parameters:
logprobs-trueto include log probabilities in the response- Returns:
this
-
topLogprobs
Sets the number of most likely tokens to return log probabilities for at each position. Requireslogprobsto betrue. 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
Sets the name of the specific tool to force whentoolChoiceis set to force a particular tool.- Parameters:
toolChoiceName- the tool name to force- Returns:
this
-
baseUrl
Sets the IBM watsonx.ai endpoint from a predefinedCloudRegion.- 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 aURI.- Parameters:
url- the base URL URI- Returns:
this
-
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
Enables debug logging of request bodies sent to the watsonx.ai API.- Parameters:
logRequests-trueto enable request logging- Returns:
this
-
logResponses
Enables debug logging of response bodies received from the watsonx.ai API.- Parameters:
logResponses-trueto enable response logging- Returns:
this
-
timeout
Sets the HTTP request timeout. Defaults to 60 seconds.- Parameters:
timeout- the request timeout- Returns:
this
-
authenticator
public WatsonxDeploymentStreamingChatModel.Builder authenticator(com.ibm.watsonx.ai.core.auth.Authenticator authenticator) Sets a customAuthenticatorfor generating bearer tokens.- Parameters:
authenticator- the authenticator- Returns:
this
-
httpClient
Sets a customHttpClientto use for all API calls.- Parameters:
httpClient- the HTTP client- Returns:
this
-
verifySsl
Controls whether SSL certificate verification is performed. Defaults totrue.- Parameters:
verifySsl-falseto disable SSL verification- Returns:
this
-