Class GenaiProviderManager
The GenaiProviderManager offers static methods to instantiate
Genai and EmbeddingProvider implementations based on a
provider/model string, using Java reflection. Providers are expected to
follow a conventional package and class naming pattern, or may be specified
by fully qualified class name.
Provider Naming Convention
- Provider and model are specified as
Provider:Model(e.g.,OpenAI:gpt-4). - If the provider name contains a dot (
.), it is treated as a fully qualified class name. - Otherwise, the provider is resolved using the pattern
org.machanism.machai.ai.provider.{provider}.{Provider}Provider.
Usage Example
Configurator conf = ...;
Genai provider = GenaiProviderManager.getProvider("OpenAI:gpt-4", conf);
EmbeddingProvider embeddingProvider = GenaiProviderManager.getEmbeddingProvider("OpenAI:embedding-model", conf);
If the provider cannot be found or instantiated, an
IllegalArgumentException is thrown.
- Author:
- Viktor Tovstyi
-
Method Summary
Modifier and TypeMethodDescriptionstatic EmbeddingProvidergetEmbeddingProvider(String embeddingModel, Configurator conf) Dynamically loads and initializes anEmbeddingProviderbased on the specified provider/model string.static GenaigetProvider(String chatModel, Configurator conf) Dynamically loads and initializes aGenaiprovider based on the specified provider/model string.
-
Method Details
-
getProvider
Dynamically loads and initializes aGenaiprovider based on the specified provider/model string.The provider name and model are parsed from the input string (format:
Provider:Model). The provider class is resolved using a conventional naming pattern or as a fully qualified class name. The provider is instantiated and initialized with the specified model and configuration.- Parameters:
chatModel- the provider/model string (e.g.,OpenAI:gpt-4)conf- the configuration object for provider initialization- Returns:
- the initialized
Genaiprovider instance, ornullif the provider name is blank - Throws:
IllegalArgumentException- if the provider name is invalid, or if the provider cannot be found or instantiated
-
getEmbeddingProvider
Dynamically loads and initializes anEmbeddingProviderbased on the specified provider/model string.The provider name and model are parsed from the input string (format:
Provider:Model). The provider class is resolved using a conventional naming pattern or as a fully qualified class name. The provider is instantiated and initialized with the specified model and configuration.- Parameters:
embeddingModel- the provider/model string (e.g.,OpenAI:embedding-model)conf- the configuration object for provider initialization- Returns:
- the initialized
EmbeddingProviderinstance, ornullif the provider name is blank - Throws:
IllegalArgumentException- if the provider cannot be found, does not implementEmbeddingProvider, or cannot be instantiated
-