Package org.codelibs.fess.llm
Class LlmClientManager
java.lang.Object
org.codelibs.fess.llm.LlmClientManager
Manager class for coordinating LLM (Large Language Model) client operations.
This class serves as the central coordinator for LLM operations in Fess.
It manages registered LLM clients and provides access to the configured
LLM provider based on the current configuration.
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe list of registered LLM clients. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks whether LLM chat functionality is available and configured.chat(LlmChatRequest request) Performs a chat completion request using the configured LLM client.detectIntent(String userMessage) Detects the intent of a user message using the configured LLM client.detectIntent(String userMessage, List<LlmMessage> history) Detects the intent of a user message with conversation history context.Evaluates search results for relevance using the configured LLM client.generateAnswer(String userMessage, List<Map<String, Object>> documents, List<LlmMessage> history) Generates an answer using document content (synchronous).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.protected LlmClientGets the available LLM client, performing a single lookup.Gets the LLM client instance for the configured LLM type.Gets all registered LLM clients.protected StringGets the configured LLM type from the system configuration.protected booleanChecks if RAG chat feature is enabled.regenerateQuery(String userMessage, String failedQuery, String failureReason, List<LlmMessage> history) Regenerates a search query when the previous query failed.voidRegisters an LLM client with this manager.voidstreamChat(LlmChatRequest request, LlmStreamCallback callback) Performs a streaming chat completion request using the configured LLM client.voidstreamGenerateAnswer(String userMessage, List<Map<String, Object>> documents, List<LlmMessage> history, LlmStreamCallback callback) Generates an answer using document content (streaming).
-
Field Details
-
clientList
The list of registered LLM clients.
-
-
Constructor Details
-
LlmClientManager
public LlmClientManager()Default constructor.
-
-
Method Details
-
available
public boolean available()Checks whether LLM chat functionality is available and configured.- Returns:
- true if LLM chat is configured and available, false otherwise
-
getClient
Gets the LLM client instance for the configured LLM type.- Returns:
- The LLM client instance, or null if not found
-
getLlmType
Gets the configured LLM type from the system configuration.- Returns:
- The LLM type string from configuration (e.g., "ollama", "openai", "gemini")
-
isRagChatEnabled
protected boolean isRagChatEnabled()Checks if RAG chat feature is enabled.- Returns:
- true if RAG chat is enabled, false otherwise
-
getClients
Gets all registered LLM clients.- Returns:
- Array of all registered LLM clients
-
register
Registers an LLM client with this manager.- Parameters:
client- The LLM client to register
-
chat
Performs a chat completion request using the configured LLM client.- Parameters:
request- the chat request- Returns:
- the chat response
- Throws:
LlmException- if LLM is not available or an error occurs
-
streamChat
Performs a streaming chat completion request using the configured LLM client.- Parameters:
request- the chat requestcallback- the callback to receive streaming chunks- Throws:
LlmException- if LLM is not available or an error occurs
-
getAvailableClient
Gets the available LLM client, performing a single lookup.- Returns:
- the available LLM client
- Throws:
LlmException- if LLM client is not available
-
detectIntent
Detects the intent of a user message using the configured LLM client.- Parameters:
userMessage- the user's message- Returns:
- the detected intent with extracted keywords
- Throws:
LlmException- if LLM is not available
-
detectIntent
Detects the intent of a user message with conversation history context.- Parameters:
userMessage- the user's messagehistory- the conversation history for context- Returns:
- the detected intent with extracted keywords
- Throws:
LlmException- if LLM is not available
-
evaluateResults
public RelevanceEvaluationResult evaluateResults(String userMessage, String query, List<Map<String, Object>> searchResults) Evaluates search results for relevance using the configured LLM client.- Parameters:
userMessage- the original user messagequery- the search query usedsearchResults- the search results to evaluate- Returns:
- evaluation result with relevant document IDs
- Throws:
LlmException- if LLM is not available
-
generateAnswer
public LlmChatResponse generateAnswer(String userMessage, List<Map<String, Object>> documents, List<LlmMessage> history) Generates an answer using document content (synchronous).- Parameters:
userMessage- the user's messagedocuments- the documents with contenthistory- the conversation history- Returns:
- the chat response
- Throws:
LlmException- if LLM is not available
-
regenerateQuery
public String regenerateQuery(String userMessage, String failedQuery, String failureReason, List<LlmMessage> history) Regenerates a search query when the previous query failed.- Parameters:
userMessage- the user's original messagefailedQuery- the query that failedfailureReason- the reason for failurehistory- the conversation history- Returns:
- a new query string
- Throws:
LlmException- if LLM is not available
-
streamGenerateAnswer
public void streamGenerateAnswer(String userMessage, List<Map<String, Object>> documents, List<LlmMessage> history, LlmStreamCallback callback) Generates an answer using document content (streaming).- Parameters:
userMessage- the user's messagedocuments- the documents with contenthistory- the conversation historycallback- the streaming callback- Throws:
LlmException- if LLM is not available
-
generateUnclearIntentResponse
public void generateUnclearIntentResponse(String userMessage, List<LlmMessage> history, LlmStreamCallback callback) Generates a response asking user for clarification.- Parameters:
userMessage- the user's messagehistory- the conversation historycallback- the streaming callback- Throws:
LlmException- if LLM is not available
-
generateNoResultsResponse
public 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- Throws:
LlmException- if LLM is not available
-
generateDocumentNotFoundResponse
public 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- Throws:
LlmException- if LLM is not available
-
generateSummaryResponse
public 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- Throws:
LlmException- if LLM is not available
-
generateFaqAnswerResponse
public void generateFaqAnswerResponse(String userMessage, List<Map<String, Object>> documents, List<LlmMessage> history, LlmStreamCallback callback) Generates an FAQ answer using document content (streaming).- Parameters:
userMessage- the user's messagedocuments- the documents with contenthistory- the conversation historycallback- the streaming callback- Throws:
LlmException- if LLM is not available
-
generateDirectAnswer
public void generateDirectAnswer(String userMessage, List<LlmMessage> history, LlmStreamCallback callback) Generates a direct answer without document search.- Parameters:
userMessage- the user's messagehistory- the conversation historycallback- the streaming callback- Throws:
LlmException- if LLM is not available
-