Package org.codelibs.fess.llm
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 Summary
Modifier and TypeMethodDescriptionchat(LlmChatRequest request) Performs a chat completion request.detectIntent(String userMessage) Detects the intent of a user message.default IntentDetectionResultdetectIntent(String userMessage, List<LlmMessage> history) Detects the intent of a user message with conversation history context.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.default intGets the maximum characters for assistant message in history.default intGets the maximum characters for assistant summary in history.getName()Returns the name of this LLM client.booleanChecks if this LLM client is available and properly configured.regenerateQuery(String userMessage, String failedQuery, String failureReason, List<LlmMessage> history) Regenerates a search query when the previous query failed to produce relevant results.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
-
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
-
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
-
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 messagefailedQuery- the query that failedfailureReason- 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 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
-
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
-