Skip to content

Commit 005dbf8

Browse files
authored
fix: model loading and deleting logic inside useLLM hook (#404)
## Description Move try/catch inside async function, delete model only when preventLoad is set to false. ### Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Documentation update (improves or adds clarity to existing documentation) ### Tested on - [x] iOS - [ ] Android ### Checklist - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have updated the documentation accordingly - [x] My changes generate no new warnings
1 parent 62f7d70 commit 005dbf8

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

  • packages/react-native-executorch/src/hooks/natural_language_processing

packages/react-native-executorch/src/hooks/natural_language_processing/useLLM.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,19 @@ export const useLLM = ({
4646
setDownloadProgress(0);
4747
setError(null);
4848

49-
if (!preventLoad) {
49+
if (preventLoad) return;
50+
51+
(async () => {
5052
try {
51-
(async () => {
52-
await model.load({
53-
modelSource,
54-
tokenizerSource,
55-
tokenizerConfigSource,
56-
});
57-
})();
53+
await model.load({
54+
modelSource,
55+
tokenizerSource,
56+
tokenizerConfigSource,
57+
});
5858
} catch (e) {
5959
setError(e);
6060
}
61-
}
61+
})();
6262

6363
return () => {
6464
model.delete();

0 commit comments

Comments
 (0)