Skip to content

Commit

Permalink
feat: check context is predicting
Browse files Browse the repository at this point in the history
  • Loading branch information
jhen0409 committed Nov 21, 2024
1 parent 1569797 commit ca37546
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions android/src/main/java/com/rnllama/RNLlama.java
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,9 @@ protected Void doInBackground(Void... voids) {
if (context == null) {
throw new Exception("Context not found");
}
if (context.isPredicting()) {
throw new Exception("Context is busy");
}
context.applyLoraAdapters(loraAdapters);
} catch (Exception e) {
exception = e;
Expand Down Expand Up @@ -455,6 +458,9 @@ protected Void doInBackground(Void... voids) {
if (context == null) {
throw new Exception("Context not found");
}
if (context.isPredicting()) {
throw new Exception("Context is busy");
}
context.removeLoraAdapters();
} catch (Exception e) {
exception = e;
Expand Down
8 changes: 8 additions & 0 deletions ios/RNLlama.mm
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ - (NSArray *)supportedEvents {
reject(@"llama_error", @"Context not found", nil);
return;
}
if ([context isPredicting]) {
reject(@"llama_error", @"Context is busy", nil);
return;
}
[context applyLoraAdapters:loraAdapters];
resolve(nil);
}
Expand All @@ -294,6 +298,10 @@ - (NSArray *)supportedEvents {
reject(@"llama_error", @"Context not found", nil);
return;
}
if ([context isPredicting]) {
reject(@"llama_error", @"Context is busy", nil);
return;
}
[context removeLoraAdapters];
resolve(nil);
}
Expand Down

0 comments on commit ca37546

Please sign in to comment.