Package org.machanism.machai.ai.manager
The package contains the following components:
GenaiProviderManagerparses aProvider:Modelidentifier, locates the provider implementation, creates it through its no-argument constructor, and initializes it with aConfigurator. Conventional provider names resolve to classes underorg.machanism.machai.ai.provider.impl; embedding lookups also accept a fully qualified class name.Usageis an immutable record of input, cached-input, and output token counts for one provider interaction.UsageStatisticsstores usage records by model identifier and provides methods for retrieving records and logging token totals.
Provider resolution
Pass a provider and model separated by a colon. For a conventional provider
name, the manager first attempts
org.machanism.machai.ai.provider.impl.{Provider}Provider; if that
class is unavailable, it attempts a nested provider class in
GenaiProviderManager. The chat-provider method accepts provider names
composed of Java identifier characters, while the embedding-provider method can
additionally resolve a provider segment containing a dot as a fully qualified
class name. The selected class must expose an accessible no-argument
constructor and implement the requested provider interface.
Usage tracking
Initialize the statistics class if desired during application startup, then add each provider response to the registry. Records are grouped by the exact model identifier supplied by the caller. Retrieval of one model returns a defensive copy of its list; retrieval of all models returns a shallow copy of the registry map.
Example
UsageStatistics.init();
Configurator conf = ...;
Genai chat = GenaiProviderManager.getProvider("OpenAI:gpt-4o", conf);
EmbeddingProvider embeddings = GenaiProviderManager.getEmbeddingProvider(
"OpenAI:text-embedding-3-small", conf);
UsageStatistics.addUsage("OpenAI:gpt-4o", new Usage(500, 100, 200));
UsageStatistics.logUsage();
- See Also:
-
ClassesClassDescriptionUtility class for dynamically loading and initializing generative AI providers and embedding providers.Immutable token-usage metrics for a single generative AI interaction.Central registry for aggregated GenAI token-usage statistics.