downloadModel method

Future<String> downloadModel(
  1. String url, {
  2. String? filename,
})

Download a GGUF model from url into the app's documents directory.

Returns the local filesystem path. Skips the download if the file already exists at the destination.

Note: this method exists for development convenience. Production callers (synheart-core-flutter's SyniModule) should use the core SDK's model installer which performs SHA verification and consent gating.

Implementation

Future<String> downloadModel(String url, {String? filename}) async {
  await initialize();

  final dir = await getApplicationDocumentsDirectory();
  final modelsDir = Directory('${dir.path}/syni_models');
  if (!modelsDir.existsSync()) {
    modelsDir.createSync(recursive: true);
  }

  final name = filename ?? url.split('/').last;
  final modelPath = '${modelsDir.path}/$name';

  if (File(modelPath).existsSync()) {
    return modelPath;
  }

  final response = await http.get(Uri.parse(url));
  if (response.statusCode != 200) {
    throw SyniRuntimeError(
      'Failed to download model: HTTP ${response.statusCode}',
    );
  }
  await File(modelPath).writeAsBytes(response.bodyBytes);
  return modelPath;
}