cactus-react-native 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/android/src/main/java/com/cactus/Cactus.java +35 -0
- package/android/src/main/java/com/cactus/LlamaContext.java +18 -1
- package/android/src/main/jni.cpp +11 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_v8.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2_dotprod.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2_dotprod_i8mm.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2_i8mm.so +0 -0
- package/android/src/newarch/java/com/cactus/CactusModule.java +5 -0
- package/android/src/oldarch/java/com/cactus/CactusModule.java +5 -0
- package/ios/Cactus.mm +21 -0
- package/ios/CactusContext.h +1 -0
- package/ios/CactusContext.mm +4 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_ffi.h +0 -12
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/cactus +0 -0
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/cactus_ffi.h +0 -12
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/cactus +0 -0
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/cactus_ffi.h +0 -12
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/cactus +0 -0
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/cactus_ffi.h +0 -12
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/cactus +0 -0
- package/lib/commonjs/NativeCactus.js +0 -1
- package/lib/commonjs/NativeCactus.js.map +1 -1
- package/lib/commonjs/chat.js +33 -0
- package/lib/commonjs/chat.js.map +1 -1
- package/lib/commonjs/index.js +0 -23
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/lm.js +69 -32
- package/lib/commonjs/lm.js.map +1 -1
- package/lib/commonjs/tools.js +0 -7
- package/lib/commonjs/tools.js.map +1 -1
- package/lib/commonjs/tts.js +1 -4
- package/lib/commonjs/tts.js.map +1 -1
- package/lib/commonjs/vlm.js +25 -7
- package/lib/commonjs/vlm.js.map +1 -1
- package/lib/module/NativeCactus.js +0 -3
- package/lib/module/NativeCactus.js.map +1 -1
- package/lib/module/chat.js +31 -0
- package/lib/module/chat.js.map +1 -1
- package/lib/module/index.js +1 -10
- package/lib/module/index.js.map +1 -1
- package/lib/module/lm.js +70 -32
- package/lib/module/lm.js.map +1 -1
- package/lib/module/tools.js +0 -7
- package/lib/module/tools.js.map +1 -1
- package/lib/module/tts.js +1 -4
- package/lib/module/tts.js.map +1 -1
- package/lib/module/vlm.js +25 -7
- package/lib/module/vlm.js.map +1 -1
- package/lib/typescript/NativeCactus.d.ts +1 -142
- package/lib/typescript/NativeCactus.d.ts.map +1 -1
- package/lib/typescript/chat.d.ts +10 -0
- package/lib/typescript/chat.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +2 -4
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/lm.d.ts +13 -7
- package/lib/typescript/lm.d.ts.map +1 -1
- package/lib/typescript/tools.d.ts.map +1 -1
- package/lib/typescript/tts.d.ts.map +1 -1
- package/lib/typescript/vlm.d.ts +3 -1
- package/lib/typescript/vlm.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/NativeCactus.ts +6 -175
- package/src/chat.ts +42 -1
- package/src/index.ts +6 -17
- package/src/lm.ts +81 -26
- package/src/tools.ts +0 -5
- package/src/tts.ts +1 -4
- package/src/vlm.ts +35 -13
- package/android/src/main/jniLibs/x86_64/libcactus.so +0 -0
- package/android/src/main/jniLibs/x86_64/libcactus_x86_64.so +0 -0
- package/lib/commonjs/grammar.js +0 -560
- package/lib/commonjs/grammar.js.map +0 -1
- package/lib/module/grammar.js +0 -553
- package/lib/module/grammar.js.map +0 -1
- package/lib/typescript/grammar.d.ts +0 -37
- package/lib/typescript/grammar.d.ts.map +0 -1
- package/src/grammar.ts +0 -854
package/README.md
CHANGED
|
@@ -598,6 +598,41 @@ public class Cactus implements LifecycleEventListener {
|
|
|
598
598
|
tasks.put(task, "getLoadedLoraAdapters-" + contextId);
|
|
599
599
|
}
|
|
600
600
|
|
|
601
|
+
public void rewind(double id, Promise promise) {
|
|
602
|
+
final int contextId = (int) id;
|
|
603
|
+
AsyncTask task = new AsyncTask<Void, Void, Void>() {
|
|
604
|
+
private Exception exception;
|
|
605
|
+
|
|
606
|
+
@Override
|
|
607
|
+
protected Void doInBackground(Void... voids) {
|
|
608
|
+
try {
|
|
609
|
+
LlamaContext context = contexts.get(contextId);
|
|
610
|
+
if (context == null) {
|
|
611
|
+
throw new Exception("Context not found");
|
|
612
|
+
}
|
|
613
|
+
if (context.isPredicting()) {
|
|
614
|
+
throw new Exception("Context is busy");
|
|
615
|
+
}
|
|
616
|
+
context.rewind();
|
|
617
|
+
} catch (Exception e) {
|
|
618
|
+
exception = e;
|
|
619
|
+
}
|
|
620
|
+
return null;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
@Override
|
|
624
|
+
protected void onPostExecute(Void result) {
|
|
625
|
+
if (exception != null) {
|
|
626
|
+
promise.reject(exception);
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
promise.resolve(null);
|
|
630
|
+
tasks.remove(this);
|
|
631
|
+
}
|
|
632
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
633
|
+
tasks.put(task, "rewind-" + contextId);
|
|
634
|
+
}
|
|
635
|
+
|
|
601
636
|
public void releaseContext(double id, Promise promise) {
|
|
602
637
|
final int contextId = (int) id;
|
|
603
638
|
AsyncTask task = new AsyncTask<Void, Void, Void>() {
|
|
@@ -64,6 +64,17 @@ public class LlamaContext {
|
|
|
64
64
|
if (!params.hasKey("model")) {
|
|
65
65
|
throw new IllegalArgumentException("Missing required parameter: model");
|
|
66
66
|
}
|
|
67
|
+
|
|
68
|
+
String modelPath = params.getString("model");
|
|
69
|
+
File modelFile = new File(modelPath);
|
|
70
|
+
if (!modelFile.exists()) {
|
|
71
|
+
Log.e(NAME, "Model file does not exist: " + modelPath);
|
|
72
|
+
throw new IllegalArgumentException("Model file does not exist: " + modelPath);
|
|
73
|
+
}
|
|
74
|
+
if (!modelFile.canRead()) {
|
|
75
|
+
Log.e(NAME, "Model file is not readable: " + modelPath);
|
|
76
|
+
throw new IllegalArgumentException("Model file is not readable: " + modelPath);
|
|
77
|
+
}
|
|
67
78
|
eventEmitter = reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class);
|
|
68
79
|
this.id = id;
|
|
69
80
|
this.context = initContext(
|
|
@@ -115,7 +126,8 @@ public class LlamaContext {
|
|
|
115
126
|
params.hasKey("use_progress_callback") ? new LoadProgressCallback(this) : null
|
|
116
127
|
);
|
|
117
128
|
if (this.context == -1) {
|
|
118
|
-
throw new IllegalStateException("Failed to initialize context"
|
|
129
|
+
throw new IllegalStateException("Failed to initialize context for model: " + modelPath +
|
|
130
|
+
". Please check if the model file exists and is accessible.");
|
|
119
131
|
}
|
|
120
132
|
this.modelDetails = loadModelDetails(this.context);
|
|
121
133
|
this.reactContext = reactContext;
|
|
@@ -386,6 +398,10 @@ public class LlamaContext {
|
|
|
386
398
|
return getLoadedLoraAdapters(this.context);
|
|
387
399
|
}
|
|
388
400
|
|
|
401
|
+
public void rewind() {
|
|
402
|
+
rewind(this.context);
|
|
403
|
+
}
|
|
404
|
+
|
|
389
405
|
public void release() {
|
|
390
406
|
freeContext(context);
|
|
391
407
|
}
|
|
@@ -735,6 +751,7 @@ public class LlamaContext {
|
|
|
735
751
|
protected static native int applyLoraAdapters(long contextPtr, ReadableArray loraAdapters);
|
|
736
752
|
protected static native void removeLoraAdapters(long contextPtr);
|
|
737
753
|
protected static native WritableArray getLoadedLoraAdapters(long contextPtr);
|
|
754
|
+
protected static native void rewind(long contextPtr);
|
|
738
755
|
protected static native void freeContext(long contextPtr);
|
|
739
756
|
protected static native void setupLog(NativeLogCallback logCallback);
|
|
740
757
|
protected static native void unsetLog();
|
package/android/src/main/jni.cpp
CHANGED
|
@@ -1359,6 +1359,17 @@ Java_com_cactus_LlamaContext_getLoadedLoraAdapters(
|
|
|
1359
1359
|
return result;
|
|
1360
1360
|
}
|
|
1361
1361
|
|
|
1362
|
+
JNIEXPORT void JNICALL
|
|
1363
|
+
Java_com_cactus_LlamaContext_rewind(
|
|
1364
|
+
JNIEnv *env, jobject thiz, jlong context_ptr) {
|
|
1365
|
+
UNUSED(env);
|
|
1366
|
+
UNUSED(thiz);
|
|
1367
|
+
auto llama = context_map[(long) context_ptr];
|
|
1368
|
+
if (llama != nullptr) {
|
|
1369
|
+
llama->rewind();
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1362
1373
|
JNIEXPORT void JNICALL
|
|
1363
1374
|
Java_com_cactus_LlamaContext_freeContext(
|
|
1364
1375
|
JNIEnv *env, jobject thiz, jlong context_ptr) {
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -189,6 +189,11 @@ public class CactusModule extends NativeCactusSpec {
|
|
|
189
189
|
cactus.releaseVocoder(id, promise);
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
+
@ReactMethod
|
|
193
|
+
public void rewind(double id, Promise promise) {
|
|
194
|
+
cactus.rewind(id, promise);
|
|
195
|
+
}
|
|
196
|
+
|
|
192
197
|
@ReactMethod
|
|
193
198
|
public void releaseContext(double id, Promise promise) {
|
|
194
199
|
cactus.releaseContext(id, promise);
|
|
@@ -188,6 +188,11 @@ public class CactusModule extends ReactContextBaseJavaModule {
|
|
|
188
188
|
cactus.releaseVocoder(id, promise);
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
+
@ReactMethod
|
|
192
|
+
public void rewind(double id, Promise promise) {
|
|
193
|
+
cactus.rewind(id, promise);
|
|
194
|
+
}
|
|
195
|
+
|
|
191
196
|
@ReactMethod
|
|
192
197
|
public void releaseContext(double id, Promise promise) {
|
|
193
198
|
cactus.releaseContext(id, promise);
|
package/ios/Cactus.mm
CHANGED
|
@@ -473,6 +473,27 @@ RCT_EXPORT_METHOD(multimodalCompletion:(double)contextId
|
|
|
473
473
|
});
|
|
474
474
|
}
|
|
475
475
|
|
|
476
|
+
RCT_EXPORT_METHOD(rewind:(double)contextId
|
|
477
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
478
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
479
|
+
{
|
|
480
|
+
CactusContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
|
|
481
|
+
if (context == nil) {
|
|
482
|
+
reject(@"llama_error", @"Context not found", nil);
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
if ([context isPredicting]) {
|
|
486
|
+
reject(@"llama_error", @"Context is busy", nil);
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
@try {
|
|
490
|
+
[context rewind];
|
|
491
|
+
resolve(nil);
|
|
492
|
+
} @catch (NSException *exception) {
|
|
493
|
+
reject(@"llama_cpp_error", exception.reason, nil);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
476
497
|
RCT_EXPORT_METHOD(releaseContext:(double)contextId
|
|
477
498
|
withResolver:(RCTPromiseResolveBlock)resolve
|
|
478
499
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
package/ios/CactusContext.h
CHANGED
package/ios/CactusContext.mm
CHANGED
|
@@ -182,7 +182,6 @@ CACTUS_FFI_EXPORT cactus_float_array_c_t cactus_decode_audio_tokens_c(cactus_con
|
|
|
182
182
|
|
|
183
183
|
CACTUS_FFI_EXPORT void cactus_release_vocoder_c(cactus_context_handle_t handle);
|
|
184
184
|
|
|
185
|
-
// **HIGH PRIORITY ADDITIONS**
|
|
186
185
|
|
|
187
186
|
typedef struct {
|
|
188
187
|
const char* path;
|
|
@@ -204,19 +203,13 @@ typedef struct {
|
|
|
204
203
|
double tg_std;
|
|
205
204
|
} cactus_bench_result_c_t;
|
|
206
205
|
|
|
207
|
-
// **HIGH PRIORITY: Benchmarking**
|
|
208
206
|
CACTUS_FFI_EXPORT cactus_bench_result_c_t cactus_bench_c(cactus_context_handle_t handle, int pp, int tg, int pl, int nr);
|
|
209
|
-
|
|
210
|
-
// **HIGH PRIORITY: LoRA Adapter Support**
|
|
211
207
|
CACTUS_FFI_EXPORT int cactus_apply_lora_adapters_c(cactus_context_handle_t handle, const cactus_lora_adapters_c_t* adapters);
|
|
212
208
|
CACTUS_FFI_EXPORT void cactus_remove_lora_adapters_c(cactus_context_handle_t handle);
|
|
213
209
|
CACTUS_FFI_EXPORT cactus_lora_adapters_c_t cactus_get_loaded_lora_adapters_c(cactus_context_handle_t handle);
|
|
214
|
-
|
|
215
|
-
// **HIGH PRIORITY: Chat Template Support**
|
|
216
210
|
CACTUS_FFI_EXPORT bool cactus_validate_chat_template_c(cactus_context_handle_t handle, bool use_jinja, const char* name);
|
|
217
211
|
CACTUS_FFI_EXPORT char* cactus_get_formatted_chat_c(cactus_context_handle_t handle, const char* messages, const char* chat_template);
|
|
218
212
|
|
|
219
|
-
// **ADVANCED: Chat with Jinja and Tools Support**
|
|
220
213
|
typedef struct {
|
|
221
214
|
char* prompt;
|
|
222
215
|
char* json_schema;
|
|
@@ -235,28 +228,23 @@ CACTUS_FFI_EXPORT cactus_chat_result_c_t cactus_get_formatted_chat_with_jinja_c(
|
|
|
235
228
|
const char* tool_choice
|
|
236
229
|
);
|
|
237
230
|
|
|
238
|
-
// **HIGH PRIORITY: Context Management**
|
|
239
231
|
CACTUS_FFI_EXPORT void cactus_rewind_c(cactus_context_handle_t handle);
|
|
240
232
|
CACTUS_FFI_EXPORT bool cactus_init_sampling_c(cactus_context_handle_t handle);
|
|
241
233
|
|
|
242
|
-
// **COMPLETION CONTROL**
|
|
243
234
|
CACTUS_FFI_EXPORT void cactus_begin_completion_c(cactus_context_handle_t handle);
|
|
244
235
|
CACTUS_FFI_EXPORT void cactus_end_completion_c(cactus_context_handle_t handle);
|
|
245
236
|
CACTUS_FFI_EXPORT void cactus_load_prompt_c(cactus_context_handle_t handle);
|
|
246
237
|
CACTUS_FFI_EXPORT void cactus_load_prompt_with_media_c(cactus_context_handle_t handle, const char** media_paths, int media_count);
|
|
247
238
|
|
|
248
|
-
// **TOKEN PROCESSING**
|
|
249
239
|
CACTUS_FFI_EXPORT int cactus_do_completion_step_c(cactus_context_handle_t handle, char** token_text);
|
|
250
240
|
CACTUS_FFI_EXPORT size_t cactus_find_stopping_strings_c(cactus_context_handle_t handle, const char* text, size_t last_token_size, int stop_type);
|
|
251
241
|
|
|
252
|
-
// **HIGH PRIORITY: Model Information**
|
|
253
242
|
CACTUS_FFI_EXPORT int32_t cactus_get_n_ctx_c(cactus_context_handle_t handle);
|
|
254
243
|
CACTUS_FFI_EXPORT int32_t cactus_get_n_embd_c(cactus_context_handle_t handle);
|
|
255
244
|
CACTUS_FFI_EXPORT char* cactus_get_model_desc_c(cactus_context_handle_t handle);
|
|
256
245
|
CACTUS_FFI_EXPORT int64_t cactus_get_model_size_c(cactus_context_handle_t handle);
|
|
257
246
|
CACTUS_FFI_EXPORT int64_t cactus_get_model_params_c(cactus_context_handle_t handle);
|
|
258
247
|
|
|
259
|
-
// Memory management functions
|
|
260
248
|
CACTUS_FFI_EXPORT void cactus_free_bench_result_members_c(cactus_bench_result_c_t* result);
|
|
261
249
|
CACTUS_FFI_EXPORT void cactus_free_lora_adapters_c(cactus_lora_adapters_c_t* adapters);
|
|
262
250
|
CACTUS_FFI_EXPORT void cactus_free_chat_result_members_c(cactus_chat_result_c_t* result);
|
|
Binary file
|
package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/cactus_ffi.h
CHANGED
|
@@ -182,7 +182,6 @@ CACTUS_FFI_EXPORT cactus_float_array_c_t cactus_decode_audio_tokens_c(cactus_con
|
|
|
182
182
|
|
|
183
183
|
CACTUS_FFI_EXPORT void cactus_release_vocoder_c(cactus_context_handle_t handle);
|
|
184
184
|
|
|
185
|
-
// **HIGH PRIORITY ADDITIONS**
|
|
186
185
|
|
|
187
186
|
typedef struct {
|
|
188
187
|
const char* path;
|
|
@@ -204,19 +203,13 @@ typedef struct {
|
|
|
204
203
|
double tg_std;
|
|
205
204
|
} cactus_bench_result_c_t;
|
|
206
205
|
|
|
207
|
-
// **HIGH PRIORITY: Benchmarking**
|
|
208
206
|
CACTUS_FFI_EXPORT cactus_bench_result_c_t cactus_bench_c(cactus_context_handle_t handle, int pp, int tg, int pl, int nr);
|
|
209
|
-
|
|
210
|
-
// **HIGH PRIORITY: LoRA Adapter Support**
|
|
211
207
|
CACTUS_FFI_EXPORT int cactus_apply_lora_adapters_c(cactus_context_handle_t handle, const cactus_lora_adapters_c_t* adapters);
|
|
212
208
|
CACTUS_FFI_EXPORT void cactus_remove_lora_adapters_c(cactus_context_handle_t handle);
|
|
213
209
|
CACTUS_FFI_EXPORT cactus_lora_adapters_c_t cactus_get_loaded_lora_adapters_c(cactus_context_handle_t handle);
|
|
214
|
-
|
|
215
|
-
// **HIGH PRIORITY: Chat Template Support**
|
|
216
210
|
CACTUS_FFI_EXPORT bool cactus_validate_chat_template_c(cactus_context_handle_t handle, bool use_jinja, const char* name);
|
|
217
211
|
CACTUS_FFI_EXPORT char* cactus_get_formatted_chat_c(cactus_context_handle_t handle, const char* messages, const char* chat_template);
|
|
218
212
|
|
|
219
|
-
// **ADVANCED: Chat with Jinja and Tools Support**
|
|
220
213
|
typedef struct {
|
|
221
214
|
char* prompt;
|
|
222
215
|
char* json_schema;
|
|
@@ -235,28 +228,23 @@ CACTUS_FFI_EXPORT cactus_chat_result_c_t cactus_get_formatted_chat_with_jinja_c(
|
|
|
235
228
|
const char* tool_choice
|
|
236
229
|
);
|
|
237
230
|
|
|
238
|
-
// **HIGH PRIORITY: Context Management**
|
|
239
231
|
CACTUS_FFI_EXPORT void cactus_rewind_c(cactus_context_handle_t handle);
|
|
240
232
|
CACTUS_FFI_EXPORT bool cactus_init_sampling_c(cactus_context_handle_t handle);
|
|
241
233
|
|
|
242
|
-
// **COMPLETION CONTROL**
|
|
243
234
|
CACTUS_FFI_EXPORT void cactus_begin_completion_c(cactus_context_handle_t handle);
|
|
244
235
|
CACTUS_FFI_EXPORT void cactus_end_completion_c(cactus_context_handle_t handle);
|
|
245
236
|
CACTUS_FFI_EXPORT void cactus_load_prompt_c(cactus_context_handle_t handle);
|
|
246
237
|
CACTUS_FFI_EXPORT void cactus_load_prompt_with_media_c(cactus_context_handle_t handle, const char** media_paths, int media_count);
|
|
247
238
|
|
|
248
|
-
// **TOKEN PROCESSING**
|
|
249
239
|
CACTUS_FFI_EXPORT int cactus_do_completion_step_c(cactus_context_handle_t handle, char** token_text);
|
|
250
240
|
CACTUS_FFI_EXPORT size_t cactus_find_stopping_strings_c(cactus_context_handle_t handle, const char* text, size_t last_token_size, int stop_type);
|
|
251
241
|
|
|
252
|
-
// **HIGH PRIORITY: Model Information**
|
|
253
242
|
CACTUS_FFI_EXPORT int32_t cactus_get_n_ctx_c(cactus_context_handle_t handle);
|
|
254
243
|
CACTUS_FFI_EXPORT int32_t cactus_get_n_embd_c(cactus_context_handle_t handle);
|
|
255
244
|
CACTUS_FFI_EXPORT char* cactus_get_model_desc_c(cactus_context_handle_t handle);
|
|
256
245
|
CACTUS_FFI_EXPORT int64_t cactus_get_model_size_c(cactus_context_handle_t handle);
|
|
257
246
|
CACTUS_FFI_EXPORT int64_t cactus_get_model_params_c(cactus_context_handle_t handle);
|
|
258
247
|
|
|
259
|
-
// Memory management functions
|
|
260
248
|
CACTUS_FFI_EXPORT void cactus_free_bench_result_members_c(cactus_bench_result_c_t* result);
|
|
261
249
|
CACTUS_FFI_EXPORT void cactus_free_lora_adapters_c(cactus_lora_adapters_c_t* adapters);
|
|
262
250
|
CACTUS_FFI_EXPORT void cactus_free_chat_result_members_c(cactus_chat_result_c_t* result);
|
|
Binary file
|
|
@@ -182,7 +182,6 @@ CACTUS_FFI_EXPORT cactus_float_array_c_t cactus_decode_audio_tokens_c(cactus_con
|
|
|
182
182
|
|
|
183
183
|
CACTUS_FFI_EXPORT void cactus_release_vocoder_c(cactus_context_handle_t handle);
|
|
184
184
|
|
|
185
|
-
// **HIGH PRIORITY ADDITIONS**
|
|
186
185
|
|
|
187
186
|
typedef struct {
|
|
188
187
|
const char* path;
|
|
@@ -204,19 +203,13 @@ typedef struct {
|
|
|
204
203
|
double tg_std;
|
|
205
204
|
} cactus_bench_result_c_t;
|
|
206
205
|
|
|
207
|
-
// **HIGH PRIORITY: Benchmarking**
|
|
208
206
|
CACTUS_FFI_EXPORT cactus_bench_result_c_t cactus_bench_c(cactus_context_handle_t handle, int pp, int tg, int pl, int nr);
|
|
209
|
-
|
|
210
|
-
// **HIGH PRIORITY: LoRA Adapter Support**
|
|
211
207
|
CACTUS_FFI_EXPORT int cactus_apply_lora_adapters_c(cactus_context_handle_t handle, const cactus_lora_adapters_c_t* adapters);
|
|
212
208
|
CACTUS_FFI_EXPORT void cactus_remove_lora_adapters_c(cactus_context_handle_t handle);
|
|
213
209
|
CACTUS_FFI_EXPORT cactus_lora_adapters_c_t cactus_get_loaded_lora_adapters_c(cactus_context_handle_t handle);
|
|
214
|
-
|
|
215
|
-
// **HIGH PRIORITY: Chat Template Support**
|
|
216
210
|
CACTUS_FFI_EXPORT bool cactus_validate_chat_template_c(cactus_context_handle_t handle, bool use_jinja, const char* name);
|
|
217
211
|
CACTUS_FFI_EXPORT char* cactus_get_formatted_chat_c(cactus_context_handle_t handle, const char* messages, const char* chat_template);
|
|
218
212
|
|
|
219
|
-
// **ADVANCED: Chat with Jinja and Tools Support**
|
|
220
213
|
typedef struct {
|
|
221
214
|
char* prompt;
|
|
222
215
|
char* json_schema;
|
|
@@ -235,28 +228,23 @@ CACTUS_FFI_EXPORT cactus_chat_result_c_t cactus_get_formatted_chat_with_jinja_c(
|
|
|
235
228
|
const char* tool_choice
|
|
236
229
|
);
|
|
237
230
|
|
|
238
|
-
// **HIGH PRIORITY: Context Management**
|
|
239
231
|
CACTUS_FFI_EXPORT void cactus_rewind_c(cactus_context_handle_t handle);
|
|
240
232
|
CACTUS_FFI_EXPORT bool cactus_init_sampling_c(cactus_context_handle_t handle);
|
|
241
233
|
|
|
242
|
-
// **COMPLETION CONTROL**
|
|
243
234
|
CACTUS_FFI_EXPORT void cactus_begin_completion_c(cactus_context_handle_t handle);
|
|
244
235
|
CACTUS_FFI_EXPORT void cactus_end_completion_c(cactus_context_handle_t handle);
|
|
245
236
|
CACTUS_FFI_EXPORT void cactus_load_prompt_c(cactus_context_handle_t handle);
|
|
246
237
|
CACTUS_FFI_EXPORT void cactus_load_prompt_with_media_c(cactus_context_handle_t handle, const char** media_paths, int media_count);
|
|
247
238
|
|
|
248
|
-
// **TOKEN PROCESSING**
|
|
249
239
|
CACTUS_FFI_EXPORT int cactus_do_completion_step_c(cactus_context_handle_t handle, char** token_text);
|
|
250
240
|
CACTUS_FFI_EXPORT size_t cactus_find_stopping_strings_c(cactus_context_handle_t handle, const char* text, size_t last_token_size, int stop_type);
|
|
251
241
|
|
|
252
|
-
// **HIGH PRIORITY: Model Information**
|
|
253
242
|
CACTUS_FFI_EXPORT int32_t cactus_get_n_ctx_c(cactus_context_handle_t handle);
|
|
254
243
|
CACTUS_FFI_EXPORT int32_t cactus_get_n_embd_c(cactus_context_handle_t handle);
|
|
255
244
|
CACTUS_FFI_EXPORT char* cactus_get_model_desc_c(cactus_context_handle_t handle);
|
|
256
245
|
CACTUS_FFI_EXPORT int64_t cactus_get_model_size_c(cactus_context_handle_t handle);
|
|
257
246
|
CACTUS_FFI_EXPORT int64_t cactus_get_model_params_c(cactus_context_handle_t handle);
|
|
258
247
|
|
|
259
|
-
// Memory management functions
|
|
260
248
|
CACTUS_FFI_EXPORT void cactus_free_bench_result_members_c(cactus_bench_result_c_t* result);
|
|
261
249
|
CACTUS_FFI_EXPORT void cactus_free_lora_adapters_c(cactus_lora_adapters_c_t* adapters);
|
|
262
250
|
CACTUS_FFI_EXPORT void cactus_free_chat_result_members_c(cactus_chat_result_c_t* result);
|
|
Binary file
|
package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/cactus_ffi.h
CHANGED
|
@@ -182,7 +182,6 @@ CACTUS_FFI_EXPORT cactus_float_array_c_t cactus_decode_audio_tokens_c(cactus_con
|
|
|
182
182
|
|
|
183
183
|
CACTUS_FFI_EXPORT void cactus_release_vocoder_c(cactus_context_handle_t handle);
|
|
184
184
|
|
|
185
|
-
// **HIGH PRIORITY ADDITIONS**
|
|
186
185
|
|
|
187
186
|
typedef struct {
|
|
188
187
|
const char* path;
|
|
@@ -204,19 +203,13 @@ typedef struct {
|
|
|
204
203
|
double tg_std;
|
|
205
204
|
} cactus_bench_result_c_t;
|
|
206
205
|
|
|
207
|
-
// **HIGH PRIORITY: Benchmarking**
|
|
208
206
|
CACTUS_FFI_EXPORT cactus_bench_result_c_t cactus_bench_c(cactus_context_handle_t handle, int pp, int tg, int pl, int nr);
|
|
209
|
-
|
|
210
|
-
// **HIGH PRIORITY: LoRA Adapter Support**
|
|
211
207
|
CACTUS_FFI_EXPORT int cactus_apply_lora_adapters_c(cactus_context_handle_t handle, const cactus_lora_adapters_c_t* adapters);
|
|
212
208
|
CACTUS_FFI_EXPORT void cactus_remove_lora_adapters_c(cactus_context_handle_t handle);
|
|
213
209
|
CACTUS_FFI_EXPORT cactus_lora_adapters_c_t cactus_get_loaded_lora_adapters_c(cactus_context_handle_t handle);
|
|
214
|
-
|
|
215
|
-
// **HIGH PRIORITY: Chat Template Support**
|
|
216
210
|
CACTUS_FFI_EXPORT bool cactus_validate_chat_template_c(cactus_context_handle_t handle, bool use_jinja, const char* name);
|
|
217
211
|
CACTUS_FFI_EXPORT char* cactus_get_formatted_chat_c(cactus_context_handle_t handle, const char* messages, const char* chat_template);
|
|
218
212
|
|
|
219
|
-
// **ADVANCED: Chat with Jinja and Tools Support**
|
|
220
213
|
typedef struct {
|
|
221
214
|
char* prompt;
|
|
222
215
|
char* json_schema;
|
|
@@ -235,28 +228,23 @@ CACTUS_FFI_EXPORT cactus_chat_result_c_t cactus_get_formatted_chat_with_jinja_c(
|
|
|
235
228
|
const char* tool_choice
|
|
236
229
|
);
|
|
237
230
|
|
|
238
|
-
// **HIGH PRIORITY: Context Management**
|
|
239
231
|
CACTUS_FFI_EXPORT void cactus_rewind_c(cactus_context_handle_t handle);
|
|
240
232
|
CACTUS_FFI_EXPORT bool cactus_init_sampling_c(cactus_context_handle_t handle);
|
|
241
233
|
|
|
242
|
-
// **COMPLETION CONTROL**
|
|
243
234
|
CACTUS_FFI_EXPORT void cactus_begin_completion_c(cactus_context_handle_t handle);
|
|
244
235
|
CACTUS_FFI_EXPORT void cactus_end_completion_c(cactus_context_handle_t handle);
|
|
245
236
|
CACTUS_FFI_EXPORT void cactus_load_prompt_c(cactus_context_handle_t handle);
|
|
246
237
|
CACTUS_FFI_EXPORT void cactus_load_prompt_with_media_c(cactus_context_handle_t handle, const char** media_paths, int media_count);
|
|
247
238
|
|
|
248
|
-
// **TOKEN PROCESSING**
|
|
249
239
|
CACTUS_FFI_EXPORT int cactus_do_completion_step_c(cactus_context_handle_t handle, char** token_text);
|
|
250
240
|
CACTUS_FFI_EXPORT size_t cactus_find_stopping_strings_c(cactus_context_handle_t handle, const char* text, size_t last_token_size, int stop_type);
|
|
251
241
|
|
|
252
|
-
// **HIGH PRIORITY: Model Information**
|
|
253
242
|
CACTUS_FFI_EXPORT int32_t cactus_get_n_ctx_c(cactus_context_handle_t handle);
|
|
254
243
|
CACTUS_FFI_EXPORT int32_t cactus_get_n_embd_c(cactus_context_handle_t handle);
|
|
255
244
|
CACTUS_FFI_EXPORT char* cactus_get_model_desc_c(cactus_context_handle_t handle);
|
|
256
245
|
CACTUS_FFI_EXPORT int64_t cactus_get_model_size_c(cactus_context_handle_t handle);
|
|
257
246
|
CACTUS_FFI_EXPORT int64_t cactus_get_model_params_c(cactus_context_handle_t handle);
|
|
258
247
|
|
|
259
|
-
// Memory management functions
|
|
260
248
|
CACTUS_FFI_EXPORT void cactus_free_bench_result_members_c(cactus_bench_result_c_t* result);
|
|
261
249
|
CACTUS_FFI_EXPORT void cactus_free_lora_adapters_c(cactus_lora_adapters_c_t* adapters);
|
|
262
250
|
CACTUS_FFI_EXPORT void cactus_free_chat_result_members_c(cactus_chat_result_c_t* result);
|
|
Binary file
|
|
@@ -5,6 +5,5 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _reactNative = require("react-native");
|
|
8
|
-
// New TTS/Audio types
|
|
9
8
|
var _default = exports.default = _reactNative.TurboModuleRegistry.get('Cactus');
|
|
10
9
|
//# sourceMappingURL=NativeCactus.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","get"],"sourceRoot":"../../src","sources":["NativeCactus.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","get"],"sourceRoot":"../../src","sources":["NativeCactus.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAAkD,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GA2TnCC,gCAAmB,CAACC,GAAG,CAAO,QAAQ,CAAC","ignoreList":[]}
|
package/lib/commonjs/chat.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.ConversationHistoryManager = void 0;
|
|
6
7
|
exports.formatChat = formatChat;
|
|
7
8
|
function formatChat(messages) {
|
|
8
9
|
const chat = [];
|
|
@@ -34,4 +35,36 @@ function formatChat(messages) {
|
|
|
34
35
|
});
|
|
35
36
|
return chat;
|
|
36
37
|
}
|
|
38
|
+
class ConversationHistoryManager {
|
|
39
|
+
history = [];
|
|
40
|
+
processNewMessages(fullMessageHistory) {
|
|
41
|
+
let divergent = fullMessageHistory.length < this.history.length;
|
|
42
|
+
if (!divergent) {
|
|
43
|
+
for (let i = 0; i < this.history.length; i++) {
|
|
44
|
+
if (JSON.stringify(this.history[i]) !== JSON.stringify(fullMessageHistory[i])) {
|
|
45
|
+
divergent = true;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (divergent) {
|
|
51
|
+
return {
|
|
52
|
+
newMessages: fullMessageHistory,
|
|
53
|
+
requiresReset: true
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const newMessages = fullMessageHistory.slice(this.history.length);
|
|
57
|
+
return {
|
|
58
|
+
newMessages,
|
|
59
|
+
requiresReset: false
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
update(newMessages, assistantResponse) {
|
|
63
|
+
this.history.push(...newMessages, assistantResponse);
|
|
64
|
+
}
|
|
65
|
+
reset() {
|
|
66
|
+
this.history = [];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.ConversationHistoryManager = ConversationHistoryManager;
|
|
37
70
|
//# sourceMappingURL=chat.js.map
|
package/lib/commonjs/chat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["formatChat","messages","chat","forEach","currMsg","role","content","Array","isArray","part","text","TypeError","Error","push"],"sourceRoot":"../../src","sources":["chat.ts"],"mappings":"
|
|
1
|
+
{"version":3,"names":["formatChat","messages","chat","forEach","currMsg","role","content","Array","isArray","part","text","TypeError","Error","push","ConversationHistoryManager","history","processNewMessages","fullMessageHistory","divergent","length","i","JSON","stringify","newMessages","requiresReset","slice","update","assistantResponse","reset","exports"],"sourceRoot":"../../src","sources":["chat.ts"],"mappings":";;;;;;;AAWO,SAASA,UAAUA,CACxBC,QAAsC,EACZ;EAC1B,MAAMC,IAA8B,GAAG,EAAE;EAEzCD,QAAQ,CAACE,OAAO,CAAEC,OAAO,IAAK;IAC5B,MAAMC,IAAY,GAAGD,OAAO,CAACC,IAAI,IAAI,EAAE;IAEvC,IAAIC,OAAe,GAAG,EAAE;IACxB,IAAI,SAAS,IAAIF,OAAO,EAAE;MACxB,IAAI,OAAOA,OAAO,CAACE,OAAO,KAAK,QAAQ,EAAE;QACvC;QAAC,CAAC;UAAEA;QAAQ,CAAC,GAAGF,OAAO;MACzB,CAAC,MAAM,IAAIG,KAAK,CAACC,OAAO,CAACJ,OAAO,CAACE,OAAO,CAAC,EAAE;QACzCF,OAAO,CAACE,OAAO,CAACH,OAAO,CAAEM,IAAI,IAAK;UAChC,IAAI,MAAM,IAAIA,IAAI,EAAE;YAClBH,OAAO,IAAI,GAAGA,OAAO,GAAG,IAAI,GAAG,EAAE,GAAGG,IAAI,CAACC,IAAI,EAAE;UACjD;QACF,CAAC,CAAC;MACJ,CAAC,MAAM;QACL,MAAM,IAAIC,SAAS,CACjB,kFACF,CAAC;MACH;IACF,CAAC,MAAM;MACL,MAAM,IAAIC,KAAK,CACb,6EACF,CAAC;IACH;IAEAV,IAAI,CAACW,IAAI,CAAC;MAAER,IAAI;MAAEC;IAAQ,CAAC,CAAC;EAC9B,CAAC,CAAC;EACF,OAAOJ,IAAI;AACb;AAOO,MAAMY,0BAA0B,CAAC;EAC9BC,OAAO,GAAiC,EAAE;EAE3CC,kBAAkBA,CACvBC,kBAAgD,EAC7B;IACnB,IAAIC,SAAS,GAAGD,kBAAkB,CAACE,MAAM,GAAG,IAAI,CAACJ,OAAO,CAACI,MAAM;IAC/D,IAAI,CAACD,SAAS,EAAE;MACd,KAAK,IAAIE,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAG,IAAI,CAACL,OAAO,CAACI,MAAM,EAAEC,CAAC,EAAE,EAAE;QAC5C,IAAIC,IAAI,CAACC,SAAS,CAAC,IAAI,CAACP,OAAO,CAACK,CAAC,CAAC,CAAC,KAAKC,IAAI,CAACC,SAAS,CAACL,kBAAkB,CAACG,CAAC,CAAC,CAAC,EAAE;UAC7EF,SAAS,GAAG,IAAI;UAChB;QACF;MACF;IACF;IAEA,IAAIA,SAAS,EAAE;MACb,OAAO;QAAEK,WAAW,EAAEN,kBAAkB;QAAEO,aAAa,EAAE;MAAK,CAAC;IACjE;IAEA,MAAMD,WAAW,GAAGN,kBAAkB,CAACQ,KAAK,CAAC,IAAI,CAACV,OAAO,CAACI,MAAM,CAAC;IACjE,OAAO;MAAEI,WAAW;MAAEC,aAAa,EAAE;IAAM,CAAC;EAC9C;EAEOE,MAAMA,CACXH,WAAyC,EACzCI,iBAA6C,EAC7C;IACA,IAAI,CAACZ,OAAO,CAACF,IAAI,CAAC,GAAGU,WAAW,EAAEI,iBAAiB,CAAC;EACtD;EAEOC,KAAKA,CAAA,EAAG;IACb,IAAI,CAACb,OAAO,GAAG,EAAE;EACnB;AACF;AAACc,OAAA,CAAAf,0BAAA,GAAAA,0BAAA","ignoreList":[]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -27,8 +27,6 @@ var _exportNames = {
|
|
|
27
27
|
releaseVocoder: true,
|
|
28
28
|
tokenize: true,
|
|
29
29
|
getDeviceInfo: true,
|
|
30
|
-
SchemaGrammarConverter: true,
|
|
31
|
-
convertJsonSchemaToGrammar: true,
|
|
32
30
|
Tools: true,
|
|
33
31
|
CactusLM: true,
|
|
34
32
|
CactusVLM: true,
|
|
@@ -53,12 +51,6 @@ Object.defineProperty(exports, "CactusVLM", {
|
|
|
53
51
|
}
|
|
54
52
|
});
|
|
55
53
|
exports.LlamaContext = void 0;
|
|
56
|
-
Object.defineProperty(exports, "SchemaGrammarConverter", {
|
|
57
|
-
enumerable: true,
|
|
58
|
-
get: function () {
|
|
59
|
-
return _grammar.SchemaGrammarConverter;
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
54
|
Object.defineProperty(exports, "Tools", {
|
|
63
55
|
enumerable: true,
|
|
64
56
|
get: function () {
|
|
@@ -66,12 +58,6 @@ Object.defineProperty(exports, "Tools", {
|
|
|
66
58
|
}
|
|
67
59
|
});
|
|
68
60
|
exports.addNativeLogListener = addNativeLogListener;
|
|
69
|
-
Object.defineProperty(exports, "convertJsonSchemaToGrammar", {
|
|
70
|
-
enumerable: true,
|
|
71
|
-
get: function () {
|
|
72
|
-
return _grammar.convertJsonSchemaToGrammar;
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
61
|
exports.initContext = exports.getTTSType = exports.getFormattedAudioCompletion = exports.getDeviceInfo = exports.getAudioCompletionGuideTokens = exports.decodeAudioTokens = void 0;
|
|
76
62
|
exports.initLlama = initLlama;
|
|
77
63
|
exports.isVocoderEnabled = exports.isMultimodalSupportVision = exports.isMultimodalSupportAudio = exports.isMultimodalEnabled = exports.initVocoder = exports.initMultimodal = void 0;
|
|
@@ -84,7 +70,6 @@ exports.toggleNativeLog = toggleNativeLog;
|
|
|
84
70
|
exports.tokenize = void 0;
|
|
85
71
|
var _reactNative = require("react-native");
|
|
86
72
|
var _NativeCactus = _interopRequireDefault(require("./NativeCactus"));
|
|
87
|
-
var _grammar = require("./grammar");
|
|
88
73
|
var _chat = require("./chat");
|
|
89
74
|
var _tools = require("./tools");
|
|
90
75
|
var _telemetry = require("./telemetry");
|
|
@@ -202,7 +187,6 @@ class LlamaContext {
|
|
|
202
187
|
return this.completion(params, callback);
|
|
203
188
|
}
|
|
204
189
|
if (recursionCount >= recursionLimit) {
|
|
205
|
-
// console.log(`Recursion limit reached (${recursionCount}/${recursionLimit}), returning default completion`)
|
|
206
190
|
return this.completion({
|
|
207
191
|
...params,
|
|
208
192
|
jinja: true,
|
|
@@ -211,15 +195,12 @@ class LlamaContext {
|
|
|
211
195
|
}
|
|
212
196
|
const messages = [...params.messages]; // avoid mutating the original messages
|
|
213
197
|
|
|
214
|
-
// console.log('Calling completion...')
|
|
215
198
|
const result = await this.completion({
|
|
216
199
|
...params,
|
|
217
200
|
messages: messages,
|
|
218
201
|
jinja: true,
|
|
219
202
|
tools: params.tools.getSchemas()
|
|
220
203
|
}, callback);
|
|
221
|
-
// console.log('Completion result:', result);
|
|
222
|
-
|
|
223
204
|
const {
|
|
224
205
|
toolCalled,
|
|
225
206
|
toolName,
|
|
@@ -240,9 +221,6 @@ class LlamaContext {
|
|
|
240
221
|
tool_call_id: toolCallId
|
|
241
222
|
};
|
|
242
223
|
messages.push(toolMessage);
|
|
243
|
-
|
|
244
|
-
// console.log('Messages being sent to next completion:', JSON.stringify(messages, null, 2));
|
|
245
|
-
|
|
246
224
|
return await this.completionWithTools({
|
|
247
225
|
...params,
|
|
248
226
|
messages: messages
|
|
@@ -370,7 +348,6 @@ class LlamaContext {
|
|
|
370
348
|
return _NativeCactus.default.releaseContext(this.id);
|
|
371
349
|
}
|
|
372
350
|
async rewind() {
|
|
373
|
-
// @ts-ignore
|
|
374
351
|
return _NativeCactus.default.rewind(this.id);
|
|
375
352
|
}
|
|
376
353
|
}
|