build method

Builds and returns a configured LLM provider instance

Returns a unified ChatCapability interface that can be used consistently across different LLM providers. The actual implementation will vary based on the selected provider.

Note: Some providers may implement additional interfaces like EmbeddingCapability, ModelListingCapability, etc. Use dynamic casting to access these features.

Throws LLMError if:

  • No provider is specified
  • Provider is not registered
  • Required configuration like API keys are missing

Implementation

Future<ChatCapability> build() async {
  if (_providerId == null) {
    throw const GenericError('No provider specified');
  }

  // Use the registry to create the provider
  return LLMProviderRegistry.createProvider(_providerId!, _config);
}