react-native-executorch
Version:
An easy way to run AI models in React Native with ExecuTorch
34 lines • 1.35 kB
TypeScript
import { RnExecutorchError } from '../errors/errorUtils';
type Deletable = {
delete: () => void;
};
type RunOnFrame<M> = M extends {
runOnFrame: infer R;
} ? R : never;
/**
* Shared hook for modules that are instantiated via an async static factory
* (i.e. `SomeModule.fromModelName(config, onProgress)`).
*
* Handles model loading, download progress, error state, and enforces the
* not-loaded / already-generating guards so individual hooks only need to
* define their typed `forward` wrapper.
* @param props - Options object containing the factory function, config, deps array, and optional preventLoad flag.
* @returns An object with error, isReady, isGenerating, downloadProgress, runForward, instance, and runOnFrame.
* @internal
*/
export declare function useModuleFactory<M extends Deletable, Config>({ factory, config, deps, preventLoad, }: {
factory: (config: Config, onProgress: (progress: number) => void) => Promise<M>;
config: Config;
deps: ReadonlyArray<unknown>;
preventLoad?: boolean;
}): {
error: RnExecutorchError | null;
isReady: boolean;
isGenerating: boolean;
downloadProgress: number;
runForward: <R>(fn: (instance: M) => Promise<R>) => Promise<R>;
instance: M | null;
runOnFrame: RunOnFrame<M> | null;
};
export {};
//# sourceMappingURL=useModuleFactory.d.ts.map