cactus-react-native 0.0.1 → 0.1.0
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 +60 -21
- package/android/src/main/java/com/cactus/Cactus.java +465 -0
- 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 +56 -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 +229 -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 +229 -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 +229 -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 +229 -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
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Jhen-Jie Hong
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -6,9 +6,11 @@ A lightweight, high-performance framework for running AI models on mobile device
|
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
# Using npm
|
|
9
|
+
npm install react-native-fs
|
|
9
10
|
npm install cactus-react-native
|
|
10
11
|
|
|
11
12
|
# Using yarn
|
|
13
|
+
yarn add react-native-fs
|
|
12
14
|
yarn add cactus-react-native
|
|
13
15
|
|
|
14
16
|
# For iOS, install pods if not on Expo
|
|
@@ -227,4 +229,4 @@ This example demonstrates:
|
|
|
227
229
|
|
|
228
230
|
## License
|
|
229
231
|
|
|
230
|
-
This project is licensed under the
|
|
232
|
+
This project is licensed under the Apache 2.0 License.
|
|
@@ -3,26 +3,57 @@ cmake_minimum_required(VERSION 3.10)
|
|
|
3
3
|
project(cactus)
|
|
4
4
|
|
|
5
5
|
set(CMAKE_CXX_STANDARD 17)
|
|
6
|
+
|
|
6
7
|
# Use cactus as the C++ source directory
|
|
7
|
-
set(SOURCE_DIR ${CMAKE_SOURCE_DIR}
|
|
8
|
+
set(SOURCE_DIR ${CMAKE_SOURCE_DIR}/../../../../cactus)
|
|
8
9
|
|
|
10
|
+
# Include directories to match cactus core structure
|
|
9
11
|
include_directories(${SOURCE_DIR})
|
|
12
|
+
include_directories(${SOURCE_DIR}/ggml-cpu)
|
|
13
|
+
include_directories(${SOURCE_DIR}/minja)
|
|
14
|
+
include_directories(${SOURCE_DIR}/tools/mtmd)
|
|
15
|
+
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
|
10
16
|
|
|
11
17
|
set(
|
|
12
18
|
SOURCE_FILES
|
|
19
|
+
# Core cactus files
|
|
20
|
+
${SOURCE_DIR}/cactus_context.cpp
|
|
21
|
+
${SOURCE_DIR}/cactus_loader.cpp
|
|
22
|
+
${SOURCE_DIR}/cactus_completion.cpp
|
|
23
|
+
${SOURCE_DIR}/cactus_utils.cpp
|
|
24
|
+
${SOURCE_DIR}/cactus_embedding.cpp
|
|
25
|
+
${SOURCE_DIR}/cactus_lora.cpp
|
|
26
|
+
${SOURCE_DIR}/cactus_tokenization.cpp
|
|
27
|
+
${SOURCE_DIR}/cactus_multimodal.cpp
|
|
28
|
+
${SOURCE_DIR}/cactus_tts.cpp
|
|
29
|
+
${SOURCE_DIR}/cactus_bench.cpp
|
|
30
|
+
${SOURCE_DIR}/cactus_chat.cpp
|
|
31
|
+
|
|
32
|
+
# GGML core files
|
|
13
33
|
${SOURCE_DIR}/ggml.c
|
|
14
34
|
${SOURCE_DIR}/ggml-alloc.c
|
|
15
35
|
${SOURCE_DIR}/ggml-backend.cpp
|
|
16
36
|
${SOURCE_DIR}/ggml-backend-reg.cpp
|
|
17
|
-
${SOURCE_DIR}/ggml-cpu.c
|
|
18
|
-
${SOURCE_DIR}/ggml-cpu.cpp
|
|
19
|
-
${SOURCE_DIR}/ggml-cpu-aarch64.cpp
|
|
20
|
-
${SOURCE_DIR}/ggml-cpu-quants.c
|
|
21
|
-
${SOURCE_DIR}/ggml-cpu-traits.cpp
|
|
22
37
|
${SOURCE_DIR}/ggml-opt.cpp
|
|
23
38
|
${SOURCE_DIR}/ggml-threading.cpp
|
|
24
39
|
${SOURCE_DIR}/ggml-quants.c
|
|
25
40
|
${SOURCE_DIR}/gguf.cpp
|
|
41
|
+
|
|
42
|
+
# GGML CPU files
|
|
43
|
+
${SOURCE_DIR}/ggml-cpu/ggml-cpu.c
|
|
44
|
+
${SOURCE_DIR}/ggml-cpu/ggml-cpu.cpp
|
|
45
|
+
${SOURCE_DIR}/ggml-cpu/ggml-cpu-aarch64.cpp
|
|
46
|
+
${SOURCE_DIR}/ggml-cpu/ggml-cpu-quants.c
|
|
47
|
+
${SOURCE_DIR}/ggml-cpu/ggml-cpu-traits.cpp
|
|
48
|
+
${SOURCE_DIR}/ggml-cpu/amx/amx.cpp
|
|
49
|
+
${SOURCE_DIR}/ggml-cpu/amx/mmq.cpp
|
|
50
|
+
${SOURCE_DIR}/ggml-cpu/unary-ops.cpp
|
|
51
|
+
${SOURCE_DIR}/ggml-cpu/binary-ops.cpp
|
|
52
|
+
${SOURCE_DIR}/ggml-cpu/sgemm.cpp
|
|
53
|
+
${SOURCE_DIR}/ggml-cpu/vec.cpp
|
|
54
|
+
${SOURCE_DIR}/ggml-cpu/ops.cpp
|
|
55
|
+
|
|
56
|
+
# LLaMA files
|
|
26
57
|
${SOURCE_DIR}/log.cpp
|
|
27
58
|
${SOURCE_DIR}/llama-impl.cpp
|
|
28
59
|
${SOURCE_DIR}/llama-grammar.cpp
|
|
@@ -39,26 +70,34 @@ set(
|
|
|
39
70
|
${SOURCE_DIR}/llama.cpp
|
|
40
71
|
${SOURCE_DIR}/llama-model.cpp
|
|
41
72
|
${SOURCE_DIR}/llama-model-loader.cpp
|
|
73
|
+
${SOURCE_DIR}/llama-model-saver.cpp
|
|
42
74
|
${SOURCE_DIR}/llama-mmap.cpp
|
|
43
|
-
${SOURCE_DIR}/llama-vocab.cpp
|
|
44
75
|
${SOURCE_DIR}/llama-memory.cpp
|
|
45
76
|
${SOURCE_DIR}/llama-io.cpp
|
|
46
77
|
${SOURCE_DIR}/llama-graph.cpp
|
|
78
|
+
|
|
79
|
+
# Common files
|
|
47
80
|
${SOURCE_DIR}/sampling.cpp
|
|
48
81
|
${SOURCE_DIR}/unicode-data.cpp
|
|
49
82
|
${SOURCE_DIR}/unicode.cpp
|
|
50
|
-
${SOURCE_DIR}/sgemm.cpp
|
|
51
83
|
${SOURCE_DIR}/common.cpp
|
|
52
84
|
${SOURCE_DIR}/chat.cpp
|
|
53
85
|
${SOURCE_DIR}/json-schema-to-grammar.cpp
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
${SOURCE_DIR}/amx/mmq.cpp
|
|
86
|
+
|
|
87
|
+
# Template and JSON headers (header-only)
|
|
57
88
|
${SOURCE_DIR}/minja/minja.hpp
|
|
58
89
|
${SOURCE_DIR}/minja/chat-template.hpp
|
|
59
|
-
${SOURCE_DIR}/
|
|
60
|
-
|
|
61
|
-
|
|
90
|
+
${SOURCE_DIR}/json.hpp
|
|
91
|
+
|
|
92
|
+
# Multimodal/MTMD files
|
|
93
|
+
${SOURCE_DIR}/tools/mtmd/mtmd.cpp
|
|
94
|
+
${SOURCE_DIR}/tools/mtmd/mtmd-audio.cpp
|
|
95
|
+
${SOURCE_DIR}/tools/mtmd/clip.cpp
|
|
96
|
+
${SOURCE_DIR}/tools/mtmd/mtmd-helper.cpp
|
|
97
|
+
|
|
98
|
+
# JNI files
|
|
99
|
+
${CMAKE_CURRENT_SOURCE_DIR}/jni-utils.h
|
|
100
|
+
${CMAKE_CURRENT_SOURCE_DIR}/jni.cpp
|
|
62
101
|
)
|
|
63
102
|
|
|
64
103
|
find_library(LOG_LIB log)
|
|
@@ -78,13 +117,13 @@ function(build_library target_name cpu_flags)
|
|
|
78
117
|
target_compile_options(${target_name} PRIVATE -DCACTUS_ANDROID_ENABLE_LOGGING)
|
|
79
118
|
endif ()
|
|
80
119
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
120
|
+
target_compile_options(${target_name} PRIVATE -O3 -DNDEBUG)
|
|
121
|
+
target_compile_options(${target_name} PRIVATE -fvisibility=hidden -fvisibility-inlines-hidden)
|
|
122
|
+
target_compile_options(${target_name} PRIVATE -ffunction-sections -fdata-sections)
|
|
84
123
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
124
|
+
target_link_options(${target_name} PRIVATE -Wl,--gc-sections)
|
|
125
|
+
target_link_options(${target_name} PRIVATE -Wl,--exclude-libs,ALL)
|
|
126
|
+
target_link_options(${target_name} PRIVATE -flto)
|
|
88
127
|
|
|
89
128
|
endfunction()
|
|
90
129
|
|
|
@@ -101,4 +140,4 @@ if (${ANDROID_ABI} STREQUAL "arm64-v8a")
|
|
|
101
140
|
elseif (${ANDROID_ABI} STREQUAL "x86_64")
|
|
102
141
|
build_library("cactus_x86_64" "-march=x86-64" "-mtune=intel" "-msse4.2" "-mpopcnt")
|
|
103
142
|
|
|
104
|
-
endif ()
|
|
143
|
+
endif ()
|
|
@@ -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;
|
|
@@ -248,23 +249,31 @@ public class Cactus implements LifecycleEventListener {
|
|
|
248
249
|
}
|
|
249
250
|
|
|
250
251
|
public void completion(double id, final ReadableMap params, final Promise promise) {
|
|
252
|
+
Log.d(NAME, "🟢 BRIDGE: completion() method called with contextId=" + (int)id);
|
|
251
253
|
final int contextId = (int) id;
|
|
252
254
|
AsyncTask task = new AsyncTask<Void, Void, WritableMap>() {
|
|
253
255
|
private Exception exception;
|
|
254
256
|
|
|
255
257
|
@Override
|
|
256
258
|
protected WritableMap doInBackground(Void... voids) {
|
|
259
|
+
Log.d(NAME, "⚡ BRIDGE: AsyncTask doInBackground starting...");
|
|
257
260
|
try {
|
|
258
261
|
LlamaContext context = contexts.get(contextId);
|
|
259
262
|
if (context == null) {
|
|
263
|
+
Log.e(NAME, "❌ BRIDGE: Context not found for id=" + contextId);
|
|
260
264
|
throw new Exception("Context not found");
|
|
261
265
|
}
|
|
266
|
+
Log.d(NAME, "✅ BRIDGE: Context found, checking if predicting...");
|
|
262
267
|
if (context.isPredicting()) {
|
|
268
|
+
Log.e(NAME, "❌ BRIDGE: Context is busy (predicting)");
|
|
263
269
|
throw new Exception("Context is busy");
|
|
264
270
|
}
|
|
271
|
+
Log.d(NAME, "🚀 BRIDGE: About to call context.completion()...");
|
|
265
272
|
WritableMap result = context.completion(params);
|
|
273
|
+
Log.d(NAME, "✅ BRIDGE: context.completion() returned successfully");
|
|
266
274
|
return result;
|
|
267
275
|
} catch (Exception e) {
|
|
276
|
+
Log.e(NAME, "❌ BRIDGE: Exception in doInBackground: " + e.getMessage());
|
|
268
277
|
exception = e;
|
|
269
278
|
}
|
|
270
279
|
return null;
|
|
@@ -272,14 +281,19 @@ public class Cactus implements LifecycleEventListener {
|
|
|
272
281
|
|
|
273
282
|
@Override
|
|
274
283
|
protected void onPostExecute(WritableMap result) {
|
|
284
|
+
Log.d(NAME, "📤 BRIDGE: onPostExecute called");
|
|
275
285
|
if (exception != null) {
|
|
286
|
+
Log.e(NAME, "❌ BRIDGE: Rejecting promise with exception: " + exception.getMessage());
|
|
276
287
|
promise.reject(exception);
|
|
277
288
|
return;
|
|
278
289
|
}
|
|
290
|
+
Log.d(NAME, "✅ BRIDGE: Resolving promise with result");
|
|
279
291
|
promise.resolve(result);
|
|
280
292
|
tasks.remove(this);
|
|
293
|
+
Log.d(NAME, "🏁 BRIDGE: completion() finished successfully");
|
|
281
294
|
}
|
|
282
295
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
296
|
+
Log.d(NAME, "📋 BRIDGE: AsyncTask queued for execution");
|
|
283
297
|
tasks.put(task, "completion-" + contextId);
|
|
284
298
|
}
|
|
285
299
|
|
|
@@ -354,6 +368,38 @@ public class Cactus implements LifecycleEventListener {
|
|
|
354
368
|
tasks.put(task, "tokenize-" + contextId);
|
|
355
369
|
}
|
|
356
370
|
|
|
371
|
+
public void tokenize(double id, final String text, final ReadableArray mediaPaths, final Promise promise) {
|
|
372
|
+
final int contextId = (int) id;
|
|
373
|
+
AsyncTask task = new AsyncTask<Void, Void, WritableMap>() {
|
|
374
|
+
private Exception exception;
|
|
375
|
+
|
|
376
|
+
@Override
|
|
377
|
+
protected WritableMap doInBackground(Void... voids) {
|
|
378
|
+
try {
|
|
379
|
+
LlamaContext context = contexts.get(contextId);
|
|
380
|
+
if (context == null) {
|
|
381
|
+
throw new Exception("Context not found");
|
|
382
|
+
}
|
|
383
|
+
return context.tokenize(text, mediaPaths);
|
|
384
|
+
} catch (Exception e) {
|
|
385
|
+
exception = e;
|
|
386
|
+
}
|
|
387
|
+
return null;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
@Override
|
|
391
|
+
protected void onPostExecute(WritableMap result) {
|
|
392
|
+
if (exception != null) {
|
|
393
|
+
promise.reject(exception);
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
promise.resolve(result);
|
|
397
|
+
tasks.remove(this);
|
|
398
|
+
}
|
|
399
|
+
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
400
|
+
tasks.put(task, "tokenize-" + contextId);
|
|
401
|
+
}
|
|
402
|
+
|
|
357
403
|
public void detokenize(double id, final ReadableArray tokens, final Promise promise) {
|
|
358
404
|
final int contextId = (int) id;
|
|
359
405
|
AsyncTask task = new AsyncTask<Void, Void, String>() {
|
|
@@ -643,4 +689,423 @@ public class Cactus implements LifecycleEventListener {
|
|
|
643
689
|
}
|
|
644
690
|
contexts.clear();
|
|
645
691
|
}
|
|
692
|
+
|
|
693
|
+
public void initMultimodal(double id, final String mmprojPath, final boolean useGpu, final Promise promise) {
|
|
694
|
+
final int contextId = (int) id;
|
|
695
|
+
AsyncTask task = new AsyncTask<Void, Void, Boolean>() {
|
|
696
|
+
private Exception exception;
|
|
697
|
+
|
|
698
|
+
@Override
|
|
699
|
+
protected Boolean doInBackground(Void... voids) {
|
|
700
|
+
try {
|
|
701
|
+
LlamaContext context = contexts.get(contextId);
|
|
702
|
+
if (context == null) {
|
|
703
|
+
throw new Exception("Context not found");
|
|
704
|
+
}
|
|
705
|
+
return context.initMultimodal(mmprojPath, useGpu);
|
|
706
|
+
} catch (Exception e) {
|
|
707
|
+
exception = e;
|
|
708
|
+
}
|
|
709
|
+
return false;
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
@Override
|
|
713
|
+
protected void onPostExecute(Boolean result) {
|
|
714
|
+
if (exception != null) {
|
|
715
|
+
promise.reject(exception);
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
promise.resolve(result);
|
|
719
|
+
tasks.remove(this);
|
|
720
|
+
}
|
|
721
|
+
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
722
|
+
tasks.put(task, "initMultimodal-" + contextId);
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
public void isMultimodalEnabled(double id, final Promise promise) {
|
|
726
|
+
final int contextId = (int) id;
|
|
727
|
+
AsyncTask task = new AsyncTask<Void, Void, Boolean>() {
|
|
728
|
+
private Exception exception;
|
|
729
|
+
|
|
730
|
+
@Override
|
|
731
|
+
protected Boolean doInBackground(Void... voids) {
|
|
732
|
+
try {
|
|
733
|
+
LlamaContext context = contexts.get(contextId);
|
|
734
|
+
if (context == null) {
|
|
735
|
+
throw new Exception("Context not found");
|
|
736
|
+
}
|
|
737
|
+
return context.isMultimodalEnabled();
|
|
738
|
+
} catch (Exception e) {
|
|
739
|
+
exception = e;
|
|
740
|
+
}
|
|
741
|
+
return false;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
@Override
|
|
745
|
+
protected void onPostExecute(Boolean result) {
|
|
746
|
+
if (exception != null) {
|
|
747
|
+
promise.reject(exception);
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
promise.resolve(result);
|
|
751
|
+
tasks.remove(this);
|
|
752
|
+
}
|
|
753
|
+
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
754
|
+
tasks.put(task, "isMultimodalEnabled-" + contextId);
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
public void isMultimodalSupportVision(double id, final Promise promise) {
|
|
758
|
+
final int contextId = (int) id;
|
|
759
|
+
AsyncTask task = new AsyncTask<Void, Void, Boolean>() {
|
|
760
|
+
private Exception exception;
|
|
761
|
+
|
|
762
|
+
@Override
|
|
763
|
+
protected Boolean doInBackground(Void... voids) {
|
|
764
|
+
try {
|
|
765
|
+
LlamaContext context = contexts.get(contextId);
|
|
766
|
+
if (context == null) {
|
|
767
|
+
throw new Exception("Context not found");
|
|
768
|
+
}
|
|
769
|
+
return context.isMultimodalSupportVision();
|
|
770
|
+
} catch (Exception e) {
|
|
771
|
+
exception = e;
|
|
772
|
+
}
|
|
773
|
+
return false;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
@Override
|
|
777
|
+
protected void onPostExecute(Boolean result) {
|
|
778
|
+
if (exception != null) {
|
|
779
|
+
promise.reject(exception);
|
|
780
|
+
return;
|
|
781
|
+
}
|
|
782
|
+
promise.resolve(result);
|
|
783
|
+
tasks.remove(this);
|
|
784
|
+
}
|
|
785
|
+
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
786
|
+
tasks.put(task, "isMultimodalSupportVision-" + contextId);
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
public void isMultimodalSupportAudio(double id, final Promise promise) {
|
|
790
|
+
final int contextId = (int) id;
|
|
791
|
+
AsyncTask task = new AsyncTask<Void, Void, Boolean>() {
|
|
792
|
+
private Exception exception;
|
|
793
|
+
|
|
794
|
+
@Override
|
|
795
|
+
protected Boolean doInBackground(Void... voids) {
|
|
796
|
+
try {
|
|
797
|
+
LlamaContext context = contexts.get(contextId);
|
|
798
|
+
if (context == null) {
|
|
799
|
+
throw new Exception("Context not found");
|
|
800
|
+
}
|
|
801
|
+
return context.isMultimodalSupportAudio();
|
|
802
|
+
} catch (Exception e) {
|
|
803
|
+
exception = e;
|
|
804
|
+
}
|
|
805
|
+
return false;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
@Override
|
|
809
|
+
protected void onPostExecute(Boolean result) {
|
|
810
|
+
if (exception != null) {
|
|
811
|
+
promise.reject(exception);
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
promise.resolve(result);
|
|
815
|
+
tasks.remove(this);
|
|
816
|
+
}
|
|
817
|
+
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
818
|
+
tasks.put(task, "isMultimodalSupportAudio-" + contextId);
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
public void releaseMultimodal(double id, final Promise promise) {
|
|
822
|
+
final int contextId = (int) id;
|
|
823
|
+
AsyncTask task = new AsyncTask<Void, Void, Void>() {
|
|
824
|
+
private Exception exception;
|
|
825
|
+
|
|
826
|
+
@Override
|
|
827
|
+
protected Void doInBackground(Void... voids) {
|
|
828
|
+
try {
|
|
829
|
+
LlamaContext context = contexts.get(contextId);
|
|
830
|
+
if (context == null) {
|
|
831
|
+
throw new Exception("Context not found");
|
|
832
|
+
}
|
|
833
|
+
context.releaseMultimodal();
|
|
834
|
+
} catch (Exception e) {
|
|
835
|
+
exception = e;
|
|
836
|
+
}
|
|
837
|
+
return null;
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
@Override
|
|
841
|
+
protected void onPostExecute(Void result) {
|
|
842
|
+
if (exception != null) {
|
|
843
|
+
promise.reject(exception);
|
|
844
|
+
return;
|
|
845
|
+
}
|
|
846
|
+
promise.resolve(null);
|
|
847
|
+
tasks.remove(this);
|
|
848
|
+
}
|
|
849
|
+
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
850
|
+
tasks.put(task, "releaseMultimodal-" + contextId);
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
public void multimodalCompletion(double id, final String prompt, final ReadableArray mediaPaths, final ReadableMap params, final Promise promise) {
|
|
854
|
+
final int contextId = (int) id;
|
|
855
|
+
AsyncTask task = new AsyncTask<Void, Void, WritableMap>() {
|
|
856
|
+
private Exception exception;
|
|
857
|
+
|
|
858
|
+
@Override
|
|
859
|
+
protected WritableMap doInBackground(Void... voids) {
|
|
860
|
+
try {
|
|
861
|
+
LlamaContext context = contexts.get(contextId);
|
|
862
|
+
if (context == null) {
|
|
863
|
+
throw new Exception("Context not found");
|
|
864
|
+
}
|
|
865
|
+
if (context.isPredicting()) {
|
|
866
|
+
throw new Exception("Context is busy");
|
|
867
|
+
}
|
|
868
|
+
return context.multimodalCompletion(prompt, mediaPaths, params);
|
|
869
|
+
} catch (Exception e) {
|
|
870
|
+
exception = e;
|
|
871
|
+
}
|
|
872
|
+
return null;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
@Override
|
|
876
|
+
protected void onPostExecute(WritableMap result) {
|
|
877
|
+
if (exception != null) {
|
|
878
|
+
promise.reject(exception);
|
|
879
|
+
return;
|
|
880
|
+
}
|
|
881
|
+
promise.resolve(result);
|
|
882
|
+
tasks.remove(this);
|
|
883
|
+
}
|
|
884
|
+
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
885
|
+
tasks.put(task, "multimodalCompletion-" + contextId);
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
public void initVocoder(double id, final String vocoderModelPath, final Promise promise) {
|
|
889
|
+
final int contextId = (int) id;
|
|
890
|
+
AsyncTask task = new AsyncTask<Void, Void, Boolean>() {
|
|
891
|
+
private Exception exception;
|
|
892
|
+
|
|
893
|
+
@Override
|
|
894
|
+
protected Boolean doInBackground(Void... voids) {
|
|
895
|
+
try {
|
|
896
|
+
LlamaContext context = contexts.get(contextId);
|
|
897
|
+
if (context == null) {
|
|
898
|
+
throw new Exception("Context not found");
|
|
899
|
+
}
|
|
900
|
+
return context.initVocoder(vocoderModelPath);
|
|
901
|
+
} catch (Exception e) {
|
|
902
|
+
exception = e;
|
|
903
|
+
}
|
|
904
|
+
return false;
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
@Override
|
|
908
|
+
protected void onPostExecute(Boolean result) {
|
|
909
|
+
if (exception != null) {
|
|
910
|
+
promise.reject(exception);
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
913
|
+
promise.resolve(result);
|
|
914
|
+
tasks.remove(this);
|
|
915
|
+
}
|
|
916
|
+
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
917
|
+
tasks.put(task, "initVocoder-" + contextId);
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
public void isVocoderEnabled(double id, final Promise promise) {
|
|
921
|
+
final int contextId = (int) id;
|
|
922
|
+
AsyncTask task = new AsyncTask<Void, Void, Boolean>() {
|
|
923
|
+
private Exception exception;
|
|
924
|
+
|
|
925
|
+
@Override
|
|
926
|
+
protected Boolean doInBackground(Void... voids) {
|
|
927
|
+
try {
|
|
928
|
+
LlamaContext context = contexts.get(contextId);
|
|
929
|
+
if (context == null) {
|
|
930
|
+
throw new Exception("Context not found");
|
|
931
|
+
}
|
|
932
|
+
return context.isVocoderEnabled();
|
|
933
|
+
} catch (Exception e) {
|
|
934
|
+
exception = e;
|
|
935
|
+
}
|
|
936
|
+
return false;
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
@Override
|
|
940
|
+
protected void onPostExecute(Boolean result) {
|
|
941
|
+
if (exception != null) {
|
|
942
|
+
promise.reject(exception);
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
promise.resolve(result);
|
|
946
|
+
tasks.remove(this);
|
|
947
|
+
}
|
|
948
|
+
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
949
|
+
tasks.put(task, "isVocoderEnabled-" + contextId);
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
public void getTTSType(double id, final Promise promise) {
|
|
953
|
+
final int contextId = (int) id;
|
|
954
|
+
AsyncTask task = new AsyncTask<Void, Void, Integer>() {
|
|
955
|
+
private Exception exception;
|
|
956
|
+
|
|
957
|
+
@Override
|
|
958
|
+
protected Integer doInBackground(Void... voids) {
|
|
959
|
+
try {
|
|
960
|
+
LlamaContext context = contexts.get(contextId);
|
|
961
|
+
if (context == null) {
|
|
962
|
+
throw new Exception("Context not found");
|
|
963
|
+
}
|
|
964
|
+
return context.getTTSType();
|
|
965
|
+
} catch (Exception e) {
|
|
966
|
+
exception = e;
|
|
967
|
+
}
|
|
968
|
+
return -1;
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
@Override
|
|
972
|
+
protected void onPostExecute(Integer result) {
|
|
973
|
+
if (exception != null) {
|
|
974
|
+
promise.reject(exception);
|
|
975
|
+
return;
|
|
976
|
+
}
|
|
977
|
+
promise.resolve(result);
|
|
978
|
+
tasks.remove(this);
|
|
979
|
+
}
|
|
980
|
+
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
981
|
+
tasks.put(task, "getTTSType-" + contextId);
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
public void getFormattedAudioCompletion(double id, final String speakerJsonStr, final String textToSpeak, final Promise promise) {
|
|
985
|
+
final int contextId = (int) id;
|
|
986
|
+
AsyncTask task = new AsyncTask<Void, Void, String>() {
|
|
987
|
+
private Exception exception;
|
|
988
|
+
|
|
989
|
+
@Override
|
|
990
|
+
protected String doInBackground(Void... voids) {
|
|
991
|
+
try {
|
|
992
|
+
LlamaContext context = contexts.get(contextId);
|
|
993
|
+
if (context == null) {
|
|
994
|
+
throw new Exception("Context not found");
|
|
995
|
+
}
|
|
996
|
+
return context.getFormattedAudioCompletion(speakerJsonStr, textToSpeak);
|
|
997
|
+
} catch (Exception e) {
|
|
998
|
+
exception = e;
|
|
999
|
+
}
|
|
1000
|
+
return null;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
@Override
|
|
1004
|
+
protected void onPostExecute(String result) {
|
|
1005
|
+
if (exception != null) {
|
|
1006
|
+
promise.reject(exception);
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
promise.resolve(result);
|
|
1010
|
+
tasks.remove(this);
|
|
1011
|
+
}
|
|
1012
|
+
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
1013
|
+
tasks.put(task, "getFormattedAudioCompletion-" + contextId);
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
public void getAudioCompletionGuideTokens(double id, final String textToSpeak, final Promise promise) {
|
|
1017
|
+
final int contextId = (int) id;
|
|
1018
|
+
AsyncTask task = new AsyncTask<Void, Void, WritableArray>() {
|
|
1019
|
+
private Exception exception;
|
|
1020
|
+
|
|
1021
|
+
@Override
|
|
1022
|
+
protected WritableArray doInBackground(Void... voids) {
|
|
1023
|
+
try {
|
|
1024
|
+
LlamaContext context = contexts.get(contextId);
|
|
1025
|
+
if (context == null) {
|
|
1026
|
+
throw new Exception("Context not found");
|
|
1027
|
+
}
|
|
1028
|
+
return context.getAudioCompletionGuideTokens(textToSpeak);
|
|
1029
|
+
} catch (Exception e) {
|
|
1030
|
+
exception = e;
|
|
1031
|
+
}
|
|
1032
|
+
return null;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
@Override
|
|
1036
|
+
protected void onPostExecute(WritableArray result) {
|
|
1037
|
+
if (exception != null) {
|
|
1038
|
+
promise.reject(exception);
|
|
1039
|
+
return;
|
|
1040
|
+
}
|
|
1041
|
+
promise.resolve(result);
|
|
1042
|
+
tasks.remove(this);
|
|
1043
|
+
}
|
|
1044
|
+
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
1045
|
+
tasks.put(task, "getAudioCompletionGuideTokens-" + contextId);
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
public void decodeAudioTokens(double id, final ReadableArray tokens, final Promise promise) {
|
|
1049
|
+
final int contextId = (int) id;
|
|
1050
|
+
AsyncTask task = new AsyncTask<Void, Void, WritableArray>() {
|
|
1051
|
+
private Exception exception;
|
|
1052
|
+
|
|
1053
|
+
@Override
|
|
1054
|
+
protected WritableArray doInBackground(Void... voids) {
|
|
1055
|
+
try {
|
|
1056
|
+
LlamaContext context = contexts.get(contextId);
|
|
1057
|
+
if (context == null) {
|
|
1058
|
+
throw new Exception("Context not found");
|
|
1059
|
+
}
|
|
1060
|
+
return context.decodeAudioTokens(tokens);
|
|
1061
|
+
} catch (Exception e) {
|
|
1062
|
+
exception = e;
|
|
1063
|
+
}
|
|
1064
|
+
return null;
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
@Override
|
|
1068
|
+
protected void onPostExecute(WritableArray result) {
|
|
1069
|
+
if (exception != null) {
|
|
1070
|
+
promise.reject(exception);
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
promise.resolve(result);
|
|
1074
|
+
tasks.remove(this);
|
|
1075
|
+
}
|
|
1076
|
+
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
1077
|
+
tasks.put(task, "decodeAudioTokens-" + contextId);
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
public void releaseVocoder(double id, final Promise promise) {
|
|
1081
|
+
final int contextId = (int) id;
|
|
1082
|
+
AsyncTask task = new AsyncTask<Void, Void, Void>() {
|
|
1083
|
+
private Exception exception;
|
|
1084
|
+
|
|
1085
|
+
@Override
|
|
1086
|
+
protected Void doInBackground(Void... voids) {
|
|
1087
|
+
try {
|
|
1088
|
+
LlamaContext context = contexts.get(contextId);
|
|
1089
|
+
if (context == null) {
|
|
1090
|
+
throw new Exception("Context not found");
|
|
1091
|
+
}
|
|
1092
|
+
context.releaseVocoder();
|
|
1093
|
+
} catch (Exception e) {
|
|
1094
|
+
exception = e;
|
|
1095
|
+
}
|
|
1096
|
+
return null;
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
@Override
|
|
1100
|
+
protected void onPostExecute(Void result) {
|
|
1101
|
+
if (exception != null) {
|
|
1102
|
+
promise.reject(exception);
|
|
1103
|
+
return;
|
|
1104
|
+
}
|
|
1105
|
+
promise.resolve(null);
|
|
1106
|
+
tasks.remove(this);
|
|
1107
|
+
}
|
|
1108
|
+
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
1109
|
+
tasks.put(task, "releaseVocoder-" + contextId);
|
|
1110
|
+
}
|
|
646
1111
|
}
|