withBestProvider<R> method

Future<R?> withBestProvider<R>(
  1. Set<LLMCapability> required,
  2. Future<R> action(
    1. String providerId,
    2. dynamic provider
    ), {
  3. Set<LLMCapability>? preferred,
})

Execute action with the best available provider

Implementation

Future<R?> withBestProvider<R>(
  Set<LLMCapability> required,
  Future<R> Function(String providerId, dynamic provider) action, {
  Set<LLMCapability>? preferred,
}) async {
  final providerId = findBestProvider(required, preferred: preferred);
  if (providerId == null) return null;

  final provider = _providers[providerId];
  if (provider == null) return null;

  return await action(providerId, provider);
}