init method

  1. @override
Future<void> init({
  1. int maxTokens = 1024,
  2. double temperature = 1.0,
  3. int randomSeed = 1,
  4. int topK = 1,
  5. int? numOfSupportedLoraRanks,
  6. List<int>? supportedLoraRanks,
  7. String? loraPath,
})
override

Implementation

@override
Future<void> init({
  int maxTokens = 1024,
  double temperature = 1.0,
  int randomSeed = 1,
  int topK = 1,
  int? numOfSupportedLoraRanks,
  List<int>? supportedLoraRanks,
  String? loraPath,
}) async {
  if (((await _largeFileHandler.fileExists(targetPath: _modelPath)) && _loadCompleter == null) ||
      (_loadCompleter != null && _loadCompleter!.isCompleted)) {
    try {
      final directory = await getApplicationDocumentsDirectory();
      final result = await methodChannel.invokeMethod<bool>(
            'init',
            {
              'modelPath': '${directory.path}/$_modelPath',
              'maxTokens': maxTokens,
              'temperature': temperature,
              'randomSeed': randomSeed,
              'topK': topK,
              'numOfSupportedLoraRanks': numOfSupportedLoraRanks,
              'supportedLoraRanks': supportedLoraRanks,
              'loraPath': loraPath,
            },
          ) ??
          false;

      if (result && !_initCompleter.isCompleted) {
        _initCompleter.complete(true);
      } else if (!_initCompleter.isCompleted) {
        _initCompleter.completeError('Initialization failed');
      }
    } on PlatformException catch (e) {
      if (!_initCompleter.isCompleted) {
        _initCompleter.completeError('Platform error: ${e.message}');
      }
    } catch (e) {
      if (!_initCompleter.isCompleted) {
        _initCompleter.completeError('Error: $e');
      }
    }
  } else {
    throw Exception('Gemma is not loaded yet');
  }
}