init method
Implementation
Future<bool> init({
String? modelFilename,
String? chatTemplate,
int contextSize = 2048,
int gpuLayers = 0,
int threads = 4,
bool generateEmbeddings = false,
CactusProgressCallback? onProgress,
String? cactusToken,
}) async {
if (cactusToken != null) {
setCactusToken(cactusToken);
}
final filename = modelFilename ?? _lastDownloadedFilename;
if (filename == null) {
throw ArgumentError('No model filename provided and no model was previously downloaded');
}
final appDocDir = await getApplicationDocumentsDirectory();
final modelPath = '${appDocDir.path}/$filename';
final file = File(modelPath);
if (!await file.exists()) {
throw ArgumentError('Model file does not exist at path: $modelPath');
}
final initParams = CactusInitParams(
modelPath: modelPath,
chatTemplate: chatTemplate,
contextSize: contextSize,
gpuLayers: gpuLayers,
threads: threads,
generateEmbeddings: generateEmbeddings,
onInitProgress: onProgress,
);
_initParams = initParams;
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;
}
}