activeInferenceSpec method
The active inference model's spec, after the persisted identity has been restored.
For engines that resolve an identity rather than a file (ONNX's Transformers.js arm). Throws NoActiveModelError when no inference model is active, and StateError when the active model is not an InferenceModelSpec.
Implementation
Future<InferenceModelSpec> activeInferenceSpec() async {
// A resolver built via `forActiveModel()` holds a FRESH WebModelManager
// whose active identity is rehydrated from prefs asynchronously; await
// the restore before reading it (see [resolveActiveInferenceModel]).
await _modelManager.ensureInitialized();
final active = _modelManager.activeInferenceModel;
if (active == null) {
throw NoActiveModelError(
'No active inference model set. Use FlutterEdgeAi.installModel() first.',
);
}
if (active is! InferenceModelSpec) {
throw StateError(
'Active model is not an inference model spec (${active.runtimeType}).',
);
}
return active;
}