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 Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Represents a request to the LLM containing all necessary context, configuration, and tools.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    reactor.core.publisher.Flux<String>
    Streams a response from the LLM based on the provided request.
  • Method Details

    • stream

      reactor.core.publisher.Flux<String> stream(LLMProvider.LLMRequest request)
      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, not null
      Returns:
      a Flux stream that emits response tokens as strings, never null
      Throws:
      NullPointerException - if request is null
    • 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, not null
      attachmentsByMessageId - a map from ChatMessage.messageId() to the list of attachments for that message, not null
      Throws:
      NullPointerException - if any argument is null
      UnsupportedOperationException - if this provider does not support chat history restoration