Class GeminiAiProvider
java.lang.Object
uno.anahata.asi.agi.event.BasicPropertyChangeSource
uno.anahata.asi.agi.provider.AbstractAiProvider
uno.anahata.asi.gemini.GeminiAiProvider
- All Implemented Interfaces:
PropertyChangeSource, Rebindable
- Direct Known Subclasses:
GeminiGoogleCloudExpressAIProvider
The concrete implementation of the
AbstractAgiProvider for the Google
Gemini API. This class manages the native Client instance and handles
the discovery and listing of available Gemini models.- Author:
- anahata-gemini-pro-2.5
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate com.google.genai.ClientThe native Google GenAI client instance. transient to prevent serialization.private booleanWhether this provider is configured to use Google Cloud Vertex AI instead of the standard AI Studio endpoint.Fields inherited from class AbstractAiProvider
MARKUP_TABLE_HEADERModifier and TypeFieldDescriptionstatic final StringMarkdown table header for provider listings.Fields inherited from class BasicPropertyChangeSource
propertyChangeSupportModifier and TypeFieldDescriptionprotected PropertyChangeSupportSupport for firing property change events. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new Gemini Provider with default settings.GeminiAiProvider(String uuid, String displayName, boolean vertex) Craetes a new Gemini Provider using the Official Google Genai Java SDK. -
Method Summary
Modifier and TypeMethodDescriptionGets a template or hint string to display when the API keys file is empty.com.google.genai.ClientGets the native Gemini API client, creating it lazily if necessary.voidRotates the active key to the next available API key in the pool.List<? extends AbstractModel> Fetches the list of all models available from the provider's remote API.Methods inherited from class AbstractAiProvider
addModel, addModels, ensureKeysFileExists, findModels, getAllDisplayModels, getAllSupportedActions, getCachedApiModel, getCurrentKey, getEnabledModels, getKeyPoolSize, getKeysAcquisitionUri, getKeysFilePath, getModel, getModels, getModelsDirectory, getProviderDirectory, getProviderId, getUnloadableModelsDirectory, hasKeys, initialize, isEffectivelyEnabled, loadModelsFromDisk, persist, refreshCachedApiModels, reloadKeyPool, reloadKeyPoolIfNeeded, remove, removeModel, testConnection, toMarkupRow, toMarkupRowModifier and TypeMethodDescriptionvoidaddModel(AbstractModel model) Adds a new model to this provider's local models list and persists it to disk.voidaddModels(List<AbstractModel> modelsToAdd) Adds multiple models to this provider's local models list, persists each to disk, and fires a single unified property change event for"models".voidEnsures that the API keys file exists on the host filesystem, creating * parent directories and the file if missing.findModels(String query, List<ResponseModality> modalities) Finds and filters models within this provider matching a regex/text query AND all requested response modalities.Gets the combined list of local persisted models and any newly discovered API models that are not yet persisted.Gets a set of all unique supported actions across all models offered by this provider, using the cached model list.getCachedApiModel(String modelId) Finds a cached API model by its unique ID.Returns the API key currently in use by this provider instance, reloading from disk if the file was modified externally.Gets the list of models that are currently enabled for this provider.intReturns the total number of configured API keys for this provider.Gets the URI where users can acquire API keys for this provider.Resolves the path to the API keys configuration file for this provider.Finds a single model by its unique ID within this provider.Gets the master list of model entities for this provider (loaded from disk .kryo files).Resolves the path to the models directory for this provider.Resolves the absolute path to the provider's storage directory in the active container.Compatibility alias forgetUuid()to maintain integration with existing IDE and UI components that expect a provider ID.Gets the directory where model entities that failed to load are quarantined.booleanhasKeys()Checks if there are any valid API keys configured for this provider.voidInitializes this provider after instantiation and container binding.booleanChecks if this provider is effectively enabled and ready for active model requests.Loads all persisted models from this provider's models directory on disk into memory.voidpersist()Persists this AI provider entity directly to disk in the container's providers directory (~/.anahata/asi/<hostApp>/<version>/providers/<uuid>.kryo).Queries the provider's remote API to discover models and updatesAbstractAiProvider.cachedApiModels.voidReloads the API key pool from the provider's configuration file and triggers an initial key selection.voidChecks if the API keys configuration file on disk has been modified since it was last loaded.voidremove()Deletes the persisted .kryo file for this AI provider from disk and removes it from its parent container registry.voidremoveModel(AbstractModel model) Removes a model from this provider's in-memory list.Tests connectivity to the provider's remote API endpoint and returns a human-readable status summary.Formats this provider as a Markdown table row, defaulting to showing the total count of models.toMarkupRow(boolean includeModelIds) Formats this provider as a Markdown table row for provider listing tools.Methods inherited from class BasicPropertyChangeSource
addPropertyChangeListener, addPropertyChangeListener, rebind, removePropertyChangeListener, removePropertyChangeListenerModifier and TypeMethodDescriptionvoidAdds a property change listener.voidaddPropertyChangeListener(String propertyName, PropertyChangeListener listener) Adds a property change listener for a specific property.voidrebind()Re-initializes the transientPropertyChangeSupportafter deserialization.voidRemoves a property change listener.voidremovePropertyChangeListener(String propertyName, PropertyChangeListener listener) Removes a property change listener for a specific property.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface PropertyChangeSource
getPropertyChangeSupportModifier and TypeMethodDescriptionGets the PropertyChangeSupport instance for this object.
-
Field Details
-
client
private transient com.google.genai.Client clientThe native Google GenAI client instance. transient to prevent serialization. -
vertex
private boolean vertexWhether this provider is configured to use Google Cloud Vertex AI instead of the standard AI Studio endpoint.
-
-
Constructor Details
-
GeminiAiProvider
public GeminiAiProvider()Creates a new Gemini Provider with default settings. -
GeminiAiProvider
-
-
Method Details
-
getClient
public com.google.genai.Client getClient()Gets the native Gemini API client, creating it lazily if necessary.- Returns:
- The native
Clientinstance.
-
hokusPocus
public void hokusPocus()Rotates the active key to the next available API key in the pool. Subclasses override to invalidate native API clients.Implementation details: Nullifies the internal Gemini client. This forces the provider to rotate to the next API key in the pool and reconstruct the client on the very next generation request.
- Overrides:
hokusPocusin classAbstractAiProvider
-
listModels
Fetches the list of all models available from the provider's remote API.Implementation details: Synchronously fetches the list of available Generative Models from the Google GenAI service. Each native model is wrapped in a
GeminiModeladapter.- Specified by:
listModelsin classAbstractAiProvider- Returns:
- A list of provider-specific
AbstractModelobjects.
-
getApiKeyHint
Gets a template or hint string to display when the API keys file is empty.Provides a template configuration for the Gemini api_keys.txt file.
- Specified by:
getApiKeyHintin classAbstractAiProvider- Returns:
- The API key hint text.
-

