Interface LlmClient

All Known Implementing Classes:
AbstractLlmClient

public interface LlmClient
Interface for LLM (Large Language Model) clients. Implementations provide integration with different LLM providers such as Ollama, OpenAI, and Google Gemini. In addition to low-level chat operations, this interface defines high-level RAG workflow methods that allow each provider to optimize prompt construction, parameter tuning, and response parsing.
  • Method Details

    • chat

      Performs a chat completion request.
      Parameters:
      request - the chat request containing messages and parameters
      Returns:
      the chat response from the LLM
      Throws:
      LlmException - if an error occurs during the request
    • streamChat

      void streamChat(LlmChatRequest request, LlmStreamCallback callback)
      Performs a streaming chat completion request. The callback is invoked for each chunk of the response.
      Parameters:
      request - the chat request containing messages and parameters
      callback - the callback to receive streaming chunks
      Throws:
      LlmException - if an error occurs during the request
    • getName

      String getName()
      Returns the name of this LLM client.
      Returns:
      the client name (e.g., "ollama", "openai", "gemini")
    • isAvailable

      boolean isAvailable()
      Checks if this LLM client is available and properly configured.
      Returns:
      true if the client is available, false otherwise
    • detectIntent

      IntentDetectionResult detectIntent(String userMessage)
      Detects the intent of a user message.
      Parameters:
      userMessage - the user's message
      Returns:
      the detected intent with extracted keywords
    • detectIntent

      default IntentDetectionResult detectIntent(String userMessage, List<LlmMessage> history)
      Detects the intent of a user message with conversation history context.
      Parameters:
      userMessage - the user's message
      history - the conversation history for context
      Returns:
      the detected intent with extracted keywords
    • evaluateResults

      RelevanceEvaluationResult evaluateResults(String userMessage, String query, List<Map<String,Object>> searchResults)
      Evaluates search results for relevance to the user's question.
      Parameters:
      userMessage - the original user message
      query - the search query used
      searchResults - the search results to evaluate
      Returns:
      evaluation result with relevant document IDs
    • generateAnswer

      LlmChatResponse generateAnswer(String userMessage, List<Map<String,Object>> documents, List<LlmMessage> history)
      Generates an answer using document content (synchronous version for non-enhanced flow).
      Parameters:
      userMessage - the user's message
      documents - the documents with content
      history - the conversation history
      Returns:
      the chat response
    • regenerateQuery

      String regenerateQuery(String userMessage, String failedQuery, String failureReason, List<LlmMessage> history)
      Regenerates a search query when the previous query failed to produce relevant results.
      Parameters:
      userMessage - the user's original message
      failedQuery - the query that failed
      failureReason - the reason for failure ("no_results" or "no_relevant_results")
      history - the conversation history
      Returns:
      a new query string, or the userMessage if regeneration fails
    • streamGenerateAnswer

      void streamGenerateAnswer(String userMessage, List<Map<String,Object>> documents, List<LlmMessage> history, LlmStreamCallback callback)
      Generates an answer using document content (streaming version for enhanced flow).
      Parameters:
      userMessage - the user's message
      documents - the documents with content
      history - the conversation history
      callback - the streaming callback
    • generateUnclearIntentResponse

      void generateUnclearIntentResponse(String userMessage, List<LlmMessage> history, LlmStreamCallback callback)
      Generates a response asking user for clarification when intent is unclear.
      Parameters:
      userMessage - the user's message
      history - the conversation history
      callback - the streaming callback
    • generateNoResultsResponse

      void generateNoResultsResponse(String userMessage, List<LlmMessage> history, LlmStreamCallback callback)
      Generates a response when no relevant documents are found.
      Parameters:
      userMessage - the user's message
      history - the conversation history
      callback - the streaming callback
    • generateDocumentNotFoundResponse

      void generateDocumentNotFoundResponse(String userMessage, String documentUrl, List<LlmMessage> history, LlmStreamCallback callback)
      Generates a response when the specified document URL is not found.
      Parameters:
      userMessage - the user's message
      documentUrl - the URL that was not found
      history - the conversation history
      callback - the streaming callback
    • generateSummaryResponse

      void generateSummaryResponse(String userMessage, List<Map<String,Object>> documents, List<LlmMessage> history, LlmStreamCallback callback)
      Generates a summary of the specified documents.
      Parameters:
      userMessage - the user's message
      documents - the documents to summarize
      history - the conversation history
      callback - the streaming callback
    • generateFaqAnswerResponse

      void generateFaqAnswerResponse(String userMessage, List<Map<String,Object>> documents, List<LlmMessage> history, LlmStreamCallback callback)
      Generates an FAQ answer using document content (streaming). Uses a prompt optimized for direct, concise FAQ-style answers.
      Parameters:
      userMessage - the user's message
      documents - the documents with content
      history - the conversation history
      callback - the streaming callback
    • generateDirectAnswer

      void generateDirectAnswer(String userMessage, List<LlmMessage> history, LlmStreamCallback callback)
      Generates a direct answer without document search.
      Parameters:
      userMessage - the user's message
      history - the conversation history
      callback - the streaming callback
    • getHistoryAssistantMaxChars

      default int getHistoryAssistantMaxChars()
      Gets the maximum characters for assistant message in history.
      Returns:
      the maximum characters
    • getHistoryAssistantSummaryMaxChars

      default int getHistoryAssistantSummaryMaxChars()
      Gets the maximum characters for assistant summary in history.
      Returns:
      the maximum characters