Interface LLMProvider
- All Known Implementing Classes:
LangChain4JLLMProvider,SpringAILLMProvider
public interface LLMProvider
Framework-agnostic interface for Large Language Model (LLM) providers. This
interface enables AI-powered components to communicate with LLMs without
being tied to a specific implementation. Implementations are responsible for
managing conversation memory, handling streaming responses, processing
vendor-specific tool annotations, and handling file attachments.
- Author:
- Vaadin Ltd.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceRepresents a request to the LLM containing all necessary context, configuration, and tools. -
Method Summary
Modifier and TypeMethodDescriptiondefault voidsetHistory(List<ChatMessage> history, Map<String, List<AIAttachment>> attachmentsByMessageId) Restores the provider's conversation memory from a list of chat messages with their associated attachments.reactor.core.publisher.Flux<String> stream(LLMProvider.LLMRequest request) Streams a response from the LLM based on the provided request.
-
Method Details
-
stream
Streams a response from the LLM based on the provided request. This method returns a reactive stream that emits response tokens as they become available from the LLM. The provider manages conversation history internally, so each call to this method adds to the ongoing conversation context.- Parameters:
request- the LLM request containing user message, system prompt, attachments, and tools, notnull- Returns:
- a Flux stream that emits response tokens as strings, never
null - Throws:
NullPointerException- if request isnull
-
setHistory
default void setHistory(List<ChatMessage> history, Map<String, List<AIAttachment>> attachmentsByMessageId) Restores the provider's conversation memory from a list of chat messages with their associated attachments. Any existing memory is cleared before the new history is applied.Providers that support setting chat history should override this method.
This method must not be called while a streaming response is in progress.
- Parameters:
history- the list of chat messages to restore, notnullattachmentsByMessageId- a map fromChatMessage.messageId()to the list of attachments for that message, notnull- Throws:
NullPointerException- if any argument isnullUnsupportedOperationException- if this provider does not support chat history restoration
-