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
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ export class LLMController {
);
}
this.onToken = () => {};
this.nativeModule.unload();
if (this.nativeModule) {
this.nativeModule.unload();
}
this.isReadyCallback(false);
this.isGeneratingCallback(false);
}
Expand Down Expand Up @@ -245,10 +247,22 @@ export class LLMController {
}

public interrupt() {
if (!this.nativeModule) {
throw new RnExecutorchError(
RnExecutorchErrorCode.ModuleNotLoaded,
"Cannot interrupt a model that's not loaded."
);
}
this.nativeModule.interrupt();
}

public getGeneratedTokenCount(): number {
if (!this.nativeModule) {
throw new RnExecutorchError(
RnExecutorchErrorCode.ModuleNotLoaded,
"Cannot get token count for a model that's not loaded."
);
}
return this.nativeModule.getGeneratedTokenCount();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ export class OCRController {
'The model is currently generating. Please wait until previous model run is complete.'
);
}
this.nativeModule.unload();
if (this.nativeModule) {
this.nativeModule.unload();
}
this.isReadyCallback(false);
this.isGeneratingCallback(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ export class VerticalOCRController {
'The model is currently generating. Please wait until previous model run is complete.'
);
}
this.ocrNativeModule.unload();
if (this.ocrNativeModule) {
this.ocrNativeModule.unload();
}
this.isReadyCallback(false);
this.isGeneratingCallback(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ export const useLLM = ({
})();

return () => {
controllerInstance.delete();
if (controllerInstance.isReady) {
controllerInstance.delete();
}
};
}, [
controllerInstance,
Expand Down
Loading