UNPKG

react-native-executorch

Version:

An easy way to run AI models in React Native with ExecuTorch

21 lines (20 loc) 927 B
"use strict"; import { ResourceFetcher } from '../../utils/ResourceFetcher'; import { BaseModule } from '../BaseModule'; export class TextEmbeddingsModule extends BaseModule { async load(model, onDownloadProgressCallback = () => {}) { const modelPromise = ResourceFetcher.fetch(onDownloadProgressCallback, model.modelSource); const tokenizerPromise = ResourceFetcher.fetch(undefined, model.tokenizerSource); const [modelResult, tokenizerResult] = await Promise.all([modelPromise, tokenizerPromise]); const modelPath = modelResult?.[0]; const tokenizerPath = tokenizerResult?.[0]; if (!modelPath || !tokenizerPath) { throw new Error('Download interrupted.'); } this.nativeModule = global.loadTextEmbeddings(modelPath, tokenizerPath); } async forward(input) { return new Float32Array(await this.nativeModule.generate(input)); } } //# sourceMappingURL=TextEmbeddingsModule.js.map