downloadModel method
- void onProgress(
- double progress
Download model files if not present. Reports progress via onProgress.
Implementation
Future<void> downloadModel({
void Function(double progress)? onProgress,
}) async {
final dir = await _modelsDir;
final modelPath = '${dir.path}/$_modelFilename';
final vocabPath = '${dir.path}/$_vocabFilename';
// Download vocabulary file first (small, ~230 KB).
if (!File(vocabPath).existsSync()) {
dev.log('Downloading vocabulary...', name: 'LocalEmbedding');
await _dio.download(_vocabUrl, vocabPath);
}
// Download ONNX model (~90 MB).
if (!File(modelPath).existsSync()) {
dev.log('Downloading ONNX model...', name: 'LocalEmbedding');
await _dio.download(
_modelUrl,
modelPath,
onReceiveProgress: (received, total) {
if (total > 0 && onProgress != null) {
onProgress(received / total);
}
},
);
}
}