loadLmModel method
Loads and compiles a .litertlm language model.
Implementation
@override
Future<LiteRtLmModel> loadLmModel(String modelPath, {String accelerator = 'gpu'}) async {
final raw = web.window.getProperty('LiteRtLmEngine'.toJS);
if (raw == null || !raw.isA<JSObject>()) {
throw StateError('LiteRT-LM engine constructor is not available on window. Make sure to call loadLiteRtLm first.');
}
final constructor = _LiteRtLmEngineConstructor._(raw as JSObject);
final settings = JSObject();
settings.setProperty('model'.toJS, modelPath.toJS);
final backendVal = accelerator == 'cpu' ? 3 : 2; // 3 = CPU, 2 = GPU_ARTISAN
settings.setProperty('backend'.toJS, backendVal.toJS);
final executorSettings = JSObject();
executorSettings.setProperty('maxNumTokens'.toJS, 2048.toJS);
settings.setProperty('mainExecutorSettings'.toJS, executorSettings);
final jsEngine = await constructor.create(settings).toDart;
return LiteRtLmModelWeb(jsEngine);
}