From ca37546cce1de4eb2b0063ffde6a28d6613158e8 Mon Sep 17 00:00:00 2001 From: Jhen-Jie Hong Date: Thu, 21 Nov 2024 10:31:21 +0800 Subject: [PATCH] feat: check context is predicting --- android/src/main/java/com/rnllama/RNLlama.java | 6 ++++++ ios/RNLlama.mm | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/android/src/main/java/com/rnllama/RNLlama.java b/android/src/main/java/com/rnllama/RNLlama.java index 4dfa249..ab98a92 100644 --- a/android/src/main/java/com/rnllama/RNLlama.java +++ b/android/src/main/java/com/rnllama/RNLlama.java @@ -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; @@ -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; diff --git a/ios/RNLlama.mm b/ios/RNLlama.mm index de3edca..9c6b848 100644 --- a/ios/RNLlama.mm +++ b/ios/RNLlama.mm @@ -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); } @@ -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); }