Class WatsonxDeploymentStreamingChatModel
java.lang.Object
dev.langchain4j.model.watsonx.WatsonxDeploymentStreamingChatModel
- All Implemented Interfaces:
StreamingChatModel
A
StreamingChatModel implementation that integrates the IBM watsonx.ai Deployment with LangChain4j.
Example usage:
StreamingChatModel chatModel = WatsonxDeploymentStreamingChatModel.builder()
.baseUrl("https://...") // or use CloudRegion
.apiKey("...")
.deploymentId("...")
.maxOutputTokens(0)
.temperature(0.7)
.build();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class for constructingWatsonxDeploymentStreamingChatModelinstances with configurable parameters. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ChatRequestParametersprotected final Stringprotected final com.ibm.watsonx.ai.deployment.DeploymentServiceprotected final List<ChatModelListener> protected final booleanprotected final Set<Capability> -
Method Summary
Modifier and TypeMethodDescriptionprotected static final voidapplyCommonParameters(DefaultChatRequestParameters.Builder<?> target, dev.langchain4j.model.watsonx.WatsonxChatBase.Builder<?> builder) protected static voidapplyTextChatParameters(WatsonxChatRequestParameters.Builder target, dev.langchain4j.model.watsonx.WatsonxTextChatBase.Builder<?> builder) Merges intotargetthe builder values and the default request parameters that both services accept.protected com.ibm.watsonx.ai.deployment.DeploymentChatRequestbuildChatRequest(List<com.ibm.watsonx.ai.chat.model.ChatMessage> messages, List<com.ibm.watsonx.ai.chat.model.Tool> tools, ChatRequestParameters parameters) builder()Returns a newWatsonxDeploymentStreamingChatModel.Builderinstance.protected com.ibm.watsonx.ai.chat.ChatProvider<com.ibm.watsonx.ai.deployment.DeploymentChatRequest, com.ibm.watsonx.ai.chat.TextChatResponse> voiddoChat(ChatRequest chatRequest, StreamingChatResponseHandler handler) Provider-specific implementation ofStreamingChatModel.chat(ChatRequest, StreamingChatResponseHandler), which wraps it withChatModelListenerinvocation and failure reporting.protected final ChatResponseexecuteChat(ChatRequest chatRequest) protected final voidexecuteChatStreaming(ChatRequest chatRequest, StreamingChatResponseHandler handler) provider()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface StreamingChatModel
chat, chat, chat, chat, chat, chat, chat, chat, defaultRequestParameters, doChat, listeners, provider, supportedCapabilities
-
Field Details
-
deploymentService
protected final com.ibm.watsonx.ai.deployment.DeploymentService deploymentService -
deploymentId
-
listeners
-
defaultRequestParameters
-
supportedCapabilities
-
strictJsonSchema
protected final boolean strictJsonSchema
-
-
Method Details
-
doChat
Description copied from interface:StreamingChatModelProvider-specific implementation ofStreamingChatModel.chat(ChatRequest, StreamingChatResponseHandler), which wraps it withChatModelListenerinvocation and failure reporting.An implementation may throw a failure that it finds before the request is sent, for example an invalid request:
StreamingChatModel.chat(ChatRequest, StreamingChatResponseHandler)then reports it toStreamingChatResponseHandler.onError(Throwable). Every later failure goes tohandler.onError(...). An implementation does not need to care about what the user'sonErrorthrows: it never reaches the implementation. Core throws it fromchat(...)when it happens on the calling thread beforechat(...)returns, and logs it otherwise.- Specified by:
doChatin interfaceStreamingChatModel- Parameters:
chatRequest- the request, with the default request parameters of this model appliedhandler- the handler to send the streamed response and failures to
-
builder
Returns a newWatsonxDeploymentStreamingChatModel.Builderinstance.Example usage:
StreamingChatModel chatModel = WatsonxDeploymentStreamingChatModel.builder() .baseUrl("https://...") // or use CloudRegion .apiKey("...") .deploymentId("...") .maxOutputTokens(0) .temperature(0.7) .build();- Returns:
WatsonxDeploymentStreamingChatModel.Builderinstance.
-
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 intotargetthe builder values and the default request parameters that both services accept.- Parameters:
target- the parameters builder to fillbuilder- the model builder holding the values set by the caller
-
listeners
-
defaultRequestParameters
-
supportedCapabilities
-
provider
-
executeChat
-
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)
-