Class AiProviderFactory

java.lang.Object
org.egothor.methodatlas.ai.AiProviderFactory

public final class AiProviderFactory extends Object
Factory responsible for creating provider-specific AI client implementations.

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:

  1. Attempt to use a locally running OllamaClient.
  2. If Ollama is not reachable and an API key is configured, fall back to an OpenAI-compatible provider.
  3. If no provider can be resolved, an AiSuggestionException is 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 Details

    • create

      public static AiProviderClient create(AiOptions options) throws AiSuggestionException
      Creates a provider-specific AiProviderClient based on the supplied configuration.

      The selected provider determines which concrete implementation is instantiated and how availability checks are performed. When AiProvider.AUTO is configured, the method delegates provider selection to auto(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