cactus-react-native 0.0.1 → 0.1.1
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/LICENSE.txt +20 -0
- package/README.md +3 -1
- package/android/src/main/CMakeLists.txt +58 -23
- package/android/src/main/java/com/cactus/Cactus.java +484 -16
- package/android/src/main/java/com/cactus/LlamaContext.java +199 -0
- package/android/src/main/jni.cpp +325 -10
- 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/main/jniLibs/x86_64/libcactus.so +0 -0
- package/android/src/main/jniLibs/x86_64/libcactus_x86_64.so +0 -0
- package/android/src/newarch/java/com/cactus/CactusModule.java +79 -7
- package/android/src/oldarch/java/com/cactus/CactusModule.java +70 -0
- package/cactus-react-native.podspec +0 -3
- package/ios/CMakeLists.txt +58 -36
- package/ios/Cactus.mm +243 -2
- package/ios/CactusContext.h +22 -0
- package/ios/CactusContext.mm +176 -1
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus.h +92 -5
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_ffi.h +268 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/chat.h +2 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/common.h +42 -51
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-backend.h +4 -4
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-common.h +12 -6
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpp.h +1 -1
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpu.h +5 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-impl.h +52 -18
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-metal-impl.h +106 -14
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-opt.h +49 -28
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml.h +87 -106
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-arch.h +16 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-batch.h +2 -1
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-chat.h +7 -2
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-context.h +44 -33
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-cparams.h +1 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-graph.h +83 -17
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-hparams.h +44 -2
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-kv-cache.h +407 -179
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-memory.h +13 -2
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-model-loader.h +5 -3
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-model-saver.h +37 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-model.h +24 -2
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-vocab.h +6 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama.h +102 -142
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/minja/chat-template.hpp +23 -11
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/minja/minja.hpp +186 -127
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Info.plist +0 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/cactus +0 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/ggml-llama.metallib +0 -0
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/cactus.h +92 -5
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/cactus_ffi.h +268 -0
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/chat.h +2 -0
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/common.h +42 -51
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-backend.h +4 -4
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-common.h +12 -6
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpp.h +1 -1
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu.h +5 -0
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-impl.h +52 -18
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-metal-impl.h +106 -14
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-opt.h +49 -28
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml.h +87 -106
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-arch.h +16 -0
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-batch.h +2 -1
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-chat.h +7 -2
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-context.h +44 -33
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-cparams.h +1 -0
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-graph.h +83 -17
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-hparams.h +44 -2
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-kv-cache.h +407 -179
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-memory.h +13 -2
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-model-loader.h +5 -3
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-model-saver.h +37 -0
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-model.h +24 -2
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-vocab.h +6 -0
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama.h +102 -142
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/minja/chat-template.hpp +23 -11
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/minja/minja.hpp +186 -127
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Info.plist +0 -0
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/_CodeSignature/CodeResources +1 -1
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/cactus +0 -0
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/ggml-llama-sim.metallib +0 -0
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/cactus.h +92 -5
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/cactus_ffi.h +268 -0
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/chat.h +2 -0
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/common.h +42 -51
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-backend.h +4 -4
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-common.h +12 -6
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpp.h +1 -1
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpu.h +5 -0
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-impl.h +52 -18
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-metal-impl.h +106 -14
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-opt.h +49 -28
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml.h +87 -106
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-arch.h +16 -0
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-batch.h +2 -1
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-chat.h +7 -2
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-context.h +44 -33
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-cparams.h +1 -0
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-graph.h +83 -17
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-hparams.h +44 -2
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-kv-cache.h +407 -179
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-memory.h +13 -2
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-model-loader.h +5 -3
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-model-saver.h +37 -0
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-model.h +24 -2
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-vocab.h +6 -0
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama.h +102 -142
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/minja/chat-template.hpp +23 -11
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/minja/minja.hpp +186 -127
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Info.plist +0 -0
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/cactus +0 -0
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/ggml-llama.metallib +0 -0
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/cactus.h +92 -5
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/cactus_ffi.h +268 -0
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/chat.h +2 -0
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/common.h +42 -51
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-backend.h +4 -4
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-common.h +12 -6
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpp.h +1 -1
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu.h +5 -0
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-impl.h +52 -18
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-metal-impl.h +106 -14
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-opt.h +49 -28
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml.h +87 -106
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-arch.h +16 -0
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-batch.h +2 -1
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-chat.h +7 -2
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-context.h +44 -33
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-cparams.h +1 -0
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-graph.h +83 -17
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-hparams.h +44 -2
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-kv-cache.h +407 -179
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-memory.h +13 -2
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-model-loader.h +5 -3
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-model-saver.h +37 -0
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-model.h +24 -2
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-vocab.h +6 -0
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama.h +102 -142
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/minja/chat-template.hpp +23 -11
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/minja/minja.hpp +186 -127
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Info.plist +0 -0
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/_CodeSignature/CodeResources +1 -1
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/cactus +0 -0
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/ggml-llama-sim.metallib +0 -0
- package/lib/commonjs/NativeCactus.js +1 -0
- package/lib/commonjs/NativeCactus.js.map +1 -1
- package/lib/commonjs/index.js +112 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/tools.js +118 -0
- package/lib/commonjs/tools.js.map +1 -0
- package/lib/module/NativeCactus.js +3 -0
- package/lib/module/NativeCactus.js.map +1 -1
- package/lib/module/index.js +87 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/tools.js +110 -0
- package/lib/module/tools.js.map +1 -0
- package/lib/typescript/NativeCactus.d.ts +30 -1
- package/lib/typescript/NativeCactus.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +21 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/tools.d.ts +38 -0
- package/lib/typescript/tools.d.ts.map +1 -0
- package/package.json +6 -3
- package/src/NativeCactus.ts +62 -1
- package/src/index.ts +113 -2
- package/src/tools.ts +127 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpu-aarch64.h +0 -8
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpu-impl.h +0 -531
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpu-quants.h +0 -63
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpu-traits.h +0 -38
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/sgemm.h +0 -14
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-aarch64.h +0 -8
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-impl.h +0 -531
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-quants.h +0 -63
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-traits.h +0 -38
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/sgemm.h +0 -14
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpu-aarch64.h +0 -8
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpu-impl.h +0 -531
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpu-quants.h +0 -63
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpu-traits.h +0 -38
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/sgemm.h +0 -14
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-aarch64.h +0 -8
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-impl.h +0 -531
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-quants.h +0 -63
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-traits.h +0 -38
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/sgemm.h +0 -14
|
@@ -78,40 +78,112 @@ public class CactusModule extends NativeCactusSpec {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
@ReactMethod
|
|
81
|
-
public void tokenize(double id,
|
|
81
|
+
public void tokenize(double id, String text, Promise promise) {
|
|
82
82
|
cactus.tokenize(id, text, promise);
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
@ReactMethod
|
|
86
|
-
public void
|
|
86
|
+
public void tokenize(double id, String text, ReadableArray mediaPaths, Promise promise) {
|
|
87
|
+
cactus.tokenize(id, text, mediaPaths, promise);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@ReactMethod
|
|
91
|
+
public void detokenize(double id, ReadableArray tokens, Promise promise) {
|
|
87
92
|
cactus.detokenize(id, tokens, promise);
|
|
88
93
|
}
|
|
89
94
|
|
|
90
95
|
@ReactMethod
|
|
91
|
-
public void embedding(double id,
|
|
96
|
+
public void embedding(double id, String text, ReadableMap params, Promise promise) {
|
|
92
97
|
cactus.embedding(id, text, params, promise);
|
|
93
98
|
}
|
|
94
99
|
|
|
95
100
|
@ReactMethod
|
|
96
|
-
public void bench(double id,
|
|
101
|
+
public void bench(double id, double pp, double tg, double pl, double nr, Promise promise) {
|
|
97
102
|
cactus.bench(id, pp, tg, pl, nr, promise);
|
|
98
103
|
}
|
|
99
104
|
|
|
100
105
|
@ReactMethod
|
|
101
|
-
public void applyLoraAdapters(double id,
|
|
106
|
+
public void applyLoraAdapters(double id, ReadableArray loraAdapters, Promise promise) {
|
|
102
107
|
cactus.applyLoraAdapters(id, loraAdapters, promise);
|
|
103
108
|
}
|
|
104
109
|
|
|
105
110
|
@ReactMethod
|
|
106
|
-
public void removeLoraAdapters(double id,
|
|
111
|
+
public void removeLoraAdapters(double id, Promise promise) {
|
|
107
112
|
cactus.removeLoraAdapters(id, promise);
|
|
108
113
|
}
|
|
109
114
|
|
|
110
115
|
@ReactMethod
|
|
111
|
-
public void getLoadedLoraAdapters(double id,
|
|
116
|
+
public void getLoadedLoraAdapters(double id, Promise promise) {
|
|
112
117
|
cactus.getLoadedLoraAdapters(id, promise);
|
|
113
118
|
}
|
|
114
119
|
|
|
120
|
+
// New Multimodal Methods
|
|
121
|
+
@ReactMethod
|
|
122
|
+
public void initMultimodal(double id, String mmprojPath, Boolean useGpu, Promise promise) {
|
|
123
|
+
cactus.initMultimodal(id, mmprojPath, useGpu.booleanValue(), promise);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@ReactMethod
|
|
127
|
+
public void isMultimodalEnabled(double id, Promise promise) {
|
|
128
|
+
cactus.isMultimodalEnabled(id, promise);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
@ReactMethod
|
|
132
|
+
public void isMultimodalSupportVision(double id, Promise promise) {
|
|
133
|
+
cactus.isMultimodalSupportVision(id, promise);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
@ReactMethod
|
|
137
|
+
public void isMultimodalSupportAudio(double id, Promise promise) {
|
|
138
|
+
cactus.isMultimodalSupportAudio(id, promise);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
@ReactMethod
|
|
142
|
+
public void releaseMultimodal(double id, Promise promise) {
|
|
143
|
+
cactus.releaseMultimodal(id, promise);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
@ReactMethod
|
|
147
|
+
public void multimodalCompletion(double id, String prompt, ReadableArray mediaPaths, ReadableMap params, Promise promise) {
|
|
148
|
+
cactus.multimodalCompletion(id, prompt, mediaPaths, params, promise);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// New TTS/Vocoder Methods
|
|
152
|
+
@ReactMethod
|
|
153
|
+
public void initVocoder(double id, String vocoderModelPath, Promise promise) {
|
|
154
|
+
cactus.initVocoder(id, vocoderModelPath, promise);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
@ReactMethod
|
|
158
|
+
public void isVocoderEnabled(double id, Promise promise) {
|
|
159
|
+
cactus.isVocoderEnabled(id, promise);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
@ReactMethod
|
|
163
|
+
public void getTTSType(double id, Promise promise) {
|
|
164
|
+
cactus.getTTSType(id, promise);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
@ReactMethod
|
|
168
|
+
public void getFormattedAudioCompletion(double id, String speakerJsonStr, String textToSpeak, Promise promise) {
|
|
169
|
+
cactus.getFormattedAudioCompletion(id, speakerJsonStr, textToSpeak, promise);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
@ReactMethod
|
|
173
|
+
public void getAudioCompletionGuideTokens(double id, String textToSpeak, Promise promise) {
|
|
174
|
+
cactus.getAudioCompletionGuideTokens(id, textToSpeak, promise);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
@ReactMethod
|
|
178
|
+
public void decodeAudioTokens(double id, ReadableArray tokens, Promise promise) {
|
|
179
|
+
cactus.decodeAudioTokens(id, tokens, promise);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
@ReactMethod
|
|
183
|
+
public void releaseVocoder(double id, Promise promise) {
|
|
184
|
+
cactus.releaseVocoder(id, promise);
|
|
185
|
+
}
|
|
186
|
+
|
|
115
187
|
@ReactMethod
|
|
116
188
|
public void releaseContext(double id, Promise promise) {
|
|
117
189
|
cactus.releaseContext(id, promise);
|
|
@@ -83,6 +83,11 @@ public class CactusModule extends ReactContextBaseJavaModule {
|
|
|
83
83
|
cactus.tokenize(id, text, promise);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
@ReactMethod
|
|
87
|
+
public void tokenize(double id, final String text, final ReadableArray mediaPaths, final Promise promise) {
|
|
88
|
+
cactus.tokenize(id, text, mediaPaths, promise);
|
|
89
|
+
}
|
|
90
|
+
|
|
86
91
|
@ReactMethod
|
|
87
92
|
public void detokenize(double id, final ReadableArray tokens, final Promise promise) {
|
|
88
93
|
cactus.detokenize(id, tokens, promise);
|
|
@@ -113,6 +118,71 @@ public class CactusModule extends ReactContextBaseJavaModule {
|
|
|
113
118
|
cactus.getLoadedLoraAdapters(id, promise);
|
|
114
119
|
}
|
|
115
120
|
|
|
121
|
+
@ReactMethod
|
|
122
|
+
public void initMultimodal(double id, final String mmprojPath, final boolean useGpu, final Promise promise) {
|
|
123
|
+
cactus.initMultimodal(id, mmprojPath, useGpu, promise);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@ReactMethod
|
|
127
|
+
public void isMultimodalEnabled(double id, final Promise promise) {
|
|
128
|
+
cactus.isMultimodalEnabled(id, promise);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
@ReactMethod
|
|
132
|
+
public void isMultimodalSupportVision(double id, final Promise promise) {
|
|
133
|
+
cactus.isMultimodalSupportVision(id, promise);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
@ReactMethod
|
|
137
|
+
public void isMultimodalSupportAudio(double id, final Promise promise) {
|
|
138
|
+
cactus.isMultimodalSupportAudio(id, promise);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
@ReactMethod
|
|
142
|
+
public void releaseMultimodal(double id, final Promise promise) {
|
|
143
|
+
cactus.releaseMultimodal(id, promise);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
@ReactMethod
|
|
147
|
+
public void multimodalCompletion(double id, final String prompt, final ReadableArray mediaPaths, final ReadableMap params, final Promise promise) {
|
|
148
|
+
cactus.multimodalCompletion(id, prompt, mediaPaths, params, promise);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
@ReactMethod
|
|
152
|
+
public void initVocoder(double id, final String vocoderModelPath, final Promise promise) {
|
|
153
|
+
cactus.initVocoder(id, vocoderModelPath, promise);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
@ReactMethod
|
|
157
|
+
public void isVocoderEnabled(double id, final Promise promise) {
|
|
158
|
+
cactus.isVocoderEnabled(id, promise);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
@ReactMethod
|
|
162
|
+
public void getTTSType(double id, final Promise promise) {
|
|
163
|
+
cactus.getTTSType(id, promise);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
@ReactMethod
|
|
167
|
+
public void getFormattedAudioCompletion(double id, final String speakerJsonStr, final String textToSpeak, final Promise promise) {
|
|
168
|
+
cactus.getFormattedAudioCompletion(id, speakerJsonStr, textToSpeak, promise);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
@ReactMethod
|
|
172
|
+
public void getAudioCompletionGuideTokens(double id, final String textToSpeak, final Promise promise) {
|
|
173
|
+
cactus.getAudioCompletionGuideTokens(id, textToSpeak, promise);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
@ReactMethod
|
|
177
|
+
public void decodeAudioTokens(double id, final ReadableArray tokens, final Promise promise) {
|
|
178
|
+
cactus.decodeAudioTokens(id, tokens, promise);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
@ReactMethod
|
|
182
|
+
public void releaseVocoder(double id, final Promise promise) {
|
|
183
|
+
cactus.releaseVocoder(id, promise);
|
|
184
|
+
}
|
|
185
|
+
|
|
116
186
|
@ReactMethod
|
|
117
187
|
public void releaseContext(double id, Promise promise) {
|
|
118
188
|
cactus.releaseContext(id, promise);
|
|
@@ -8,11 +8,8 @@ if ENV["CACTUS_DISABLE_METAL"] != "1" then
|
|
|
8
8
|
base_compiler_flags += " -DLM_GGML_USE_METAL -DLM_GGML_METAL_USE_BF16" # -DLM_GGML_METAL_NDEBUG
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
# Use base_optimizer_flags = "" for debug builds
|
|
12
|
-
# base_optimizer_flags = ""
|
|
13
11
|
base_optimizer_flags = "-O3 -DNDEBUG"
|
|
14
12
|
|
|
15
|
-
# We always use the local ios directory since we're now copying the files
|
|
16
13
|
ios_path = 'ios'
|
|
17
14
|
|
|
18
15
|
Pod::Spec.new do |s|
|
package/ios/CMakeLists.txt
CHANGED
|
@@ -24,6 +24,7 @@ set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../cactus)
|
|
|
24
24
|
# Define public headers
|
|
25
25
|
set(PUBLIC_HEADERS
|
|
26
26
|
${SOURCE_DIR}/cactus.h
|
|
27
|
+
${SOURCE_DIR}/cactus_ffi.h
|
|
27
28
|
${SOURCE_DIR}/llama.h
|
|
28
29
|
${SOURCE_DIR}/llama-impl.h
|
|
29
30
|
${SOURCE_DIR}/ggml.h
|
|
@@ -31,60 +32,81 @@ set(PUBLIC_HEADERS
|
|
|
31
32
|
|
|
32
33
|
# Create library target
|
|
33
34
|
add_library(cactus SHARED
|
|
34
|
-
${SOURCE_DIR}/
|
|
35
|
-
${SOURCE_DIR}/
|
|
36
|
-
${SOURCE_DIR}/
|
|
37
|
-
${SOURCE_DIR}/
|
|
38
|
-
${SOURCE_DIR}/
|
|
39
|
-
${SOURCE_DIR}/
|
|
40
|
-
${SOURCE_DIR}/
|
|
41
|
-
${SOURCE_DIR}/
|
|
42
|
-
${SOURCE_DIR}/
|
|
43
|
-
${SOURCE_DIR}/
|
|
44
|
-
${SOURCE_DIR}/
|
|
45
|
-
${SOURCE_DIR}/
|
|
46
|
-
${SOURCE_DIR}/
|
|
47
|
-
${SOURCE_DIR}/
|
|
48
|
-
${SOURCE_DIR}/
|
|
49
|
-
${SOURCE_DIR}/
|
|
50
|
-
${SOURCE_DIR}/llama
|
|
51
|
-
${SOURCE_DIR}/llama-
|
|
52
|
-
${SOURCE_DIR}/llama-
|
|
53
|
-
${SOURCE_DIR}/llama-
|
|
54
|
-
${SOURCE_DIR}/llama-chat.cpp
|
|
55
|
-
${SOURCE_DIR}/llama-context.cpp
|
|
56
|
-
${SOURCE_DIR}/llama-kv-cache.cpp
|
|
57
|
-
${SOURCE_DIR}/llama-arch.cpp
|
|
58
|
-
${SOURCE_DIR}/llama-batch.cpp
|
|
35
|
+
${SOURCE_DIR}/cactus_context.cpp
|
|
36
|
+
${SOURCE_DIR}/cactus_loader.cpp
|
|
37
|
+
${SOURCE_DIR}/cactus_completion.cpp
|
|
38
|
+
${SOURCE_DIR}/cactus_utils.cpp
|
|
39
|
+
${SOURCE_DIR}/cactus_embedding.cpp
|
|
40
|
+
${SOURCE_DIR}/cactus_lora.cpp
|
|
41
|
+
${SOURCE_DIR}/cactus_tokenization.cpp
|
|
42
|
+
${SOURCE_DIR}/cactus_multimodal.cpp
|
|
43
|
+
${SOURCE_DIR}/cactus_tts.cpp
|
|
44
|
+
${SOURCE_DIR}/cactus_bench.cpp
|
|
45
|
+
${SOURCE_DIR}/cactus_chat.cpp
|
|
46
|
+
${SOURCE_DIR}/cactus_ffi.cpp
|
|
47
|
+
${SOURCE_DIR}/tools/mtmd/mtmd.cpp
|
|
48
|
+
${SOURCE_DIR}/tools/mtmd/mtmd-audio.cpp
|
|
49
|
+
${SOURCE_DIR}/tools/mtmd/clip.cpp
|
|
50
|
+
${SOURCE_DIR}/tools/mtmd/mtmd-helper.cpp
|
|
51
|
+
${SOURCE_DIR}/llama.cpp
|
|
52
|
+
${SOURCE_DIR}/llama-mmap.cpp
|
|
53
|
+
${SOURCE_DIR}/llama-memory.cpp
|
|
54
|
+
${SOURCE_DIR}/llama-io.cpp
|
|
59
55
|
${SOURCE_DIR}/llama-cparams.cpp
|
|
60
56
|
${SOURCE_DIR}/llama-hparams.cpp
|
|
61
|
-
${SOURCE_DIR}/llama.cpp
|
|
62
57
|
${SOURCE_DIR}/llama-model.cpp
|
|
63
58
|
${SOURCE_DIR}/llama-model-loader.cpp
|
|
64
|
-
${SOURCE_DIR}/llama-
|
|
59
|
+
${SOURCE_DIR}/llama-model-saver.cpp
|
|
60
|
+
${SOURCE_DIR}/llama-kv-cache.cpp
|
|
61
|
+
${SOURCE_DIR}/llama-context.cpp
|
|
62
|
+
${SOURCE_DIR}/llama-chat.cpp
|
|
63
|
+
${SOURCE_DIR}/llama-batch.cpp
|
|
64
|
+
${SOURCE_DIR}/llama-arch.cpp
|
|
65
|
+
${SOURCE_DIR}/llama-adapter.cpp
|
|
66
|
+
${SOURCE_DIR}/llama-sampling.cpp
|
|
67
|
+
${SOURCE_DIR}/llama-grammar.cpp
|
|
65
68
|
${SOURCE_DIR}/llama-vocab.cpp
|
|
66
|
-
${SOURCE_DIR}/llama-
|
|
67
|
-
${SOURCE_DIR}/llama-io.cpp
|
|
69
|
+
${SOURCE_DIR}/llama-impl.cpp
|
|
68
70
|
${SOURCE_DIR}/llama-graph.cpp
|
|
69
|
-
${SOURCE_DIR}/
|
|
70
|
-
${SOURCE_DIR}/
|
|
71
|
-
${SOURCE_DIR}/
|
|
72
|
-
${SOURCE_DIR}/
|
|
71
|
+
${SOURCE_DIR}/ggml.c
|
|
72
|
+
${SOURCE_DIR}/ggml-alloc.c
|
|
73
|
+
${SOURCE_DIR}/ggml-backend.cpp
|
|
74
|
+
${SOURCE_DIR}/ggml-quants.c
|
|
75
|
+
${SOURCE_DIR}/ggml-opt.cpp
|
|
76
|
+
${SOURCE_DIR}/ggml-threading.cpp
|
|
77
|
+
${SOURCE_DIR}/ggml-backend-reg.cpp
|
|
78
|
+
${SOURCE_DIR}/gguf.cpp
|
|
73
79
|
${SOURCE_DIR}/common.cpp
|
|
74
80
|
${SOURCE_DIR}/chat.cpp
|
|
81
|
+
${SOURCE_DIR}/log.cpp
|
|
82
|
+
${SOURCE_DIR}/sampling.cpp
|
|
75
83
|
${SOURCE_DIR}/json-schema-to-grammar.cpp
|
|
84
|
+
${SOURCE_DIR}/unicode.cpp
|
|
85
|
+
${SOURCE_DIR}/unicode-data.cpp
|
|
86
|
+
${SOURCE_DIR}/ggml-cpu/amx/amx.cpp
|
|
87
|
+
${SOURCE_DIR}/ggml-cpu/amx/mmq.cpp
|
|
88
|
+
${SOURCE_DIR}/ggml-cpu/ggml-cpu.c
|
|
89
|
+
${SOURCE_DIR}/ggml-cpu/ggml-cpu.cpp
|
|
90
|
+
${SOURCE_DIR}/ggml-cpu/ggml-cpu-aarch64.cpp
|
|
91
|
+
${SOURCE_DIR}/ggml-cpu/ggml-cpu-quants.c
|
|
92
|
+
${SOURCE_DIR}/ggml-cpu/ggml-cpu-traits.cpp
|
|
93
|
+
${SOURCE_DIR}/ggml-cpu/unary-ops.cpp
|
|
94
|
+
${SOURCE_DIR}/ggml-cpu/binary-ops.cpp
|
|
95
|
+
${SOURCE_DIR}/ggml-cpu/sgemm.cpp
|
|
96
|
+
${SOURCE_DIR}/ggml-cpu/vec.cpp
|
|
97
|
+
${SOURCE_DIR}/ggml-cpu/ops.cpp
|
|
98
|
+
${SOURCE_DIR}/ggml-metal.m
|
|
76
99
|
${SOURCE_DIR}/minja/minja.hpp
|
|
77
100
|
${SOURCE_DIR}/minja/chat-template.hpp
|
|
78
101
|
${SOURCE_DIR}/json.hpp
|
|
79
|
-
${SOURCE_DIR}/amx/amx.cpp
|
|
80
|
-
${SOURCE_DIR}/amx/mmq.cpp
|
|
81
|
-
${SOURCE_DIR}/cactus.cpp
|
|
82
102
|
)
|
|
83
103
|
|
|
84
104
|
# Setup include directories, use the cactus directory
|
|
85
105
|
target_include_directories(cactus
|
|
86
106
|
PUBLIC
|
|
87
107
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../cactus>
|
|
108
|
+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../cactus/ggml-cpu>
|
|
109
|
+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../cactus/tools/mtmd>
|
|
88
110
|
$<INSTALL_INTERFACE:include>
|
|
89
111
|
)
|
|
90
112
|
|
package/ios/Cactus.mm
CHANGED
|
@@ -237,9 +237,28 @@ RCT_EXPORT_METHOD(tokenize:(double)contextId
|
|
|
237
237
|
reject(@"llama_error", @"Context not found", nil);
|
|
238
238
|
return;
|
|
239
239
|
}
|
|
240
|
-
|
|
240
|
+
NSArray *tokens = [context tokenize:text];
|
|
241
241
|
resolve(@{ @"tokens": tokens });
|
|
242
|
-
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
RCT_EXPORT_METHOD(tokenize:(double)contextId
|
|
245
|
+
text:(NSString *)text
|
|
246
|
+
mediaPaths:(NSArray *)mediaPaths
|
|
247
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
248
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
249
|
+
{
|
|
250
|
+
CactusContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
|
|
251
|
+
if (context == nil) {
|
|
252
|
+
reject(@"llama_error", @"Context not found", nil);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (mediaPaths && [mediaPaths count] > 0) {
|
|
257
|
+
resolve([context tokenize:text withMediaPaths:mediaPaths]);
|
|
258
|
+
} else {
|
|
259
|
+
NSArray *tokens = [context tokenize:text];
|
|
260
|
+
resolve(@{ @"tokens": tokens });
|
|
261
|
+
}
|
|
243
262
|
}
|
|
244
263
|
|
|
245
264
|
RCT_EXPORT_METHOD(detokenize:(double)contextId
|
|
@@ -342,6 +361,118 @@ RCT_EXPORT_METHOD(getLoadedLoraAdapters:(double)contextId
|
|
|
342
361
|
resolve([context getLoadedLoraAdapters]);
|
|
343
362
|
}
|
|
344
363
|
|
|
364
|
+
RCT_EXPORT_METHOD(initMultimodal:(double)contextId
|
|
365
|
+
mmprojPath:(NSString *)mmprojPath
|
|
366
|
+
useGpu:(BOOL)useGpu
|
|
367
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
368
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
369
|
+
{
|
|
370
|
+
CactusContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
|
|
371
|
+
if (context == nil) {
|
|
372
|
+
reject(@"llama_error", @"Context not found", nil);
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
@try {
|
|
376
|
+
BOOL result = [context initMultimodal:mmprojPath useGpu:useGpu];
|
|
377
|
+
resolve(@(result));
|
|
378
|
+
} @catch (NSException *exception) {
|
|
379
|
+
reject(@"llama_cpp_error", exception.reason, nil);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
RCT_EXPORT_METHOD(isMultimodalEnabled:(double)contextId
|
|
384
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
385
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
386
|
+
{
|
|
387
|
+
CactusContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
|
|
388
|
+
if (context == nil) {
|
|
389
|
+
reject(@"llama_error", @"Context not found", nil);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
resolve(@([context isMultimodalEnabled]));
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
RCT_EXPORT_METHOD(isMultimodalSupportVision:(double)contextId
|
|
396
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
397
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
398
|
+
{
|
|
399
|
+
CactusContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
|
|
400
|
+
if (context == nil) {
|
|
401
|
+
reject(@"llama_error", @"Context not found", nil);
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
resolve(@([context isMultimodalSupportVision]));
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
RCT_EXPORT_METHOD(isMultimodalSupportAudio:(double)contextId
|
|
408
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
409
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
410
|
+
{
|
|
411
|
+
CactusContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
|
|
412
|
+
if (context == nil) {
|
|
413
|
+
reject(@"llama_error", @"Context not found", nil);
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
resolve(@([context isMultimodalSupportAudio]));
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
RCT_EXPORT_METHOD(releaseMultimodal:(double)contextId
|
|
420
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
421
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
422
|
+
{
|
|
423
|
+
CactusContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
|
|
424
|
+
if (context == nil) {
|
|
425
|
+
reject(@"llama_error", @"Context not found", nil);
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
[context releaseMultimodal];
|
|
429
|
+
resolve(nil);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
RCT_EXPORT_METHOD(multimodalCompletion:(double)contextId
|
|
433
|
+
prompt:(NSString *)prompt
|
|
434
|
+
mediaPaths:(NSArray *)mediaPaths
|
|
435
|
+
completionParams:(NSDictionary *)completionParams
|
|
436
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
437
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
438
|
+
{
|
|
439
|
+
CactusContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
|
|
440
|
+
if (context == nil) {
|
|
441
|
+
reject(@"llama_error", @"Context not found", nil);
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
if ([context isPredicting]) {
|
|
445
|
+
reject(@"llama_error", @"Context is busy", nil);
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
dispatch_async(llamaDQueue, ^{
|
|
449
|
+
@try {
|
|
450
|
+
@autoreleasepool {
|
|
451
|
+
NSDictionary* completionResult = [context multimodalCompletion:prompt
|
|
452
|
+
withMediaPaths:mediaPaths
|
|
453
|
+
params:completionParams
|
|
454
|
+
onToken:^(NSMutableDictionary *tokenResult) {
|
|
455
|
+
if (![completionParams[@"emit_partial_completion"] boolValue]) return;
|
|
456
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
457
|
+
[self sendEventWithName:@"@Cactus_onToken"
|
|
458
|
+
body:@{
|
|
459
|
+
@"contextId": [NSNumber numberWithDouble:contextId],
|
|
460
|
+
@"tokenResult": tokenResult
|
|
461
|
+
}
|
|
462
|
+
];
|
|
463
|
+
[tokenResult release];
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
];
|
|
467
|
+
resolve(completionResult);
|
|
468
|
+
}
|
|
469
|
+
} @catch (NSException *exception) {
|
|
470
|
+
reject(@"llama_cpp_error", exception.reason, nil);
|
|
471
|
+
[context stopCompletion];
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
|
|
345
476
|
RCT_EXPORT_METHOD(releaseContext:(double)contextId
|
|
346
477
|
withResolver:(RCTPromiseResolveBlock)resolve
|
|
347
478
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
@@ -368,6 +499,116 @@ RCT_EXPORT_METHOD(releaseAllContexts:(RCTPromiseResolveBlock)resolve
|
|
|
368
499
|
resolve(nil);
|
|
369
500
|
}
|
|
370
501
|
|
|
502
|
+
// New TTS/Vocoder Methods
|
|
503
|
+
RCT_EXPORT_METHOD(initVocoder:(double)contextId
|
|
504
|
+
vocoderModelPath:(NSString *)vocoderModelPath
|
|
505
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
506
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
507
|
+
{
|
|
508
|
+
CactusContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
|
|
509
|
+
if (context == nil) {
|
|
510
|
+
reject(@"llama_error", @"Context not found", nil);
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
@try {
|
|
514
|
+
BOOL result = [context initVocoder:vocoderModelPath];
|
|
515
|
+
resolve(@(result));
|
|
516
|
+
} @catch (NSException *exception) {
|
|
517
|
+
reject(@"llama_cpp_error", exception.reason, nil);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
RCT_EXPORT_METHOD(isVocoderEnabled:(double)contextId
|
|
522
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
523
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
524
|
+
{
|
|
525
|
+
CactusContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
|
|
526
|
+
if (context == nil) {
|
|
527
|
+
reject(@"llama_error", @"Context not found", nil);
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
resolve(@([context isVocoderEnabled]));
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
RCT_EXPORT_METHOD(getTTSType:(double)contextId
|
|
534
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
535
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
536
|
+
{
|
|
537
|
+
CactusContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
|
|
538
|
+
if (context == nil) {
|
|
539
|
+
reject(@"llama_error", @"Context not found", nil);
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
resolve(@{ @"type": @([context getTTSType]) });
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
RCT_EXPORT_METHOD(getFormattedAudioCompletion:(double)contextId
|
|
546
|
+
speakerJsonStr:(NSString *)speakerJsonStr
|
|
547
|
+
textToSpeak:(NSString *)textToSpeak
|
|
548
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
549
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
550
|
+
{
|
|
551
|
+
CactusContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
|
|
552
|
+
if (context == nil) {
|
|
553
|
+
reject(@"llama_error", @"Context not found", nil);
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
@try {
|
|
557
|
+
NSString *result = [context getFormattedAudioCompletion:speakerJsonStr textToSpeak:textToSpeak];
|
|
558
|
+
resolve(@{ @"formatted_prompt": result });
|
|
559
|
+
} @catch (NSException *exception) {
|
|
560
|
+
reject(@"llama_cpp_error", exception.reason, nil);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
RCT_EXPORT_METHOD(getAudioCompletionGuideTokens:(double)contextId
|
|
565
|
+
textToSpeak:(NSString *)textToSpeak
|
|
566
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
567
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
568
|
+
{
|
|
569
|
+
CactusContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
|
|
570
|
+
if (context == nil) {
|
|
571
|
+
reject(@"llama_error", @"Context not found", nil);
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
@try {
|
|
575
|
+
NSArray *tokens = [context getAudioCompletionGuideTokens:textToSpeak];
|
|
576
|
+
resolve(@{ @"tokens": tokens });
|
|
577
|
+
} @catch (NSException *exception) {
|
|
578
|
+
reject(@"llama_cpp_error", exception.reason, nil);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
RCT_EXPORT_METHOD(decodeAudioTokens:(double)contextId
|
|
583
|
+
tokens:(NSArray *)tokens
|
|
584
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
585
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
586
|
+
{
|
|
587
|
+
CactusContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
|
|
588
|
+
if (context == nil) {
|
|
589
|
+
reject(@"llama_error", @"Context not found", nil);
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
@try {
|
|
593
|
+
NSArray *audioData = [context decodeAudioTokens:tokens];
|
|
594
|
+
resolve(@{ @"audio_data": audioData });
|
|
595
|
+
} @catch (NSException *exception) {
|
|
596
|
+
reject(@"llama_cpp_error", exception.reason, nil);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
RCT_EXPORT_METHOD(releaseVocoder:(double)contextId
|
|
601
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
602
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
603
|
+
{
|
|
604
|
+
CactusContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
|
|
605
|
+
if (context == nil) {
|
|
606
|
+
reject(@"llama_error", @"Context not found", nil);
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
[context releaseVocoder];
|
|
610
|
+
resolve(nil);
|
|
611
|
+
}
|
|
371
612
|
|
|
372
613
|
- (void)invalidate {
|
|
373
614
|
if (llamaContexts == nil) {
|
package/ios/CactusContext.h
CHANGED
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
- (NSDictionary *)completion:(NSDictionary *)params onToken:(void (^)(NSMutableDictionary *tokenResult))onToken;
|
|
38
38
|
- (void)stopCompletion;
|
|
39
39
|
- (NSArray *)tokenize:(NSString *)text;
|
|
40
|
+
- (NSArray *)tokenize:(NSString *)text withMediaPaths:(NSArray *)mediaPaths;
|
|
40
41
|
- (NSString *)detokenize:(NSArray *)tokens;
|
|
41
42
|
- (NSDictionary *)embedding:(NSString *)text params:(NSDictionary *)params;
|
|
42
43
|
- (NSDictionary *)getFormattedChatWithJinja:(NSString *)messages
|
|
@@ -52,6 +53,27 @@
|
|
|
52
53
|
- (void)applyLoraAdapters:(NSArray *)loraAdapters;
|
|
53
54
|
- (void)removeLoraAdapters;
|
|
54
55
|
- (NSArray *)getLoadedLoraAdapters;
|
|
56
|
+
|
|
57
|
+
// New Multimodal Methods
|
|
58
|
+
- (BOOL)initMultimodal:(NSString *)mmprojPath useGpu:(BOOL)useGpu;
|
|
59
|
+
- (BOOL)isMultimodalEnabled;
|
|
60
|
+
- (BOOL)isMultimodalSupportVision;
|
|
61
|
+
- (BOOL)isMultimodalSupportAudio;
|
|
62
|
+
- (void)releaseMultimodal;
|
|
63
|
+
- (NSDictionary *)multimodalCompletion:(NSString *)prompt
|
|
64
|
+
withMediaPaths:(NSArray *)mediaPaths
|
|
65
|
+
params:(NSDictionary *)params
|
|
66
|
+
onToken:(void (^)(NSMutableDictionary *tokenResult))onToken;
|
|
67
|
+
|
|
68
|
+
// New TTS/Vocoder Methods
|
|
69
|
+
- (BOOL)initVocoder:(NSString *)vocoderModelPath;
|
|
70
|
+
- (BOOL)isVocoderEnabled;
|
|
71
|
+
- (int)getTTSType;
|
|
72
|
+
- (NSString *)getFormattedAudioCompletion:(NSString *)speakerJsonStr textToSpeak:(NSString *)textToSpeak;
|
|
73
|
+
- (NSArray *)getAudioCompletionGuideTokens:(NSString *)textToSpeak;
|
|
74
|
+
- (NSArray *)decodeAudioTokens:(NSArray *)tokens;
|
|
75
|
+
- (void)releaseVocoder;
|
|
76
|
+
|
|
55
77
|
- (void)invalidate;
|
|
56
78
|
|
|
57
79
|
@end
|