installModelFromAssetWithProgress method

  1. @override
Stream<int> installModelFromAssetWithProgress(
  1. String path, {
  2. String? loraPath,
})
override

Installs model from Flutter assets with progress tracking (debug only)

Implementation

@override
Stream<int> installModelFromAssetWithProgress(String path, {String? loraPath}) async* {
  if (kReleaseMode) {
    throw UnsupportedError("Asset model loading is not supported in release builds");
  }

  await _ensureInitialized();

  final spec = InferenceModelSpec(
    name: path.split('/').last.replaceAll('.bin', '').replaceAll('.task', ''),
    modelUrl: 'asset://$path',
    loraUrl: loraPath != null ? 'asset://$loraPath' : null,
  );

  // Since assets are copied instantly, we'll simulate progress
  for (int progress = 0; progress <= 100; progress += 10) {
    yield progress;
    if (progress < 100) {
      await Future.delayed(const Duration(milliseconds: 50));
    }
  }

  await _ensureModelReadySpec(spec);
}