create method
EmbeddingEngine.create(settings).
Implementation
@override
Future<LiteRtLmWebEngine> create(LiteRtLmWebEngineSettings settings) async {
final js = JSObject()
..['model'] = settings.modelUrl.toJS
..['backend'] = _backendValue(settings.backend).toJS
..['maxInputLength'] = settings.maxInputLength.toJS;
// Absent, never null: the runtime tests `!== undefined`, and a null
// visionBackend would ask for a tower with no backend.
if (settings.visionBackend case final vision?) {
js['visionBackend'] = _backendValue(vision).toJS;
}
// The same rule: absent = the audio tower disabled.
if (settings.audioBackend case final audio?) {
js['audioBackend'] = _backendValue(audio).toJS;
}
if (settings.minInputLength case final min?) {
js['minInputLength'] = min.toJS;
}
if (settings.visionTokensPerImage case final budget?) {
js['visionTokensPerImage'] = budget.toJS;
}
final _EmbeddingEngine engine;
try {
engine = await _EmbeddingEngine.create(js).toDart;
} catch (e) {
final version = otherWebRuntimeVersionSentence();
if (version == null) rethrow;
throw _OtherVersionCreateFailure('$e. $version');
}
return _WindowEngine(engine);
}