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
|
@@ -13,6 +13,7 @@ import com.facebook.react.bridge.LifecycleEventListener;
|
|
|
13
13
|
import com.facebook.react.bridge.ReadableMap;
|
|
14
14
|
import com.facebook.react.bridge.ReadableArray;
|
|
15
15
|
import com.facebook.react.bridge.WritableMap;
|
|
16
|
+
import com.facebook.react.bridge.WritableArray;
|
|
16
17
|
import com.facebook.react.bridge.Arguments;
|
|
17
18
|
|
|
18
19
|
import java.util.HashMap;
|
|
@@ -20,11 +21,14 @@ import java.util.Random;
|
|
|
20
21
|
import java.io.File;
|
|
21
22
|
import java.io.FileInputStream;
|
|
22
23
|
import java.io.PushbackInputStream;
|
|
24
|
+
import java.util.concurrent.ExecutorService;
|
|
25
|
+
import java.util.concurrent.Executors;
|
|
23
26
|
|
|
24
27
|
public class Cactus implements LifecycleEventListener {
|
|
25
28
|
public static final String NAME = "Cactus";
|
|
26
29
|
|
|
27
30
|
private ReactApplicationContext reactContext;
|
|
31
|
+
private final ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
|
|
28
32
|
|
|
29
33
|
public Cactus(ReactApplicationContext reactContext) {
|
|
30
34
|
reactContext.addLifecycleEventListener(this);
|
|
@@ -94,7 +98,7 @@ public class Cactus implements LifecycleEventListener {
|
|
|
94
98
|
}
|
|
95
99
|
promise.resolve(result);
|
|
96
100
|
}
|
|
97
|
-
}.executeOnExecutor(
|
|
101
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
98
102
|
}
|
|
99
103
|
|
|
100
104
|
public void initContext(double id, final ReadableMap params, final Promise promise) {
|
|
@@ -138,7 +142,7 @@ public class Cactus implements LifecycleEventListener {
|
|
|
138
142
|
promise.resolve(result);
|
|
139
143
|
tasks.remove(this);
|
|
140
144
|
}
|
|
141
|
-
}.executeOnExecutor(
|
|
145
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
142
146
|
tasks.put(task, "initContext");
|
|
143
147
|
}
|
|
144
148
|
|
|
@@ -177,7 +181,7 @@ public class Cactus implements LifecycleEventListener {
|
|
|
177
181
|
promise.resolve(result);
|
|
178
182
|
tasks.remove(this);
|
|
179
183
|
}
|
|
180
|
-
}.executeOnExecutor(
|
|
184
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
181
185
|
tasks.put(task, "getFormattedChat-" + contextId);
|
|
182
186
|
}
|
|
183
187
|
|
|
@@ -210,7 +214,7 @@ public class Cactus implements LifecycleEventListener {
|
|
|
210
214
|
promise.resolve(result);
|
|
211
215
|
tasks.remove(this);
|
|
212
216
|
}
|
|
213
|
-
}.executeOnExecutor(
|
|
217
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
214
218
|
tasks.put(task, "loadSession-" + contextId);
|
|
215
219
|
}
|
|
216
220
|
|
|
@@ -243,28 +247,36 @@ public class Cactus implements LifecycleEventListener {
|
|
|
243
247
|
promise.resolve(result);
|
|
244
248
|
tasks.remove(this);
|
|
245
249
|
}
|
|
246
|
-
}.executeOnExecutor(
|
|
250
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
247
251
|
tasks.put(task, "saveSession-" + contextId);
|
|
248
252
|
}
|
|
249
253
|
|
|
250
254
|
public void completion(double id, final ReadableMap params, final Promise promise) {
|
|
255
|
+
Log.d(NAME, "BRIDGE: completion() method called with contextId=" + (int)id);
|
|
251
256
|
final int contextId = (int) id;
|
|
252
257
|
AsyncTask task = new AsyncTask<Void, Void, WritableMap>() {
|
|
253
258
|
private Exception exception;
|
|
254
259
|
|
|
255
260
|
@Override
|
|
256
261
|
protected WritableMap doInBackground(Void... voids) {
|
|
262
|
+
Log.d(NAME, "⚡ BRIDGE: AsyncTask doInBackground starting...");
|
|
257
263
|
try {
|
|
258
264
|
LlamaContext context = contexts.get(contextId);
|
|
259
265
|
if (context == null) {
|
|
266
|
+
Log.e(NAME, "BRIDGE: Context not found for id=" + contextId);
|
|
260
267
|
throw new Exception("Context not found");
|
|
261
268
|
}
|
|
269
|
+
Log.d(NAME, "BRIDGE: Context found, checking if predicting...");
|
|
262
270
|
if (context.isPredicting()) {
|
|
271
|
+
Log.e(NAME, "BRIDGE: Context is busy (predicting)");
|
|
263
272
|
throw new Exception("Context is busy");
|
|
264
273
|
}
|
|
274
|
+
Log.d(NAME, "BRIDGE: About to call context.completion()...");
|
|
265
275
|
WritableMap result = context.completion(params);
|
|
276
|
+
Log.d(NAME, "BRIDGE: context.completion() returned successfully");
|
|
266
277
|
return result;
|
|
267
278
|
} catch (Exception e) {
|
|
279
|
+
Log.e(NAME, "BRIDGE: Exception in doInBackground: " + e.getMessage());
|
|
268
280
|
exception = e;
|
|
269
281
|
}
|
|
270
282
|
return null;
|
|
@@ -272,14 +284,19 @@ public class Cactus implements LifecycleEventListener {
|
|
|
272
284
|
|
|
273
285
|
@Override
|
|
274
286
|
protected void onPostExecute(WritableMap result) {
|
|
287
|
+
Log.d(NAME, "BRIDGE: onPostExecute called");
|
|
275
288
|
if (exception != null) {
|
|
289
|
+
Log.e(NAME, "BRIDGE: Rejecting promise with exception: " + exception.getMessage());
|
|
276
290
|
promise.reject(exception);
|
|
277
291
|
return;
|
|
278
292
|
}
|
|
293
|
+
Log.d(NAME, "BRIDGE: Resolving promise with result");
|
|
279
294
|
promise.resolve(result);
|
|
280
295
|
tasks.remove(this);
|
|
296
|
+
Log.d(NAME, "BRIDGE: completion() finished successfully");
|
|
281
297
|
}
|
|
282
|
-
}.executeOnExecutor(
|
|
298
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
299
|
+
Log.d(NAME, "BRIDGE: AsyncTask queued for execution");
|
|
283
300
|
tasks.put(task, "completion-" + contextId);
|
|
284
301
|
}
|
|
285
302
|
|
|
@@ -318,7 +335,7 @@ public class Cactus implements LifecycleEventListener {
|
|
|
318
335
|
promise.resolve(result);
|
|
319
336
|
tasks.remove(this);
|
|
320
337
|
}
|
|
321
|
-
}.executeOnExecutor(
|
|
338
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
322
339
|
tasks.put(task, "stopCompletion-" + contextId);
|
|
323
340
|
}
|
|
324
341
|
|
|
@@ -350,7 +367,39 @@ public class Cactus implements LifecycleEventListener {
|
|
|
350
367
|
promise.resolve(result);
|
|
351
368
|
tasks.remove(this);
|
|
352
369
|
}
|
|
353
|
-
}.executeOnExecutor(
|
|
370
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
371
|
+
tasks.put(task, "tokenize-" + contextId);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
public void tokenize(double id, final String text, final ReadableArray mediaPaths, final Promise promise) {
|
|
375
|
+
final int contextId = (int) id;
|
|
376
|
+
AsyncTask task = new AsyncTask<Void, Void, WritableMap>() {
|
|
377
|
+
private Exception exception;
|
|
378
|
+
|
|
379
|
+
@Override
|
|
380
|
+
protected WritableMap doInBackground(Void... voids) {
|
|
381
|
+
try {
|
|
382
|
+
LlamaContext context = contexts.get(contextId);
|
|
383
|
+
if (context == null) {
|
|
384
|
+
throw new Exception("Context not found");
|
|
385
|
+
}
|
|
386
|
+
return context.tokenize(text, mediaPaths);
|
|
387
|
+
} catch (Exception e) {
|
|
388
|
+
exception = e;
|
|
389
|
+
}
|
|
390
|
+
return null;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
@Override
|
|
394
|
+
protected void onPostExecute(WritableMap result) {
|
|
395
|
+
if (exception != null) {
|
|
396
|
+
promise.reject(exception);
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
promise.resolve(result);
|
|
400
|
+
tasks.remove(this);
|
|
401
|
+
}
|
|
402
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
354
403
|
tasks.put(task, "tokenize-" + contextId);
|
|
355
404
|
}
|
|
356
405
|
|
|
@@ -382,7 +431,7 @@ public class Cactus implements LifecycleEventListener {
|
|
|
382
431
|
promise.resolve(result);
|
|
383
432
|
tasks.remove(this);
|
|
384
433
|
}
|
|
385
|
-
}.executeOnExecutor(
|
|
434
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
386
435
|
tasks.put(task, "detokenize-" + contextId);
|
|
387
436
|
}
|
|
388
437
|
|
|
@@ -414,7 +463,7 @@ public class Cactus implements LifecycleEventListener {
|
|
|
414
463
|
promise.resolve(result);
|
|
415
464
|
tasks.remove(this);
|
|
416
465
|
}
|
|
417
|
-
}.executeOnExecutor(
|
|
466
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
418
467
|
tasks.put(task, "embedding-" + contextId);
|
|
419
468
|
}
|
|
420
469
|
|
|
@@ -446,7 +495,7 @@ public class Cactus implements LifecycleEventListener {
|
|
|
446
495
|
promise.resolve(result);
|
|
447
496
|
tasks.remove(this);
|
|
448
497
|
}
|
|
449
|
-
}.executeOnExecutor(
|
|
498
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
450
499
|
tasks.put(task, "bench-" + contextId);
|
|
451
500
|
}
|
|
452
501
|
|
|
@@ -479,7 +528,7 @@ public class Cactus implements LifecycleEventListener {
|
|
|
479
528
|
return;
|
|
480
529
|
}
|
|
481
530
|
}
|
|
482
|
-
}.executeOnExecutor(
|
|
531
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
483
532
|
tasks.put(task, "applyLoraAdapters-" + contextId);
|
|
484
533
|
}
|
|
485
534
|
|
|
@@ -513,7 +562,7 @@ public class Cactus implements LifecycleEventListener {
|
|
|
513
562
|
}
|
|
514
563
|
promise.resolve(null);
|
|
515
564
|
}
|
|
516
|
-
}.executeOnExecutor(
|
|
565
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
517
566
|
tasks.put(task, "removeLoraAdapters-" + contextId);
|
|
518
567
|
}
|
|
519
568
|
|
|
@@ -544,7 +593,7 @@ public class Cactus implements LifecycleEventListener {
|
|
|
544
593
|
}
|
|
545
594
|
promise.resolve(result);
|
|
546
595
|
}
|
|
547
|
-
}.executeOnExecutor(
|
|
596
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
548
597
|
tasks.put(task, "getLoadedLoraAdapters-" + contextId);
|
|
549
598
|
}
|
|
550
599
|
|
|
@@ -586,7 +635,7 @@ public class Cactus implements LifecycleEventListener {
|
|
|
586
635
|
promise.resolve(null);
|
|
587
636
|
tasks.remove(this);
|
|
588
637
|
}
|
|
589
|
-
}.executeOnExecutor(
|
|
638
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
590
639
|
tasks.put(task, "releaseContext-" + contextId);
|
|
591
640
|
}
|
|
592
641
|
|
|
@@ -613,7 +662,7 @@ public class Cactus implements LifecycleEventListener {
|
|
|
613
662
|
promise.resolve(null);
|
|
614
663
|
tasks.remove(this);
|
|
615
664
|
}
|
|
616
|
-
}.executeOnExecutor(
|
|
665
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
617
666
|
tasks.put(task, "releaseAllContexts");
|
|
618
667
|
}
|
|
619
668
|
|
|
@@ -643,4 +692,423 @@ public class Cactus implements LifecycleEventListener {
|
|
|
643
692
|
}
|
|
644
693
|
contexts.clear();
|
|
645
694
|
}
|
|
695
|
+
|
|
696
|
+
public void initMultimodal(double id, final String mmprojPath, final boolean useGpu, final Promise promise) {
|
|
697
|
+
final int contextId = (int) id;
|
|
698
|
+
AsyncTask task = new AsyncTask<Void, Void, Boolean>() {
|
|
699
|
+
private Exception exception;
|
|
700
|
+
|
|
701
|
+
@Override
|
|
702
|
+
protected Boolean doInBackground(Void... voids) {
|
|
703
|
+
try {
|
|
704
|
+
LlamaContext context = contexts.get(contextId);
|
|
705
|
+
if (context == null) {
|
|
706
|
+
throw new Exception("Context not found");
|
|
707
|
+
}
|
|
708
|
+
return context.initMultimodal(mmprojPath, useGpu);
|
|
709
|
+
} catch (Exception e) {
|
|
710
|
+
exception = e;
|
|
711
|
+
}
|
|
712
|
+
return false;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
@Override
|
|
716
|
+
protected void onPostExecute(Boolean result) {
|
|
717
|
+
if (exception != null) {
|
|
718
|
+
promise.reject(exception);
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
promise.resolve(result);
|
|
722
|
+
tasks.remove(this);
|
|
723
|
+
}
|
|
724
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
725
|
+
tasks.put(task, "initMultimodal-" + contextId);
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
public void isMultimodalEnabled(double id, final Promise promise) {
|
|
729
|
+
final int contextId = (int) id;
|
|
730
|
+
AsyncTask task = new AsyncTask<Void, Void, Boolean>() {
|
|
731
|
+
private Exception exception;
|
|
732
|
+
|
|
733
|
+
@Override
|
|
734
|
+
protected Boolean doInBackground(Void... voids) {
|
|
735
|
+
try {
|
|
736
|
+
LlamaContext context = contexts.get(contextId);
|
|
737
|
+
if (context == null) {
|
|
738
|
+
throw new Exception("Context not found");
|
|
739
|
+
}
|
|
740
|
+
return context.isMultimodalEnabled();
|
|
741
|
+
} catch (Exception e) {
|
|
742
|
+
exception = e;
|
|
743
|
+
}
|
|
744
|
+
return false;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
@Override
|
|
748
|
+
protected void onPostExecute(Boolean result) {
|
|
749
|
+
if (exception != null) {
|
|
750
|
+
promise.reject(exception);
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
promise.resolve(result);
|
|
754
|
+
tasks.remove(this);
|
|
755
|
+
}
|
|
756
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
757
|
+
tasks.put(task, "isMultimodalEnabled-" + contextId);
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
public void isMultimodalSupportVision(double id, final Promise promise) {
|
|
761
|
+
final int contextId = (int) id;
|
|
762
|
+
AsyncTask task = new AsyncTask<Void, Void, Boolean>() {
|
|
763
|
+
private Exception exception;
|
|
764
|
+
|
|
765
|
+
@Override
|
|
766
|
+
protected Boolean doInBackground(Void... voids) {
|
|
767
|
+
try {
|
|
768
|
+
LlamaContext context = contexts.get(contextId);
|
|
769
|
+
if (context == null) {
|
|
770
|
+
throw new Exception("Context not found");
|
|
771
|
+
}
|
|
772
|
+
return context.isMultimodalSupportVision();
|
|
773
|
+
} catch (Exception e) {
|
|
774
|
+
exception = e;
|
|
775
|
+
}
|
|
776
|
+
return false;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
@Override
|
|
780
|
+
protected void onPostExecute(Boolean result) {
|
|
781
|
+
if (exception != null) {
|
|
782
|
+
promise.reject(exception);
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
785
|
+
promise.resolve(result);
|
|
786
|
+
tasks.remove(this);
|
|
787
|
+
}
|
|
788
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
789
|
+
tasks.put(task, "isMultimodalSupportVision-" + contextId);
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
public void isMultimodalSupportAudio(double id, final Promise promise) {
|
|
793
|
+
final int contextId = (int) id;
|
|
794
|
+
AsyncTask task = new AsyncTask<Void, Void, Boolean>() {
|
|
795
|
+
private Exception exception;
|
|
796
|
+
|
|
797
|
+
@Override
|
|
798
|
+
protected Boolean doInBackground(Void... voids) {
|
|
799
|
+
try {
|
|
800
|
+
LlamaContext context = contexts.get(contextId);
|
|
801
|
+
if (context == null) {
|
|
802
|
+
throw new Exception("Context not found");
|
|
803
|
+
}
|
|
804
|
+
return context.isMultimodalSupportAudio();
|
|
805
|
+
} catch (Exception e) {
|
|
806
|
+
exception = e;
|
|
807
|
+
}
|
|
808
|
+
return false;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
@Override
|
|
812
|
+
protected void onPostExecute(Boolean result) {
|
|
813
|
+
if (exception != null) {
|
|
814
|
+
promise.reject(exception);
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
promise.resolve(result);
|
|
818
|
+
tasks.remove(this);
|
|
819
|
+
}
|
|
820
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
821
|
+
tasks.put(task, "isMultimodalSupportAudio-" + contextId);
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
public void releaseMultimodal(double id, final Promise promise) {
|
|
825
|
+
final int contextId = (int) id;
|
|
826
|
+
AsyncTask task = new AsyncTask<Void, Void, Void>() {
|
|
827
|
+
private Exception exception;
|
|
828
|
+
|
|
829
|
+
@Override
|
|
830
|
+
protected Void doInBackground(Void... voids) {
|
|
831
|
+
try {
|
|
832
|
+
LlamaContext context = contexts.get(contextId);
|
|
833
|
+
if (context == null) {
|
|
834
|
+
throw new Exception("Context not found");
|
|
835
|
+
}
|
|
836
|
+
context.releaseMultimodal();
|
|
837
|
+
} catch (Exception e) {
|
|
838
|
+
exception = e;
|
|
839
|
+
}
|
|
840
|
+
return null;
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
@Override
|
|
844
|
+
protected void onPostExecute(Void result) {
|
|
845
|
+
if (exception != null) {
|
|
846
|
+
promise.reject(exception);
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
promise.resolve(null);
|
|
850
|
+
tasks.remove(this);
|
|
851
|
+
}
|
|
852
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
853
|
+
tasks.put(task, "releaseMultimodal-" + contextId);
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
public void multimodalCompletion(double id, final String prompt, final ReadableArray mediaPaths, final ReadableMap params, final Promise promise) {
|
|
857
|
+
final int contextId = (int) id;
|
|
858
|
+
AsyncTask task = new AsyncTask<Void, Void, WritableMap>() {
|
|
859
|
+
private Exception exception;
|
|
860
|
+
|
|
861
|
+
@Override
|
|
862
|
+
protected WritableMap doInBackground(Void... voids) {
|
|
863
|
+
try {
|
|
864
|
+
LlamaContext context = contexts.get(contextId);
|
|
865
|
+
if (context == null) {
|
|
866
|
+
throw new Exception("Context not found");
|
|
867
|
+
}
|
|
868
|
+
if (context.isPredicting()) {
|
|
869
|
+
throw new Exception("Context is busy");
|
|
870
|
+
}
|
|
871
|
+
return context.multimodalCompletion(prompt, mediaPaths, params);
|
|
872
|
+
} catch (Exception e) {
|
|
873
|
+
exception = e;
|
|
874
|
+
}
|
|
875
|
+
return null;
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
@Override
|
|
879
|
+
protected void onPostExecute(WritableMap result) {
|
|
880
|
+
if (exception != null) {
|
|
881
|
+
promise.reject(exception);
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
884
|
+
promise.resolve(result);
|
|
885
|
+
tasks.remove(this);
|
|
886
|
+
}
|
|
887
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
888
|
+
tasks.put(task, "multimodalCompletion-" + contextId);
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
public void initVocoder(double id, final String vocoderModelPath, final Promise promise) {
|
|
892
|
+
final int contextId = (int) id;
|
|
893
|
+
AsyncTask task = new AsyncTask<Void, Void, Boolean>() {
|
|
894
|
+
private Exception exception;
|
|
895
|
+
|
|
896
|
+
@Override
|
|
897
|
+
protected Boolean doInBackground(Void... voids) {
|
|
898
|
+
try {
|
|
899
|
+
LlamaContext context = contexts.get(contextId);
|
|
900
|
+
if (context == null) {
|
|
901
|
+
throw new Exception("Context not found");
|
|
902
|
+
}
|
|
903
|
+
return context.initVocoder(vocoderModelPath);
|
|
904
|
+
} catch (Exception e) {
|
|
905
|
+
exception = e;
|
|
906
|
+
}
|
|
907
|
+
return false;
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
@Override
|
|
911
|
+
protected void onPostExecute(Boolean result) {
|
|
912
|
+
if (exception != null) {
|
|
913
|
+
promise.reject(exception);
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
916
|
+
promise.resolve(result);
|
|
917
|
+
tasks.remove(this);
|
|
918
|
+
}
|
|
919
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
920
|
+
tasks.put(task, "initVocoder-" + contextId);
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
public void isVocoderEnabled(double id, final Promise promise) {
|
|
924
|
+
final int contextId = (int) id;
|
|
925
|
+
AsyncTask task = new AsyncTask<Void, Void, Boolean>() {
|
|
926
|
+
private Exception exception;
|
|
927
|
+
|
|
928
|
+
@Override
|
|
929
|
+
protected Boolean doInBackground(Void... voids) {
|
|
930
|
+
try {
|
|
931
|
+
LlamaContext context = contexts.get(contextId);
|
|
932
|
+
if (context == null) {
|
|
933
|
+
throw new Exception("Context not found");
|
|
934
|
+
}
|
|
935
|
+
return context.isVocoderEnabled();
|
|
936
|
+
} catch (Exception e) {
|
|
937
|
+
exception = e;
|
|
938
|
+
}
|
|
939
|
+
return false;
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
@Override
|
|
943
|
+
protected void onPostExecute(Boolean result) {
|
|
944
|
+
if (exception != null) {
|
|
945
|
+
promise.reject(exception);
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
promise.resolve(result);
|
|
949
|
+
tasks.remove(this);
|
|
950
|
+
}
|
|
951
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
952
|
+
tasks.put(task, "isVocoderEnabled-" + contextId);
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
public void getTTSType(double id, final Promise promise) {
|
|
956
|
+
final int contextId = (int) id;
|
|
957
|
+
AsyncTask task = new AsyncTask<Void, Void, Integer>() {
|
|
958
|
+
private Exception exception;
|
|
959
|
+
|
|
960
|
+
@Override
|
|
961
|
+
protected Integer doInBackground(Void... voids) {
|
|
962
|
+
try {
|
|
963
|
+
LlamaContext context = contexts.get(contextId);
|
|
964
|
+
if (context == null) {
|
|
965
|
+
throw new Exception("Context not found");
|
|
966
|
+
}
|
|
967
|
+
return context.getTTSType();
|
|
968
|
+
} catch (Exception e) {
|
|
969
|
+
exception = e;
|
|
970
|
+
}
|
|
971
|
+
return -1;
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
@Override
|
|
975
|
+
protected void onPostExecute(Integer result) {
|
|
976
|
+
if (exception != null) {
|
|
977
|
+
promise.reject(exception);
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
promise.resolve(result);
|
|
981
|
+
tasks.remove(this);
|
|
982
|
+
}
|
|
983
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
984
|
+
tasks.put(task, "getTTSType-" + contextId);
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
public void getFormattedAudioCompletion(double id, final String speakerJsonStr, final String textToSpeak, final Promise promise) {
|
|
988
|
+
final int contextId = (int) id;
|
|
989
|
+
AsyncTask task = new AsyncTask<Void, Void, String>() {
|
|
990
|
+
private Exception exception;
|
|
991
|
+
|
|
992
|
+
@Override
|
|
993
|
+
protected String doInBackground(Void... voids) {
|
|
994
|
+
try {
|
|
995
|
+
LlamaContext context = contexts.get(contextId);
|
|
996
|
+
if (context == null) {
|
|
997
|
+
throw new Exception("Context not found");
|
|
998
|
+
}
|
|
999
|
+
return context.getFormattedAudioCompletion(speakerJsonStr, textToSpeak);
|
|
1000
|
+
} catch (Exception e) {
|
|
1001
|
+
exception = e;
|
|
1002
|
+
}
|
|
1003
|
+
return null;
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
@Override
|
|
1007
|
+
protected void onPostExecute(String result) {
|
|
1008
|
+
if (exception != null) {
|
|
1009
|
+
promise.reject(exception);
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
1012
|
+
promise.resolve(result);
|
|
1013
|
+
tasks.remove(this);
|
|
1014
|
+
}
|
|
1015
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
1016
|
+
tasks.put(task, "getFormattedAudioCompletion-" + contextId);
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
public void getAudioCompletionGuideTokens(double id, final String textToSpeak, final Promise promise) {
|
|
1020
|
+
final int contextId = (int) id;
|
|
1021
|
+
AsyncTask task = new AsyncTask<Void, Void, WritableArray>() {
|
|
1022
|
+
private Exception exception;
|
|
1023
|
+
|
|
1024
|
+
@Override
|
|
1025
|
+
protected WritableArray doInBackground(Void... voids) {
|
|
1026
|
+
try {
|
|
1027
|
+
LlamaContext context = contexts.get(contextId);
|
|
1028
|
+
if (context == null) {
|
|
1029
|
+
throw new Exception("Context not found");
|
|
1030
|
+
}
|
|
1031
|
+
return context.getAudioCompletionGuideTokens(textToSpeak);
|
|
1032
|
+
} catch (Exception e) {
|
|
1033
|
+
exception = e;
|
|
1034
|
+
}
|
|
1035
|
+
return null;
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
@Override
|
|
1039
|
+
protected void onPostExecute(WritableArray result) {
|
|
1040
|
+
if (exception != null) {
|
|
1041
|
+
promise.reject(exception);
|
|
1042
|
+
return;
|
|
1043
|
+
}
|
|
1044
|
+
promise.resolve(result);
|
|
1045
|
+
tasks.remove(this);
|
|
1046
|
+
}
|
|
1047
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
1048
|
+
tasks.put(task, "getAudioCompletionGuideTokens-" + contextId);
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
public void decodeAudioTokens(double id, final ReadableArray tokens, final Promise promise) {
|
|
1052
|
+
final int contextId = (int) id;
|
|
1053
|
+
AsyncTask task = new AsyncTask<Void, Void, WritableArray>() {
|
|
1054
|
+
private Exception exception;
|
|
1055
|
+
|
|
1056
|
+
@Override
|
|
1057
|
+
protected WritableArray doInBackground(Void... voids) {
|
|
1058
|
+
try {
|
|
1059
|
+
LlamaContext context = contexts.get(contextId);
|
|
1060
|
+
if (context == null) {
|
|
1061
|
+
throw new Exception("Context not found");
|
|
1062
|
+
}
|
|
1063
|
+
return context.decodeAudioTokens(tokens);
|
|
1064
|
+
} catch (Exception e) {
|
|
1065
|
+
exception = e;
|
|
1066
|
+
}
|
|
1067
|
+
return null;
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
@Override
|
|
1071
|
+
protected void onPostExecute(WritableArray result) {
|
|
1072
|
+
if (exception != null) {
|
|
1073
|
+
promise.reject(exception);
|
|
1074
|
+
return;
|
|
1075
|
+
}
|
|
1076
|
+
promise.resolve(result);
|
|
1077
|
+
tasks.remove(this);
|
|
1078
|
+
}
|
|
1079
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
1080
|
+
tasks.put(task, "decodeAudioTokens-" + contextId);
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
public void releaseVocoder(double id, final Promise promise) {
|
|
1084
|
+
final int contextId = (int) id;
|
|
1085
|
+
AsyncTask task = new AsyncTask<Void, Void, Void>() {
|
|
1086
|
+
private Exception exception;
|
|
1087
|
+
|
|
1088
|
+
@Override
|
|
1089
|
+
protected Void doInBackground(Void... voids) {
|
|
1090
|
+
try {
|
|
1091
|
+
LlamaContext context = contexts.get(contextId);
|
|
1092
|
+
if (context == null) {
|
|
1093
|
+
throw new Exception("Context not found");
|
|
1094
|
+
}
|
|
1095
|
+
context.releaseVocoder();
|
|
1096
|
+
} catch (Exception e) {
|
|
1097
|
+
exception = e;
|
|
1098
|
+
}
|
|
1099
|
+
return null;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
@Override
|
|
1103
|
+
protected void onPostExecute(Void result) {
|
|
1104
|
+
if (exception != null) {
|
|
1105
|
+
promise.reject(exception);
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
1108
|
+
promise.resolve(null);
|
|
1109
|
+
tasks.remove(this);
|
|
1110
|
+
}
|
|
1111
|
+
}.executeOnExecutor(singleThreadExecutor);
|
|
1112
|
+
tasks.put(task, "releaseVocoder-" + contextId);
|
|
1113
|
+
}
|
|
646
1114
|
}
|