Package org.machanism.machai.ai.manager
package org.machanism.machai.ai.manager
Provider resolution and usage tracking for generative AI integrations.
This package contains the classes that translate configured chat model identifiers into concrete
Genai provider implementations and collect token-consumption
metrics produced by those providers. It supports both provider instantiation for runtime use and
post-execution aggregation of usage statistics for logging and inspection.
Primary responsibilities
- Resolve provider implementations from model identifiers such as
OpenAI:gpt-4o-mini. - Initialize resolved providers with a
Configuratorafter applying the selectedchatModelvalue. - Represent token usage for individual invocations with immutable usage records.
- Aggregate and log usage information across one or more configured models.
Included types
GenaiProviderManagercreates provider instances from configured model identifiers.Usagestores token counts for a single provider call.UsageStatisticsgroups and reports usage metrics by model identifier.
Identifier handling
Provider identifiers are typically supplied in the form Provider:Model. When the provider segment
does not contain a package separator, the implementation class is inferred using the package naming
convention org.machanism.machai.ai.provider.<provider-lowercase>.<Provider>Provider. When the
provider segment is already a fully qualified class name, it is loaded directly.
Example
Configurator conf = ...;
Genai provider = GenaiProviderManager.getProvider("OpenAI:gpt-4o-mini", conf);
String response = provider.perform();
UsageStatistics.addUsage("OpenAI:gpt-4o-mini", provider.usage());
UsageStatistics.logUsageForModel("OpenAI:gpt-4o-mini");
-
ClassesClassDescriptionToken usage metrics for a single generative-AI invocation.Manages and aggregates usage statistics for GenAI models.