createEngine method

  1. @override
EngineHandle createEngine(
  1. EngineConfig config
)
override

Implementation

@override
EngineHandle createEngine(EngineConfig config) {
  final jsEngine = _loadSdk()
      .timeout(
        _sdkLoadTimeout,
        onTimeout: () => throw const LiteRtLmException(
          'Timed out loading the LiteRT-LM JS SDK.',
        ),
      )
      .then((sdk) {
        final settings = <String, Object?>{
          'model': config.modelPath,
          'backend': _backendValue(sdk, config.backend),
        };

        final maxNumTokens = config.maxNumTokens;
        if (maxNumTokens != null) {
          settings['mainExecutorSettings'] = {'maxNumTokens': maxNumTokens};
        }

        final engineConstructor = sdk.getProperty<JSObject>('Engine'.toJS);
        return _promiseToFuture<JSObject>(
          engineConstructor.callMethod<JSPromise<JSObject>>(
            'create'.toJS,
            _parseJson(jsonEncode(settings)),
          ),
        );
      });
  return _WebEngineHandle(jsEngine);
}