Class GeminiLlmClient

java.lang.Object
org.codelibs.fess.llm.AbstractLlmClient
org.codelibs.fess.llm.gemini.GeminiLlmClient
All Implemented Interfaces:
LlmClient

public class GeminiLlmClient extends AbstractLlmClient
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 Details

    • NAME

      protected static final String NAME
      The name identifier for the Gemini LLM client.
      See Also:
    • ROLE_MODEL

      protected static final String ROLE_MODEL
      Gemini role for model responses (equivalent to "assistant" in OpenAI).
      See Also:
  • Constructor Details

    • GeminiLlmClient

      public GeminiLlmClient()
      Default constructor.
  • Method Details

    • getName

      public String getName()
      Description copied from interface: LlmClient
      Returns the name of this LLM client.
      Returns:
      the client name (e.g., "ollama", "openai", "gemini")
    • checkAvailabilityNow

      protected boolean checkAvailabilityNow()
      Description copied from class: AbstractLlmClient
      Performs the actual availability check against the LLM provider.
      Specified by:
      checkAvailabilityNow in class AbstractLlmClient
      Returns:
      true if the provider is available
    • chat

      public LlmChatResponse chat(LlmChatRequest request)
      Description copied from interface: LlmClient
      Performs a chat completion request.
      Parameters:
      request - the chat request containing messages and parameters
      Returns:
      the chat response from the LLM
    • streamChat

      public void streamChat(LlmChatRequest request, LlmStreamCallback callback)
      Description copied from interface: LlmClient
      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
    • getModelName

      protected String getModelName(LlmChatRequest request)
      Gets the model name from the request or config.
      Parameters:
      request - the chat request
      Returns:
      the model name
    • buildApiUrl

      protected String buildApiUrl(String model, boolean stream)
      Builds the API URL for the specified model.
      Parameters:
      model - the model name
      stream - whether this is a streaming request
      Returns:
      the complete API URL
    • buildRequestBody

      protected Map<String,Object> buildRequestBody(LlmChatRequest request)
      Builds the request body for the Gemini API.
      Parameters:
      request - the chat request
      Returns:
      the request body as a map
    • convertMessage

      protected Map<String,Object> convertMessage(LlmMessage message)
      Converts an LlmMessage to a map for the Gemini API request.
      Parameters:
      message - the message to convert
      Returns:
      the message as a map
    • getApiKey

      protected String getApiKey()
      Gets the Gemini API key.
      Returns:
      the API key
    • getApiUrl

      protected String getApiUrl()
      Gets the Gemini API URL.
      Returns:
      the API URL
    • getModel

      protected String getModel()
      Description copied from class: AbstractLlmClient
      Gets the model name.
      Specified by:
      getModel in class AbstractLlmClient
      Returns:
      the model name
    • getTimeout

      protected int getTimeout()
      Description copied from class: AbstractLlmClient
      Gets the request timeout in milliseconds.
      Specified by:
      getTimeout in class AbstractLlmClient
      Returns:
      the timeout in milliseconds
    • getIntentDetectionMaxTokens

      protected int getIntentDetectionMaxTokens()
      Description copied from class: AbstractLlmClient
      Gets the maximum tokens for intent detection.
      Overrides:
      getIntentDetectionMaxTokens in class AbstractLlmClient
      Returns:
      the maximum tokens for intent detection
    • getEvaluationMaxTokens

      protected int getEvaluationMaxTokens()
      Description copied from class: AbstractLlmClient
      Gets the maximum tokens for result evaluation.
      Overrides:
      getEvaluationMaxTokens in class AbstractLlmClient
      Returns:
      the maximum tokens for result evaluation