Skip to content

Commit

Permalink
feat: default context limit to unlimited
Browse files Browse the repository at this point in the history
  • Loading branch information
jhen0409 committed Jan 24, 2025
1 parent 34b377a commit 3f88f6e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion android/src/main/java/com/rnllama/RNLlama.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public RNLlama(ReactApplicationContext reactContext) {

private HashMap<Integer, LlamaContext> contexts = new HashMap<>();

private int llamaContextLimit = 1;
private int llamaContextLimit = -1;

public void setContextLimit(double limit, Promise promise) {
llamaContextLimit = (int) limit;
Expand Down Expand Up @@ -83,6 +83,9 @@ protected WritableMap doInBackground(Void... voids) {
if (context != null) {
throw new Exception("Context already exists");
}
if (llamaContextLimit > -1 && contexts.size() >= llamaContextLimit) {
throw new Exception("Context limit reached");
}
LlamaContext llamaContext = new LlamaContext(contextId, reactContext, params);
if (llamaContext.getContext() == 0) {
throw new Exception("Failed to initialize context");
Expand Down
4 changes: 2 additions & 2 deletions ios/RNLlama.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@implementation RNLlama

NSMutableDictionary *llamaContexts;
double llamaContextLimit = 1;
double llamaContextLimit = -1;
dispatch_queue_t llamaDQueue;

RCT_EXPORT_MODULE()
Expand Down Expand Up @@ -48,7 +48,7 @@ @implementation RNLlama
llamaContexts = [[NSMutableDictionary alloc] init];
}

if (llamaContextLimit > 0 && [llamaContexts count] >= llamaContextLimit) {
if (llamaContextLimit > -1 && [llamaContexts count] >= llamaContextLimit) {
reject(@"llama_error", @"Context limit reached", nil);
return;
}
Expand Down

0 comments on commit 3f88f6e

Please sign in to comment.