Package org.codelibs.fess.llm
Interface LlmClient
- All Known Implementing Classes:
AbstractLlmClient,GeminiLlmClient,OllamaLlmClient,OpenAiLlmClient
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 Summary
Modifier and TypeMethodDescriptionchat(LlmChatRequest request) Performs a chat completion request.detectIntent(String userMessage) Detects the intent of a user message.Evaluates search results for relevance to the user's question.generateAnswer(String userMessage, List<Map<String, Object>> documents, List<LlmMessage> history) Generates an answer using document content (synchronous version for non-enhanced flow).voidgenerateDirectAnswer(String userMessage, List<LlmMessage> history, LlmStreamCallback callback) Generates a direct answer without document search.voidgenerateDocumentNotFoundResponse(String userMessage, String documentUrl, List<LlmMessage> history, LlmStreamCallback callback) Generates a response when the specified document URL is not found.voidgenerateFaqAnswerResponse(String userMessage, List<Map<String, Object>> documents, List<LlmMessage> history, LlmStreamCallback callback) Generates an FAQ answer using document content (streaming).voidgenerateNoResultsResponse(String userMessage, List<LlmMessage> history, LlmStreamCallback callback) Generates a response when no relevant documents are found.voidgenerateSummaryResponse(String userMessage, List<Map<String, Object>> documents, List<LlmMessage> history, LlmStreamCallback callback) Generates a summary of the specified documents.voidgenerateUnclearIntentResponse(String userMessage, List<LlmMessage> history, LlmStreamCallback callback) Generates a response asking user for clarification when intent is unclear.getName()Returns the name of this LLM client.booleanChecks if this LLM client is available and properly configured.voidstreamChat(LlmChatRequest request, LlmStreamCallback callback) Performs a streaming chat completion request.voidstreamGenerateAnswer(String userMessage, List<Map<String, Object>> documents, List<LlmMessage> history, LlmStreamCallback callback) Generates an answer using document content (streaming version for enhanced flow).
-
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
Performs a streaming chat completion request. The callback is invoked for each chunk of the response.- Parameters:
request- the chat request containing messages and parameterscallback- 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
Detects the intent of a user message.- Parameters:
userMessage- the user's message- 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 messagequery- the search query usedsearchResults- 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 messagedocuments- the documents with contenthistory- the conversation history- Returns:
- the chat response
-
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 messagedocuments- the documents with contenthistory- the conversation historycallback- 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 messagehistory- the conversation historycallback- 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 messagehistory- the conversation historycallback- 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 messagedocumentUrl- the URL that was not foundhistory- the conversation historycallback- 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 messagedocuments- the documents to summarizehistory- the conversation historycallback- 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 messagedocuments- the documents with contenthistory- the conversation historycallback- the streaming callback
-
generateDirectAnswer
Generates a direct answer without document search.- Parameters:
userMessage- the user's messagehistory- the conversation historycallback- the streaming callback
-