installModelFromAssetWithProgress method

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

Installs the model and lora weights from the asset with progress.

Model should be loaded before initialization.

This method can be safely called multiple times. Model and lora weights will be loaded only if they doesn't exist.

To reload the model, call deleteModel first. To reload the lora weights, call deleteLoraWeights first.

This method should be used only for development purpose. Never embed neither model nor lora weights in the production app.

Implementation

@override
Stream<int> installModelFromAssetWithProgress(String path, {String? loraPath}) async* {
  final modelFileName = Uri.parse(path).pathSegments.last;
  _modelFileName = modelFileName;

  final prefs = await _prefs;
  await prefs.setString(_prefsModelKey, modelFileName);

  yield* _loadModelWithProgressIfNeeded(() => _largeFileHandler.copyAssetToLocalStorageWithProgress(
    assetName: path,
    targetPath: modelFileName,
  ));

  if (loraPath != null) {
    await installLoraWeightsFromAsset(loraPath);
  }
}