Interface ChatModel
- All Known Implementing Classes:
AnthropicChatModel, AzureOpenAiChatModel, BedrockChatModel, DisabledChatModel, GoogleAiGeminiChatModel, GoogleGenAiChatModel, GPULlama3ChatModel, HuggingFaceChatModel, JlamaChatModel, LocalAiChatModel, MistralAiChatModel, OllamaChatModel, OpenAiChatModel, OpenAiOfficialChatModel, OpenAiOfficialResponsesChatModel, OpenAiResponsesChatModel, VertexAiAnthropicChatModel, VertexAiChatModel, VertexAiGeminiChatModel, WatsonxChatModel, WatsonxDeploymentChatModel, WatsonxGatewayChatModel, WorkersAiChatModel
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault ChatResponsechat(ChatMessage... messages) default ChatResponsechat(ChatRequest chatRequest) This is the main API to interact with the chat model.default ChatResponsechat(ChatRequest chatRequest, ChatRequestOptions options) Sends a chat request with additional invocation options.default Stringdefault ChatResponsechat(List<ChatMessage> messages) default CompletableFuture<ChatResponse> chatAsync(ChatMessage... messages) Non-blocking convenience counterpart ofchat(ChatMessage...).default CompletableFuture<ChatResponse> chatAsync(ChatRequest chatRequest) Non-blocking counterpart ofchat(ChatRequest): sends a chat request and returns aCompletableFuturethat completes with theChatResponseonce the model responds.default CompletableFuture<ChatResponse> chatAsync(ChatRequest chatRequest, ChatRequestOptions options) Sends a non-blocking chat request with additional invocation options.default CompletableFuture<String> Non-blocking convenience counterpart ofchat(String): completes with the text of the model's response.default CompletableFuture<ChatResponse> chatAsync(List<ChatMessage> messages) Non-blocking convenience counterpart ofchat(List).default ChatRequestParametersdefault ChatResponsedoChat(ChatRequest chatRequest) default CompletableFuture<ChatResponse> doChatAsync(ChatRequest chatRequest) SPI hook for a genuinely non-blocking chat implementation, invoked bychatAsync(ChatRequest).default List<ChatModelListener> default ModelProviderprovider()default Set<Capability>
-
Method Details
-
chat
This is the main API to interact with the chat model.- Parameters:
chatRequest- aChatRequest, containing all the inputs to the LLM- Returns:
- a
ChatResponse, containing all the outputs from the LLM
-
chat
Sends a chat request with additional invocation options.- Parameters:
chatRequest- aChatRequest, containing all the inputs to the LLMoptions- aChatRequestOptionscarrying listener attributes and other per-call metadata- Returns:
- a
ChatResponse, containing all the outputs from the LLM - Since:
- 1.13.0
-
doChat
-
chatAsync
Non-blocking counterpart ofchat(ChatRequest): sends a chat request and returns aCompletableFuturethat completes with theChatResponseonce the model responds.Unlike
chat(ChatRequest), this method does not block the calling thread. Operational failures (including unsupported-parameter validation) are delivered through the returned future (completed exceptionally), not thrown synchronously — the async analog of how the publisher API signals errors viaonError.Registered
ChatModelListeners are invoked:onRequestwhen the request is initiated, thenonResponseonce the response is available, oronErroron failure.Threading. The returned future is completed on the model's own thread - for HTTP models, the transport's I/O worker that reads the response (the JDK HTTP client's
HttpClient-*workers). A continuation attached without an explicit executor (thenApply,thenAccept, ...) therefore runs on that thread, where blocking is as harmful as blocking in aChatModelListenercallback: it stalls the worker and, under concurrency, degrades throughput for every in-flight call. Keep continuations non-blocking, or hand blocking work to your ownExecutorvia the*Asyncvariants (thenApplyAsync(fn, executor)).- Parameters:
chatRequest- aChatRequest, containing all the inputs to the LLM- Returns:
- a
CompletableFutureof theChatResponse - Since:
- 1.20.0
-
chatAsync
@Experimental default CompletableFuture<ChatResponse> chatAsync(ChatRequest chatRequest, ChatRequestOptions options) Sends a non-blocking chat request with additional invocation options.- Parameters:
chatRequest- aChatRequest, containing all the inputs to the LLMoptions- aChatRequestOptionscarrying listener attributes and other per-call metadata- Returns:
- a
CompletableFutureof theChatResponse - Since:
- 1.20.0
- See Also:
-
doChatAsync
SPI hook for a genuinely non-blocking chat implementation, invoked bychatAsync(ChatRequest).The default returns a failed future carrying
AsyncNotSupportedExceptionto signal that this model has no native asynchronous implementation. Callers on the asynchronous and reactive path (for example the non-blocking RAG stages) detect this and either offload the blockingdoChat(ChatRequest)or fail loudly with an actionable message. A model backed by remote HTTP I/O overrides this with a genuinely asynchronous call (no thread parked).- Parameters:
chatRequest- aChatRequest, containing all the inputs to the LLM- Returns:
- a
CompletableFutureof theChatResponse - Since:
- 1.20.0
-
defaultRequestParameters
-
listeners
-
provider
-
chat
-
chat
-
chat
-
chatAsync
Non-blocking convenience counterpart ofchat(String): completes with the text of the model's response.- Since:
- 1.20.0
-
chatAsync
Non-blocking convenience counterpart ofchat(ChatMessage...).- Since:
- 1.20.0
-
chatAsync
Non-blocking convenience counterpart ofchat(List).- Since:
- 1.20.0
-
supportedCapabilities
-