availability method
Checks the key and that the provider serves ProviderConfig.model, by listing models. A server without a model listing counts as available.
Implementation
@override
Future<AiAvailability> availability({String locale = 'en'}) async {
if (config.model.trim().isEmpty) return AiAvailability.unsupported;
try {
final models = await listModels(timeout: availabilityTimeout);
final model = config.model.trim();
final served =
models.isEmpty ||
models.any((id) => id == model || id.endsWith('/$model'));
return served ? AiAvailability.available : AiAvailability.unsupported;
} on SystemLlmException catch (error) {
return switch (error.code) {
SystemLlmException.unauthorized => AiAvailability.unauthorized,
SystemLlmException.modelNotFound ||
SystemLlmException.invalidResponse => AiAvailability.available,
_ => AiAvailability.unreachable,
};
}
}