Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/react-native-executorch/src/modules/BaseModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ export class BaseModule {
static onDownloadProgressCallback: (downloadProgress: number) => void =
() => {};

static async load(...sources: ResourceSource[]): Promise<void> {
static async load(
sources: ResourceSource[],
...loadArgs: any[] // this can be used in derived classes to pass extra args to load method
): Promise<void> {
try {
const paths = await ResourceFetcher.fetchMultipleResources(
this.onDownloadProgressCallback,
...sources
);
await this.nativeModule.loadModule(...paths);
await this.nativeModule.loadModule(...paths, ...loadArgs);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think nativeModule accepts loadArgs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, in some cases it can? What if we want to pass an extra argument to the native side load function? I see no downside. When you call this in derived class:

await super.load([modelSource, tokenizerSource], someArg);

you can expect that everything goes to the native side as it should

} catch (error) {
throw new Error(getError(error));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class TextEmbeddingsModule extends BaseModule {
modelSource: ResourceSource,
tokenizerSource: ResourceSource
) {
await super.load(modelSource, tokenizerSource);
await super.load([modelSource, tokenizerSource]);
}

static override async forward(input: string): Promise<number[]> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class TokenizerModule extends BaseModule {
protected static override nativeModule = TokenizerNativeModule;

static override async load(tokenizerSource: ResourceSource) {
await super.load(tokenizerSource);
await super.load([tokenizerSource]);
}

static async decode(
Expand Down
Loading