init method
Implementation
Future<bool> init({
String? modelFilename,
String? mmprojFilename,
String? chatTemplate,
int contextSize = 2048,
int gpuLayers = 0,
int threads = 4,
CactusProgressCallback? onProgress,
String? cactusToken,
}) async {
if (cactusToken != null) {
setCactusToken(cactusToken);
}
final actualModelFilename = modelFilename ?? _lastDownloadedModelFilename;
final actualMmprojFilename = mmprojFilename ?? _lastDownloadedMmprojFilename;
if (actualModelFilename == null || actualMmprojFilename == null) {
throw ArgumentError('No model or mmproj filenames provided and no files were previously downloaded');
}
final appDocDir = await getApplicationDocumentsDirectory();
final modelPath = '${appDocDir.path}/$actualModelFilename';
final mmprojPath = '${appDocDir.path}/$actualMmprojFilename';
final modelFile = File(modelPath);
final mmprojFile = File(mmprojPath);
if (!await modelFile.exists()) {
throw ArgumentError('Model file does not exist at path: $modelPath');
}
if (!await mmprojFile.exists()) {
throw ArgumentError('MMProj file does not exist at path: $mmprojPath');
}
final initParams = CactusInitParams(
modelPath: modelPath,
mmprojPath: mmprojPath,
chatTemplate: chatTemplate,
contextSize: contextSize,
gpuLayers: gpuLayers,
threads: threads,
onInitProgress: onProgress,
);
try {
_context = await CactusContext.init(initParams);
return true;
} catch (e) {
CactusTelemetry.error(e, initParams);
if (onProgress != null) {
onProgress(null, "Initialization failed: ${e.toString()}", true);
}
return false;
}
}