Package org.machanism.machai.ai.manager
Class GenaiProviderManager
java.lang.Object
org.machanism.machai.ai.manager.GenaiProviderManager
Factory/registry for resolving
Genai implementations from a provider/model identifier and
aggregating per-run Usage metrics.
The model identifier is formatted as Provider:Model (for example, OpenAI:gpt-4o-mini). If the
provider portion is omitted (for example, gpt-4o-mini), the default provider is used.
Providers are instantiated via reflection. A provider can be referenced either by:
- a short provider name (mapped to
org.machanism.machai.ai.provider.<provider>.<Provider>Provider), or - a fully-qualified class name.
Usage
Configurator conf = ...;
Genai provider = GenaiProviderManager.getProvider("OpenAI:gpt-4o-mini", conf);
provider.prompt("Hello!");
String response = provider.perform();
GenaiProviderManager.addUsage(provider.usage());
GenaiProviderManager.logUsage();
Thread-safety: Usage aggregation is backed by a static ArrayList and is not
synchronized.
- Author:
- Viktor Tovstyi
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidAdds a singleUsagerecord to the in-memory aggregation list.static GenaigetProvider(String chatModel, Configurator conf) Creates a provider instance for the given provider/model identifier and applies the selected model.static voidlogUsage()Logs a summary of the aggregatedUsagerecords.
-
Method Details
-
getProvider
Creates a provider instance for the given provider/model identifier and applies the selected model.- Parameters:
chatModel- the model identifier formatted asProvider:Modelor justModelconf- configurator used to initialize the provider- Returns:
- a new provider instance configured with the requested model
- Throws:
IllegalArgumentException- if the provider cannot be resolved or instantiated
-
addUsage
Adds a singleUsagerecord to the in-memory aggregation list.- Parameters:
usage- usage to add
-
logUsage
public static void logUsage()Logs a summary of the aggregatedUsagerecords.
-