Package org.machanism.machai.process.manager
The package has two responsibilities. ProcessProviderManager is
the reflection-based entry point for creating configured process and
embedding providers. Usage represents the token counts reported by
one interaction, while UsageStatistics collects those records by
model identifier and writes aggregate summaries through SLF4J.
Provider resolution
Provider requests use the form Provider:Model. The manager splits
at the first colon: the text before it identifies the provider and the text
after it is passed to the provider as its model name. A blank provider
segment returns null. Provider implementations are created through
a public no-argument constructor and initialized with the model name and a
Configurator.
Process-provider names must be valid Java identifiers. Simple names are
resolved against the supported provider class-name conventions, with the
later convention taking precedence when both classes exist, then against
the manager's nested-provider fallback. Embedding-provider
names containing a dot are treated as fully qualified class names; other
names use the same convention lookup. An embedding class must implement
EmbeddingProvider. Missing
classes, unavailable public no-argument constructors, reflection failures,
invalid process-provider names, and incompatible embedding classes are
reported as IllegalArgumentException. Runtime exceptions thrown by
an embedding provider during initialization are propagated unchanged.
Usage collection and reporting
Usage is an immutable value object containing input, cached-input,
and output token counts. UsageStatistics stores usage records in a
static, in-memory map keyed by the exact model identifier supplied to
UsageStatistics.addUsage(String, Usage). The registry is not
persisted between application runs. Model-specific additions and reads are
synchronized. UsageStatistics.getUsageForModel(String) returns a
defensive list copy, whereas
UsageStatistics.getAllModelUsages() returns a shallow map copy whose
value lists remain shared.
Example
UsageStatistics.init();
Configurator conf = ...;
ProcessProvider chat = ProcessProviderManager.getProvider("OpenAI:gpt-4o", conf);
EmbeddingProvider embeddings = ProcessProviderManager.getEmbeddingProvider(
"OpenAI:text-embedding-3-small", conf);
UsageStatistics.addUsage("OpenAI:gpt-4o", new Usage(500, 100, 200));
UsageStatistics.logUsage();
Call UsageStatistics.init() during startup when eager utility
class initialization is useful. Use UsageStatistics.logUsage() to
report each currently registered model, or
UsageStatistics.logUsageForModel(String) to report one model.
- 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.