Package org.codelibs.fess.llm.gemini
Class GeminiLlmClient
java.lang.Object
org.codelibs.fess.llm.AbstractLlmClient
org.codelibs.fess.llm.gemini.GeminiLlmClient
- All Implemented Interfaces:
LlmClient
LLM client implementation for Google Gemini API.
Google Gemini provides cloud-based LLM services including Gemini models.
This client supports both synchronous and streaming chat completions.
- Author:
- FessProject
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final StringThe name identifier for the Gemini LLM client.protected static final StringGemini role for model responses (equivalent to "assistant" in OpenAI).Fields inherited from class org.codelibs.fess.llm.AbstractLlmClient
answerGenerationSystemPrompt, availabilityCheckTask, cachedAvailability, directAnswerSystemPrompt, documentNotFoundSystemPrompt, evaluationPrompt, faqAnswerSystemPrompt, httpClient, intentDetectionPrompt, noResultsSystemPrompt, objectMapper, summarySystemPrompt, summarySystemPromptSuffix, unclearIntentSystemPrompt -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringbuildApiUrl(String model, boolean stream) Builds the API URL for the specified model.buildRequestBody(LlmChatRequest request) Builds the request body for the Gemini API.chat(LlmChatRequest request) Performs a chat completion request.protected booleanPerforms the actual availability check against the LLM provider.convertMessage(LlmMessage message) Converts an LlmMessage to a map for the Gemini API request.protected StringGets the Gemini API key.protected StringGets the Gemini API URL.protected intGets the maximum tokens for result evaluation.protected intGets the maximum tokens for intent detection.protected StringgetModel()Gets the model name.protected StringgetModelName(LlmChatRequest request) Gets the model name from the request or config.getName()Returns the name of this LLM client.protected intGets the request timeout in milliseconds.voidstreamChat(LlmChatRequest request, LlmStreamCallback callback) Performs a streaming chat completion request.Methods inherited from class org.codelibs.fess.llm.AbstractLlmClient
addHistory, buildContext, buildEvaluationPrompt, buildIntentDetectionPrompt, buildStreamingRequest, destroy, detectIntent, evaluateResults, extractJsonArray, extractJsonBoolean, extractJsonIntArray, extractJsonString, extractJsonStringFallback, generateAnswer, generateDirectAnswer, generateDocumentNotFoundResponse, generateFaqAnswerResponse, generateNoResultsResponse, generateSummaryResponse, generateUnclearIntentResponse, getAvailabilityCheckInterval, getHttpClient, getLanguageInstruction, getLlmType, getMaxTokens, getStringValue, getTemperature, getUserLocale, init, isAvailable, isRagChatEnabled, parseEvaluationResponse, parseIntentResponse, resolveLanguageInstruction, setAnswerGenerationSystemPrompt, setDirectAnswerSystemPrompt, setDocumentNotFoundSystemPrompt, setEvaluationPrompt, setFaqAnswerSystemPrompt, setIntentDetectionPrompt, setNoResultsSystemPrompt, setSummarySystemPrompt, setSummarySystemPromptSuffix, setUnclearIntentSystemPrompt, startAvailabilityCheck, streamGenerateAnswer, stripCodeFences, updateAvailability
-
Field Details
-
NAME
The name identifier for the Gemini LLM client.- See Also:
-
ROLE_MODEL
Gemini role for model responses (equivalent to "assistant" in OpenAI).- See Also:
-
-
Constructor Details
-
GeminiLlmClient
public GeminiLlmClient()Default constructor.
-
-
Method Details
-
getName
Description copied from interface:LlmClientReturns the name of this LLM client.- Returns:
- the client name (e.g., "ollama", "openai", "gemini")
-
checkAvailabilityNow
protected boolean checkAvailabilityNow()Description copied from class:AbstractLlmClientPerforms the actual availability check against the LLM provider.- Specified by:
checkAvailabilityNowin classAbstractLlmClient- Returns:
- true if the provider is available
-
chat
Description copied from interface:LlmClientPerforms a chat completion request.- Parameters:
request- the chat request containing messages and parameters- Returns:
- the chat response from the LLM
-
streamChat
Description copied from interface:LlmClientPerforms 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
-
getModelName
Gets the model name from the request or config.- Parameters:
request- the chat request- Returns:
- the model name
-
buildApiUrl
Builds the API URL for the specified model.- Parameters:
model- the model namestream- whether this is a streaming request- Returns:
- the complete API URL
-
buildRequestBody
Builds the request body for the Gemini API.- Parameters:
request- the chat request- Returns:
- the request body as a map
-
convertMessage
Converts an LlmMessage to a map for the Gemini API request.- Parameters:
message- the message to convert- Returns:
- the message as a map
-
getApiKey
Gets the Gemini API key.- Returns:
- the API key
-
getApiUrl
Gets the Gemini API URL.- Returns:
- the API URL
-
getModel
Description copied from class:AbstractLlmClientGets the model name.- Specified by:
getModelin classAbstractLlmClient- Returns:
- the model name
-
getTimeout
protected int getTimeout()Description copied from class:AbstractLlmClientGets the request timeout in milliseconds.- Specified by:
getTimeoutin classAbstractLlmClient- Returns:
- the timeout in milliseconds
-
getIntentDetectionMaxTokens
protected int getIntentDetectionMaxTokens()Description copied from class:AbstractLlmClientGets the maximum tokens for intent detection.- Overrides:
getIntentDetectionMaxTokensin classAbstractLlmClient- Returns:
- the maximum tokens for intent detection
-
getEvaluationMaxTokens
protected int getEvaluationMaxTokens()Description copied from class:AbstractLlmClientGets the maximum tokens for result evaluation.- Overrides:
getEvaluationMaxTokensin classAbstractLlmClient- Returns:
- the maximum tokens for result evaluation
-