Class WatsonxGatewayStreamingChatModel
java.lang.Object
dev.langchain4j.model.watsonx.WatsonxGatewayStreamingChatModel
- All Implemented Interfaces:
StreamingChatModel
A
StreamingChatModel implementation that integrates the IBM watsonx.ai Model Gateway with LangChain4j.
Example usage:
StreamingChatModel chatModel = WatsonxGatewayStreamingChatModel.builder()
.baseUrl("https://...") // or use CloudRegion
.apiKey("...")
.modelName("gpt-4o")
.maxOutputTokens(0)
.temperature(0.7)
.build();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class for constructingWatsonxGatewayStreamingChatModelinstances with configurable parameters. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ChatRequestParametersprotected final List<ChatModelListener> protected final com.ibm.watsonx.ai.gateway.chat.ModelGatewayChatServiceprotected final booleanprotected final Set<Capability> -
Method Summary
Modifier and TypeMethodDescriptionprotected static final voidapplyCommonParameters(DefaultChatRequestParameters.Builder<?> target, dev.langchain4j.model.watsonx.WatsonxChatBase.Builder<?> builder) protected com.ibm.watsonx.ai.gateway.chat.ModelGatewayChatRequestbuildChatRequest(List<com.ibm.watsonx.ai.chat.model.ChatMessage> messages, List<com.ibm.watsonx.ai.chat.model.Tool> tools, ChatRequestParameters parameters) builder()Returns a newWatsonxGatewayStreamingChatModel.Builderinstance.protected com.ibm.watsonx.ai.chat.ChatProvider<com.ibm.watsonx.ai.gateway.chat.ModelGatewayChatRequest, com.ibm.watsonx.ai.gateway.chat.ModelGatewayChatResponse> 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
-
modelGatewayChatService
protected final com.ibm.watsonx.ai.gateway.chat.ModelGatewayChatService modelGatewayChatService -
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 newWatsonxGatewayStreamingChatModel.Builderinstance.Example usage:
StreamingChatModel chatModel = WatsonxGatewayStreamingChatModel.builder() .baseUrl("https://...") // or use CloudRegion .apiKey("...") .modelName("gpt-4o") .maxOutputTokens(0) .temperature(0.7) .build();- Returns:
WatsonxGatewayStreamingChatModel.Builderinstance.
-
chatProvider
protected com.ibm.watsonx.ai.chat.ChatProvider<com.ibm.watsonx.ai.gateway.chat.ModelGatewayChatRequest, com.ibm.watsonx.ai.gateway.chat.ModelGatewayChatResponse> chatProvider() -
buildChatRequest
protected com.ibm.watsonx.ai.gateway.chat.ModelGatewayChatRequest buildChatRequest(List<com.ibm.watsonx.ai.chat.model.ChatMessage> messages, List<com.ibm.watsonx.ai.chat.model.Tool> tools, ChatRequestParameters parameters) -
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)
-