Class AiProviderFactory
This class centralizes the logic for selecting and constructing concrete
AiProviderClient implementations based on the configuration provided
through AiOptions. It abstracts provider instantiation from the rest
of the application so that higher-level components interact only with the
AiProviderClient interface.
Provider Resolution
When an explicit provider is configured in AiOptions.provider(), the
factory constructs the corresponding client implementation. When
AiProvider.AUTO is selected, the factory attempts to determine a
suitable provider automatically using the following strategy:
- Attempt to use a locally running
OllamaClient. - If Ollama is not reachable and an API key is configured, fall back to an OpenAI-compatible provider.
- If no provider can be resolved, an
AiSuggestionExceptionis thrown.
The factory ensures that returned clients are usable by verifying provider availability when required.
This class is intentionally non-instantiable and exposes only static factory methods.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic AiProviderClientCreates a provider-specificAiProviderClientbased on the supplied configuration.
-
Method Details
-
create
Creates a provider-specificAiProviderClientbased on the supplied configuration.The selected provider determines which concrete implementation is instantiated and how availability checks are performed. When
AiProvider.AUTOis configured, the method delegates provider selection toauto(AiOptions).- Parameters:
options- AI configuration describing provider, model, endpoint, authentication, and runtime limits- Returns:
- initialized provider client ready to perform inference requests
- Throws:
AiSuggestionException- if the provider cannot be initialized, required authentication is missing, or no suitable provider can be resolved
-