cactus-react-native 0.2.11 → 1.0.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/Cactus.podspec +34 -0
- package/LICENSE +38 -0
- package/README.md +354 -69
- package/android/CMakeLists.txt +40 -0
- package/android/build.gradle +68 -44
- package/android/gradle.properties +5 -5
- package/android/src/main/AndroidManifest.xml +1 -3
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/cactus/CactusPackage.kt +22 -0
- package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusCrypto.kt +38 -0
- package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusDeviceInfo.kt +24 -0
- package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusFileSystem.kt +227 -0
- package/android/src/main/jniLibs/arm64-v8a/{libcactus_v8_2_dotprod.so → libcactus.a} +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_util.so +0 -0
- package/cpp/HybridCactus.cpp +123 -0
- package/cpp/HybridCactus.hpp +35 -0
- package/cpp/HybridCactusUtil.cpp +45 -0
- package/cpp/HybridCactusUtil.hpp +26 -0
- package/cpp/cactus_ffi.h +55 -0
- package/cpp/cactus_util.h +25 -0
- package/ios/HybridCactusCrypto.swift +37 -0
- package/ios/HybridCactusDeviceInfo.swift +32 -0
- package/ios/HybridCactusFileSystem.swift +234 -0
- package/ios/cactus.xcframework/{info.plist → Info.plist} +2 -37
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus.h +8 -229
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_ffi.h +28 -229
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/engine.h +347 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ffi_utils.h +286 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/graph.h +319 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel.h +254 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel_utils.h +343 -0
- 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-simulator/cactus.framework/Headers/cactus.h +11 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_ffi.h +55 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/engine.h +347 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/ffi_utils.h +286 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/graph.h +319 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel.h +254 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel_utils.h +343 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Info.plist +0 -0
- package/ios/cactus.xcframework/{tvos-arm64_x86_64-simulator → ios-arm64-simulator}/cactus.framework/_CodeSignature/CodeResources +1 -1
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/cactus +0 -0
- package/ios/cactus_util.xcframework/Info.plist +39 -0
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/cactus_util.h +25 -0
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/ios_utils.h +10 -0
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/logging.h +25 -0
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Info.plist +0 -0
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/cactus_util +0 -0
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/cactus_util.h +25 -0
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/ios_utils.h +10 -0
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/logging.h +25 -0
- package/ios/{cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework → cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework}/Info.plist +0 -0
- package/ios/{cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework → cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework}/_CodeSignature/CodeResources +36 -2
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/cactus_util +0 -0
- package/lib/module/api/Database.js +60 -0
- package/lib/module/api/Database.js.map +1 -0
- package/lib/module/classes/CactusLM.js +149 -0
- package/lib/module/classes/CactusLM.js.map +1 -0
- package/lib/module/config/CactusConfig.js +6 -0
- package/lib/module/config/CactusConfig.js.map +1 -0
- package/lib/module/constants/packageVersion.js +4 -0
- package/lib/module/constants/packageVersion.js.map +1 -0
- package/lib/module/hooks/useCactusLM.js +233 -0
- package/lib/module/hooks/useCactusLM.js.map +1 -0
- package/lib/module/index.js +9 -409
- package/lib/module/index.js.map +1 -1
- package/lib/module/native/Cactus.js +50 -0
- package/lib/module/native/Cactus.js.map +1 -0
- package/lib/module/native/CactusCrypto.js +10 -0
- package/lib/module/native/CactusCrypto.js.map +1 -0
- package/lib/module/native/CactusDeviceInfo.js +13 -0
- package/lib/module/native/CactusDeviceInfo.js.map +1 -0
- package/lib/module/native/CactusFileSystem.js +35 -0
- package/lib/module/native/CactusFileSystem.js.map +1 -0
- package/lib/module/native/CactusUtil.js +23 -0
- package/lib/module/native/CactusUtil.js.map +1 -0
- package/lib/module/native/index.js +8 -0
- package/lib/module/native/index.js.map +1 -0
- package/lib/module/specs/Cactus.nitro.js +4 -0
- package/lib/module/specs/Cactus.nitro.js.map +1 -0
- package/lib/module/specs/CactusCrypto.nitro.js +4 -0
- package/lib/module/specs/CactusCrypto.nitro.js.map +1 -0
- package/lib/module/specs/CactusDeviceInfo.nitro.js +4 -0
- package/lib/module/specs/CactusDeviceInfo.nitro.js.map +1 -0
- package/lib/module/specs/CactusFileSystem.nitro.js +4 -0
- package/lib/module/specs/CactusFileSystem.nitro.js.map +1 -0
- package/lib/module/specs/CactusUtil.nitro.js +4 -0
- package/lib/module/specs/CactusUtil.nitro.js.map +1 -0
- package/lib/module/telemetry/Telemetry.js +100 -0
- package/lib/module/telemetry/Telemetry.js.map +1 -0
- package/lib/module/types/CactusLM.js +2 -0
- package/lib/module/types/CactusLM.js.map +1 -0
- package/lib/module/types/CactusModel.js +2 -0
- package/lib/module/types/CactusModel.js.map +1 -0
- package/lib/module/utils/error.js +4 -0
- package/lib/module/utils/error.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/api/Database.d.ts +11 -0
- package/lib/typescript/src/api/Database.d.ts.map +1 -0
- package/lib/typescript/src/classes/CactusLM.d.ts +25 -0
- package/lib/typescript/src/classes/CactusLM.d.ts.map +1 -0
- package/lib/typescript/src/config/CactusConfig.d.ts +5 -0
- package/lib/typescript/src/config/CactusConfig.d.ts.map +1 -0
- package/lib/typescript/src/constants/packageVersion.d.ts +2 -0
- package/lib/typescript/src/constants/packageVersion.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useCactusLM.d.ts +20 -0
- package/lib/typescript/src/hooks/useCactusLM.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +6 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/native/Cactus.d.ts +11 -0
- package/lib/typescript/src/native/Cactus.d.ts.map +1 -0
- package/lib/typescript/src/native/CactusCrypto.d.ts +5 -0
- package/lib/typescript/src/native/CactusCrypto.d.ts.map +1 -0
- package/lib/typescript/src/native/CactusDeviceInfo.d.ts +7 -0
- package/lib/typescript/src/native/CactusDeviceInfo.d.ts.map +1 -0
- package/lib/typescript/src/native/CactusFileSystem.d.ts +13 -0
- package/lib/typescript/src/native/CactusFileSystem.d.ts.map +1 -0
- package/lib/typescript/src/native/CactusUtil.d.ts +6 -0
- package/lib/typescript/src/native/CactusUtil.d.ts.map +1 -0
- package/lib/typescript/src/native/index.d.ts +6 -0
- package/lib/typescript/src/native/index.d.ts.map +1 -0
- package/lib/typescript/src/specs/Cactus.nitro.d.ts +13 -0
- package/lib/typescript/src/specs/Cactus.nitro.d.ts.map +1 -0
- package/lib/typescript/src/specs/CactusCrypto.nitro.d.ts +8 -0
- package/lib/typescript/src/specs/CactusCrypto.nitro.d.ts.map +1 -0
- package/lib/typescript/src/specs/CactusDeviceInfo.nitro.d.ts +16 -0
- package/lib/typescript/src/specs/CactusDeviceInfo.nitro.d.ts.map +1 -0
- package/lib/typescript/src/specs/CactusFileSystem.nitro.d.ts +16 -0
- package/lib/typescript/src/specs/CactusFileSystem.nitro.d.ts.map +1 -0
- package/lib/typescript/src/specs/CactusUtil.nitro.d.ts +10 -0
- package/lib/typescript/src/specs/CactusUtil.nitro.d.ts.map +1 -0
- package/lib/typescript/src/telemetry/Telemetry.d.ts +30 -0
- package/lib/typescript/src/telemetry/Telemetry.d.ts.map +1 -0
- package/lib/typescript/src/types/CactusLM.d.ts +65 -0
- package/lib/typescript/src/types/CactusLM.d.ts.map +1 -0
- package/lib/typescript/src/types/CactusModel.d.ts +12 -0
- package/lib/typescript/src/types/CactusModel.d.ts.map +1 -0
- package/lib/typescript/src/utils/error.d.ts +2 -0
- package/lib/typescript/src/utils/error.d.ts.map +1 -0
- package/nitro.json +31 -0
- package/nitrogen/generated/android/c++/JDeviceInfo.hpp +74 -0
- package/nitrogen/generated/android/c++/JFunc_void_double.hpp +74 -0
- package/nitrogen/generated/android/c++/JHybridCactusCryptoSpec.cpp +65 -0
- package/nitrogen/generated/android/c++/JHybridCactusCryptoSpec.hpp +65 -0
- package/nitrogen/generated/android/c++/JHybridCactusDeviceInfoSpec.cpp +85 -0
- package/nitrogen/generated/android/c++/JHybridCactusDeviceInfoSpec.hpp +66 -0
- package/nitrogen/generated/android/c++/JHybridCactusFileSystemSpec.cpp +192 -0
- package/nitrogen/generated/android/c++/JHybridCactusFileSystemSpec.hpp +73 -0
- package/nitrogen/generated/android/cactus+autolinking.cmake +87 -0
- package/nitrogen/generated/android/cactus+autolinking.gradle +27 -0
- package/nitrogen/generated/android/cactusOnLoad.cpp +86 -0
- package/nitrogen/generated/android/cactusOnLoad.hpp +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/DeviceInfo.kt +50 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/Func_void_double.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusCryptoSpec.kt +58 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusDeviceInfoSpec.kt +62 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusFileSystemSpec.kt +95 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/cactusOnLoad.kt +35 -0
- package/nitrogen/generated/ios/Cactus+autolinking.rb +60 -0
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.cpp +122 -0
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.hpp +373 -0
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Umbrella.hpp +60 -0
- package/nitrogen/generated/ios/CactusAutolinking.mm +69 -0
- package/nitrogen/generated/ios/CactusAutolinking.swift +55 -0
- package/nitrogen/generated/ios/c++/HybridCactusCryptoSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridCactusCryptoSpecSwift.hpp +77 -0
- package/nitrogen/generated/ios/c++/HybridCactusDeviceInfoSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridCactusDeviceInfoSpecSwift.hpp +88 -0
- package/nitrogen/generated/ios/c++/HybridCactusFileSystemSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridCactusFileSystemSpecSwift.hpp +143 -0
- package/nitrogen/generated/ios/swift/DeviceInfo.swift +98 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_DeviceInfo.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_double.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__optional_std__string_.swift +54 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +47 -0
- package/nitrogen/generated/ios/swift/HybridCactusCryptoSpec.swift +57 -0
- package/nitrogen/generated/ios/swift/HybridCactusCryptoSpec_cxx.swift +139 -0
- package/nitrogen/generated/ios/swift/HybridCactusDeviceInfoSpec.swift +58 -0
- package/nitrogen/generated/ios/swift/HybridCactusDeviceInfoSpec_cxx.swift +164 -0
- package/nitrogen/generated/ios/swift/HybridCactusFileSystemSpec.swift +65 -0
- package/nitrogen/generated/ios/swift/HybridCactusFileSystemSpec_cxx.swift +303 -0
- package/nitrogen/generated/shared/c++/DeviceInfo.hpp +92 -0
- package/nitrogen/generated/shared/c++/HybridCactusCryptoSpec.cpp +21 -0
- package/nitrogen/generated/shared/c++/HybridCactusCryptoSpec.hpp +63 -0
- package/nitrogen/generated/shared/c++/HybridCactusDeviceInfoSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridCactusDeviceInfoSpec.hpp +67 -0
- package/nitrogen/generated/shared/c++/HybridCactusFileSystemSpec.cpp +29 -0
- package/nitrogen/generated/shared/c++/HybridCactusFileSystemSpec.hpp +73 -0
- package/nitrogen/generated/shared/c++/HybridCactusSpec.cpp +26 -0
- package/nitrogen/generated/shared/c++/HybridCactusSpec.hpp +71 -0
- package/nitrogen/generated/shared/c++/HybridCactusUtilSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridCactusUtilSpec.hpp +66 -0
- package/package.json +84 -143
- package/src/api/Database.ts +83 -0
- package/src/classes/CactusLM.ts +203 -0
- package/src/config/CactusConfig.ts +4 -0
- package/src/constants/packageVersion.ts +1 -0
- package/src/hooks/useCactusLM.ts +282 -0
- package/src/index.tsx +23 -0
- package/src/native/Cactus.ts +79 -0
- package/src/native/CactusCrypto.ts +11 -0
- package/src/native/CactusDeviceInfo.ts +18 -0
- package/src/native/CactusFileSystem.ts +47 -0
- package/src/native/CactusUtil.ts +27 -0
- package/src/native/index.ts +5 -0
- package/src/specs/Cactus.nitro.ts +16 -0
- package/src/specs/CactusCrypto.nitro.ts +6 -0
- package/src/specs/CactusDeviceInfo.nitro.ts +15 -0
- package/src/specs/CactusFileSystem.nitro.ts +21 -0
- package/src/specs/CactusUtil.nitro.ts +8 -0
- package/src/telemetry/Telemetry.ts +159 -0
- package/src/types/CactusLM.ts +71 -0
- package/src/types/CactusModel.ts +14 -0
- package/src/utils/error.ts +2 -0
- package/LICENSE.txt +0 -20
- package/android/src/main/CMakeLists.txt +0 -140
- package/android/src/main/java/com/cactus/Cactus.java +0 -1190
- package/android/src/main/java/com/cactus/CactusPackage.java +0 -48
- package/android/src/main/java/com/cactus/LlamaContext.java +0 -748
- package/android/src/main/jni-utils.h +0 -100
- package/android/src/main/jni.cpp +0 -1605
- 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_i8mm.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2_i8mm.so +0 -0
- package/android/src/newarch/java/com/cactus/CactusModule.java +0 -204
- package/android/src/oldarch/java/com/cactus/CactusModule.java +0 -205
- package/cactus-react-native.podspec +0 -42
- package/ios/CMakeLists.txt +0 -131
- package/ios/Cactus.h +0 -6
- package/ios/Cactus.mm +0 -681
- package/ios/CactusContext.h +0 -81
- package/ios/CactusContext.mm +0 -1032
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/chat.h +0 -145
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/common.h +0 -674
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-alloc.h +0 -76
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-backend-impl.h +0 -255
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-backend.h +0 -354
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-common.h +0 -1857
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpp.h +0 -39
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpu.h +0 -143
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-impl.h +0 -601
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-metal-impl.h +0 -622
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-metal.h +0 -66
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-opt.h +0 -237
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-quants.h +0 -100
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-threading.h +0 -14
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml.h +0 -2202
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/gguf.h +0 -202
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/json-schema-to-grammar.h +0 -21
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/json.hpp +0 -24766
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-adapter.h +0 -76
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-arch.h +0 -437
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-batch.h +0 -89
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-chat.h +0 -58
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-context.h +0 -276
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-cparams.h +0 -39
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-cpp.h +0 -30
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-grammar.h +0 -173
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-graph.h +0 -640
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-hparams.h +0 -190
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-impl.h +0 -61
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-io.h +0 -35
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-kv-cache.h +0 -515
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-memory.h +0 -32
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-mmap.h +0 -68
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-model-loader.h +0 -169
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-model-saver.h +0 -37
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-model.h +0 -425
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-sampling.h +0 -32
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-vocab.h +0 -131
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama.h +0 -1376
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/log.h +0 -103
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/minja/chat-template.hpp +0 -542
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/minja/minja.hpp +0 -2974
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/sampling.h +0 -107
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/unicode-data.h +0 -20
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/unicode.h +0 -66
- 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 +0 -232
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/cactus_ffi.h +0 -256
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/chat.h +0 -145
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/common.h +0 -674
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-alloc.h +0 -76
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-backend-impl.h +0 -255
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-backend.h +0 -354
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-common.h +0 -1857
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpp.h +0 -39
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu.h +0 -143
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-impl.h +0 -601
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-metal-impl.h +0 -622
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-metal.h +0 -66
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-opt.h +0 -237
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-quants.h +0 -100
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-threading.h +0 -14
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml.h +0 -2202
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/gguf.h +0 -202
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/json-schema-to-grammar.h +0 -21
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/json.hpp +0 -24766
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-adapter.h +0 -76
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-arch.h +0 -437
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-batch.h +0 -89
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-chat.h +0 -58
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-context.h +0 -276
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-cparams.h +0 -39
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-cpp.h +0 -30
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-grammar.h +0 -173
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-graph.h +0 -640
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-hparams.h +0 -190
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-impl.h +0 -61
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-io.h +0 -35
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-kv-cache.h +0 -515
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-memory.h +0 -32
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-mmap.h +0 -68
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-model-loader.h +0 -169
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-model-saver.h +0 -37
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-model.h +0 -425
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-sampling.h +0 -32
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-vocab.h +0 -131
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama.h +0 -1376
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/log.h +0 -103
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/minja/chat-template.hpp +0 -542
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/minja/minja.hpp +0 -2974
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/sampling.h +0 -107
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/unicode-data.h +0 -20
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/unicode.h +0 -66
- 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 +0 -232
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/cactus_ffi.h +0 -256
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/chat.h +0 -145
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/common.h +0 -674
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-alloc.h +0 -76
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-backend-impl.h +0 -255
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-backend.h +0 -354
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-common.h +0 -1857
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpp.h +0 -39
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpu.h +0 -143
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-impl.h +0 -601
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-metal-impl.h +0 -622
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-metal.h +0 -66
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-opt.h +0 -237
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-quants.h +0 -100
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-threading.h +0 -14
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml.h +0 -2202
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/gguf.h +0 -202
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/json-schema-to-grammar.h +0 -21
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/json.hpp +0 -24766
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-adapter.h +0 -76
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-arch.h +0 -437
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-batch.h +0 -89
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-chat.h +0 -58
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-context.h +0 -276
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-cparams.h +0 -39
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-cpp.h +0 -30
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-grammar.h +0 -173
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-graph.h +0 -640
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-hparams.h +0 -190
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-impl.h +0 -61
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-io.h +0 -35
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-kv-cache.h +0 -515
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-memory.h +0 -32
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-mmap.h +0 -68
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-model-loader.h +0 -169
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-model-saver.h +0 -37
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-model.h +0 -425
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-sampling.h +0 -32
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-vocab.h +0 -131
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama.h +0 -1376
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/log.h +0 -103
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/minja/chat-template.hpp +0 -542
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/minja/minja.hpp +0 -2974
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/sampling.h +0 -107
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/unicode-data.h +0 -20
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/unicode.h +0 -66
- 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 +0 -232
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/cactus_ffi.h +0 -256
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/chat.h +0 -145
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/common.h +0 -674
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-alloc.h +0 -76
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-backend-impl.h +0 -255
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-backend.h +0 -354
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-common.h +0 -1857
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpp.h +0 -39
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu.h +0 -143
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-impl.h +0 -601
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-metal-impl.h +0 -622
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-metal.h +0 -66
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-opt.h +0 -237
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-quants.h +0 -100
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-threading.h +0 -14
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml.h +0 -2202
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/gguf.h +0 -202
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/json-schema-to-grammar.h +0 -21
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/json.hpp +0 -24766
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-adapter.h +0 -76
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-arch.h +0 -437
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-batch.h +0 -89
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-chat.h +0 -58
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-context.h +0 -276
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-cparams.h +0 -39
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-cpp.h +0 -30
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-grammar.h +0 -173
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-graph.h +0 -640
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-hparams.h +0 -190
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-impl.h +0 -61
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-io.h +0 -35
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-kv-cache.h +0 -515
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-memory.h +0 -32
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-mmap.h +0 -68
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-model-loader.h +0 -169
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-model-saver.h +0 -37
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-model.h +0 -425
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-sampling.h +0 -32
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-vocab.h +0 -131
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama.h +0 -1376
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/log.h +0 -103
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/minja/chat-template.hpp +0 -542
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/minja/minja.hpp +0 -2974
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/sampling.h +0 -107
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/unicode-data.h +0 -20
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/unicode.h +0 -66
- 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/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 +0 -9
- package/lib/commonjs/NativeCactus.js.map +0 -1
- package/lib/commonjs/agent.js +0 -73
- package/lib/commonjs/agent.js.map +0 -1
- package/lib/commonjs/chat.js +0 -73
- package/lib/commonjs/chat.js.map +0 -1
- package/lib/commonjs/index.js +0 -523
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/lm.js +0 -272
- package/lib/commonjs/lm.js.map +0 -1
- package/lib/commonjs/package.json +0 -1
- package/lib/commonjs/projectId.js +0 -9
- package/lib/commonjs/projectId.js.map +0 -1
- package/lib/commonjs/remote.js +0 -100
- package/lib/commonjs/remote.js.map +0 -1
- package/lib/commonjs/telemetry.js +0 -102
- package/lib/commonjs/telemetry.js.map +0 -1
- package/lib/commonjs/tools.js +0 -72
- package/lib/commonjs/tools.js.map +0 -1
- package/lib/commonjs/tts.js +0 -141
- package/lib/commonjs/tts.js.map +0 -1
- package/lib/commonjs/vlm.js +0 -221
- package/lib/commonjs/vlm.js.map +0 -1
- package/lib/module/NativeCactus.js +0 -5
- package/lib/module/NativeCactus.js.map +0 -1
- package/lib/module/agent.js +0 -68
- package/lib/module/agent.js.map +0 -1
- package/lib/module/chat.js +0 -67
- package/lib/module/chat.js.map +0 -1
- package/lib/module/lm.js +0 -267
- package/lib/module/lm.js.map +0 -1
- package/lib/module/projectId.js +0 -5
- package/lib/module/projectId.js.map +0 -1
- package/lib/module/remote.js +0 -91
- package/lib/module/remote.js.map +0 -1
- package/lib/module/telemetry.js +0 -97
- package/lib/module/telemetry.js.map +0 -1
- package/lib/module/tools.js +0 -66
- package/lib/module/tools.js.map +0 -1
- package/lib/module/tts.js +0 -135
- package/lib/module/tts.js.map +0 -1
- package/lib/module/vlm.js +0 -216
- package/lib/module/vlm.js.map +0 -1
- package/lib/typescript/NativeCactus.d.ts +0 -252
- package/lib/typescript/NativeCactus.d.ts.map +0 -1
- package/lib/typescript/agent.d.ts +0 -31
- package/lib/typescript/agent.d.ts.map +0 -1
- package/lib/typescript/chat.d.ts +0 -23
- package/lib/typescript/chat.d.ts.map +0 -1
- package/lib/typescript/index.d.ts +0 -114
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/lm.d.ts +0 -36
- package/lib/typescript/lm.d.ts.map +0 -1
- package/lib/typescript/projectId.d.ts +0 -2
- package/lib/typescript/projectId.d.ts.map +0 -1
- package/lib/typescript/remote.d.ts +0 -8
- package/lib/typescript/remote.d.ts.map +0 -1
- package/lib/typescript/telemetry.d.ts +0 -25
- package/lib/typescript/telemetry.d.ts.map +0 -1
- package/lib/typescript/tools.d.ts +0 -36
- package/lib/typescript/tools.d.ts.map +0 -1
- package/lib/typescript/tts.d.ts +0 -54
- package/lib/typescript/tts.d.ts.map +0 -1
- package/lib/typescript/vlm.d.ts +0 -33
- package/lib/typescript/vlm.d.ts.map +0 -1
- package/scripts/postInstall.js +0 -33
- package/src/NativeCactus.ts +0 -317
- package/src/agent.ts +0 -112
- package/src/chat.ts +0 -91
- package/src/index.ts +0 -663
- package/src/lm.ts +0 -324
- package/src/projectId.ts +0 -1
- package/src/remote.ts +0 -113
- package/src/telemetry.ts +0 -137
- package/src/tools.ts +0 -94
- package/src/tts.ts +0 -236
- package/src/vlm.ts +0 -276
package/android/build.gradle
CHANGED
|
@@ -1,60 +1,94 @@
|
|
|
1
1
|
buildscript {
|
|
2
|
+
ext.getExtOrDefault = {name ->
|
|
3
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['Cactus_' + name]
|
|
4
|
+
}
|
|
5
|
+
|
|
2
6
|
repositories {
|
|
3
7
|
google()
|
|
4
8
|
mavenCentral()
|
|
5
9
|
}
|
|
6
10
|
|
|
7
11
|
dependencies {
|
|
8
|
-
classpath "com.android.tools.build:gradle:7.2
|
|
12
|
+
classpath "com.android.tools.build:gradle:8.7.2"
|
|
13
|
+
// noinspection DifferentKotlinGradleVersion
|
|
14
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
|
|
9
15
|
}
|
|
10
16
|
}
|
|
11
17
|
|
|
12
|
-
def
|
|
13
|
-
|
|
18
|
+
def reactNativeArchitectures() {
|
|
19
|
+
def value = rootProject.getProperties().get("reactNativeArchitectures")
|
|
20
|
+
return value ? value.split(",") : ["arm64-v8a"]
|
|
14
21
|
}
|
|
15
22
|
|
|
16
23
|
apply plugin: "com.android.library"
|
|
24
|
+
apply plugin: "kotlin-android"
|
|
25
|
+
apply from: '../nitrogen/generated/android/cactus+autolinking.gradle'
|
|
17
26
|
|
|
18
|
-
|
|
19
|
-
def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
|
|
20
|
-
|
|
21
|
-
if (isNewArchitectureEnabled()) {
|
|
22
|
-
apply plugin: "com.facebook.react"
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
def getExtOrDefault(name) {
|
|
26
|
-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Cactus_" + name]
|
|
27
|
-
}
|
|
27
|
+
apply plugin: "com.facebook.react"
|
|
28
28
|
|
|
29
29
|
def getExtOrIntegerDefault(name) {
|
|
30
30
|
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Cactus_" + name]).toInteger()
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
def reactNativeArchitectures() {
|
|
34
|
-
def value = project.getProperties().get("reactNativeArchitectures")
|
|
35
|
-
def archs = value ? value.split(",") : ["x86_64", "arm64-v8a"]
|
|
36
|
-
return archs.findAll { it != "armeabi-v7a" && it != "x86" } // Not building for 32-bit architectures
|
|
37
|
-
}
|
|
38
|
-
|
|
39
33
|
android {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (ndkVersionMajor < 24) {
|
|
43
|
-
ndkVersion = project.properties["Cactus_ndkversion"]
|
|
44
|
-
}
|
|
34
|
+
namespace "com.margelo.nitro.cactus"
|
|
35
|
+
|
|
45
36
|
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
46
37
|
|
|
47
38
|
defaultConfig {
|
|
48
39
|
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
49
40
|
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
50
|
-
|
|
41
|
+
|
|
51
42
|
externalNativeBuild {
|
|
52
43
|
cmake {
|
|
44
|
+
cppFlags "-frtti -fexceptions -Wall -fstack-protector-all"
|
|
45
|
+
arguments "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
|
|
53
46
|
abiFilters (*reactNativeArchitectures())
|
|
47
|
+
|
|
48
|
+
buildTypes {
|
|
49
|
+
debug {
|
|
50
|
+
cppFlags "-O1 -g"
|
|
51
|
+
}
|
|
52
|
+
release {
|
|
53
|
+
cppFlags "-O2"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
}
|
|
57
|
-
|
|
59
|
+
|
|
60
|
+
externalNativeBuild {
|
|
61
|
+
cmake {
|
|
62
|
+
path "CMakeLists.txt"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
packagingOptions {
|
|
67
|
+
excludes = [
|
|
68
|
+
"META-INF",
|
|
69
|
+
"META-INF/**",
|
|
70
|
+
"**/libc++_shared.so",
|
|
71
|
+
"**/libfbjni.so",
|
|
72
|
+
"**/libjsi.so",
|
|
73
|
+
"**/libfolly_json.so",
|
|
74
|
+
"**/libfolly_runtime.so",
|
|
75
|
+
"**/libglog.so",
|
|
76
|
+
"**/libhermes.so",
|
|
77
|
+
"**/libhermes-executor-debug.so",
|
|
78
|
+
"**/libhermes_executor.so",
|
|
79
|
+
"**/libreactnative.so",
|
|
80
|
+
"**/libreactnativejni.so",
|
|
81
|
+
"**/libturbomodulejsijni.so",
|
|
82
|
+
"**/libreact_nativemodule_core.so",
|
|
83
|
+
"**/libjscexecutor.so"
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
buildFeatures {
|
|
88
|
+
buildConfig true
|
|
89
|
+
prefab true
|
|
90
|
+
}
|
|
91
|
+
|
|
58
92
|
buildTypes {
|
|
59
93
|
release {
|
|
60
94
|
minifyEnabled false
|
|
@@ -72,12 +106,10 @@ android {
|
|
|
72
106
|
|
|
73
107
|
sourceSets {
|
|
74
108
|
main {
|
|
75
|
-
|
|
76
|
-
java
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
jniLibs.srcDirs = ['src/main/jniLibs']
|
|
109
|
+
java.srcDirs += [
|
|
110
|
+
"generated/java",
|
|
111
|
+
"generated/jni"
|
|
112
|
+
]
|
|
81
113
|
}
|
|
82
114
|
}
|
|
83
115
|
}
|
|
@@ -87,18 +119,10 @@ repositories {
|
|
|
87
119
|
google()
|
|
88
120
|
}
|
|
89
121
|
|
|
122
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
90
123
|
|
|
91
124
|
dependencies {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
implementation "com.facebook.react:react-native:+"
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (isNewArchitectureEnabled()) {
|
|
99
|
-
react {
|
|
100
|
-
jsRootDir = file("../src/")
|
|
101
|
-
libraryName = "Cactus"
|
|
102
|
-
codegenJavaPackageName = "com.cactus"
|
|
103
|
-
}
|
|
125
|
+
implementation "com.facebook.react:react-android"
|
|
126
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
127
|
+
implementation project(":react-native-nitro-modules")
|
|
104
128
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
Cactus_kotlinVersion=
|
|
2
|
-
Cactus_minSdkVersion=
|
|
3
|
-
Cactus_targetSdkVersion=
|
|
4
|
-
Cactus_compileSdkVersion=
|
|
5
|
-
|
|
1
|
+
Cactus_kotlinVersion=2.0.21
|
|
2
|
+
Cactus_minSdkVersion=24
|
|
3
|
+
Cactus_targetSdkVersion=34
|
|
4
|
+
Cactus_compileSdkVersion=35
|
|
5
|
+
Cactus_ndkVersion=27.1.12297006
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
package com.margelo.nitro.cactus
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.BaseReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
7
|
+
|
|
8
|
+
class CactusPackage : BaseReactPackage() {
|
|
9
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
10
|
+
return null
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
14
|
+
return ReactModuleInfoProvider { HashMap() }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
companion object {
|
|
18
|
+
init {
|
|
19
|
+
System.loadLibrary("cactus")
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
package com.margelo.nitro.cactus
|
|
2
|
+
|
|
3
|
+
import com.margelo.nitro.core.Promise
|
|
4
|
+
import java.nio.ByteBuffer
|
|
5
|
+
import java.security.MessageDigest
|
|
6
|
+
import java.util.Locale
|
|
7
|
+
import java.util.UUID
|
|
8
|
+
|
|
9
|
+
class HybridCactusCrypto : HybridCactusCryptoSpec() {
|
|
10
|
+
override fun uuidv5(namespaceUuid: String, name: String): Promise<String> {
|
|
11
|
+
return Promise.async {
|
|
12
|
+
val nsUuid = try {
|
|
13
|
+
UUID.fromString(namespaceUuid)
|
|
14
|
+
} catch (e: IllegalArgumentException) {
|
|
15
|
+
throw IllegalArgumentException("Invalid namespace UUID")
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
val nsBytes = ByteBuffer.allocate(16).apply {
|
|
19
|
+
putLong(nsUuid.mostSignificantBits)
|
|
20
|
+
putLong(nsUuid.leastSignificantBits)
|
|
21
|
+
}.array()
|
|
22
|
+
val nameBytes = name.toByteArray(Charsets.UTF_8)
|
|
23
|
+
|
|
24
|
+
val sha1 = MessageDigest.getInstance("SHA-1")
|
|
25
|
+
.apply { update(nsBytes) }
|
|
26
|
+
.digest(nameBytes)
|
|
27
|
+
val uuidBytes = sha1.copyOfRange(0, 16)
|
|
28
|
+
uuidBytes[6] = (uuidBytes[6].toInt() and 0x0F or 0x50).toByte()
|
|
29
|
+
uuidBytes[8] = (uuidBytes[8].toInt() and 0x3F or 0x80).toByte()
|
|
30
|
+
|
|
31
|
+
val bb = ByteBuffer.wrap(uuidBytes)
|
|
32
|
+
|
|
33
|
+
val uuid = UUID(bb.long, bb.long)
|
|
34
|
+
|
|
35
|
+
uuid.toString().lowercase(Locale.ROOT)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
package com.margelo.nitro.cactus
|
|
2
|
+
|
|
3
|
+
import android.os.Build
|
|
4
|
+
import android.provider.Settings
|
|
5
|
+
import com.margelo.nitro.NitroModules
|
|
6
|
+
import com.margelo.nitro.core.Promise
|
|
7
|
+
|
|
8
|
+
class HybridCactusDeviceInfo : HybridCactusDeviceInfoSpec() {
|
|
9
|
+
private val context = NitroModules.applicationContext ?: error("Android context not found")
|
|
10
|
+
|
|
11
|
+
override fun getAppIdentifier(): Promise<String?> {
|
|
12
|
+
return Promise.async { context.packageName }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
override fun getDeviceInfo(): Promise<DeviceInfo> {
|
|
16
|
+
return Promise.async {
|
|
17
|
+
DeviceInfo(
|
|
18
|
+
brand = Build.MANUFACTURER, model = Build.MODEL, device_id = Settings.Secure.getString(
|
|
19
|
+
context.contentResolver, Settings.Secure.ANDROID_ID
|
|
20
|
+
), os = "Android", os_version = Build.VERSION.RELEASE
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
package com.margelo.nitro.cactus
|
|
2
|
+
|
|
3
|
+
import com.margelo.nitro.NitroModules
|
|
4
|
+
import com.margelo.nitro.core.Promise
|
|
5
|
+
import java.io.BufferedInputStream
|
|
6
|
+
import java.io.BufferedOutputStream
|
|
7
|
+
import java.io.File
|
|
8
|
+
import java.io.FileInputStream
|
|
9
|
+
import java.io.FileOutputStream
|
|
10
|
+
import java.net.HttpURLConnection
|
|
11
|
+
import java.net.URL
|
|
12
|
+
import java.util.zip.ZipEntry
|
|
13
|
+
import java.util.zip.ZipInputStream
|
|
14
|
+
import kotlin.math.floor
|
|
15
|
+
|
|
16
|
+
class HybridCactusFileSystem : HybridCactusFileSystemSpec() {
|
|
17
|
+
private val context = NitroModules.applicationContext ?: error("Android context not found")
|
|
18
|
+
|
|
19
|
+
override fun getCactusDirectory(): Promise<String> {
|
|
20
|
+
return Promise.async { cactusFile().absolutePath }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
override fun fileExists(path: String): Promise<Boolean> {
|
|
24
|
+
return Promise.async {
|
|
25
|
+
val cactusDir = cactusFile()
|
|
26
|
+
val file = File(cactusDir, path)
|
|
27
|
+
file.exists()
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
override fun writeFile(path: String, content: String): Promise<Unit> {
|
|
32
|
+
return Promise.async {
|
|
33
|
+
val cactusDir = cactusFile()
|
|
34
|
+
val file = File(cactusDir, path)
|
|
35
|
+
file.parentFile?.mkdirs()
|
|
36
|
+
file.writeText(content)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
override fun readFile(path: String): Promise<String> {
|
|
41
|
+
return Promise.async {
|
|
42
|
+
val cactusDir = cactusFile()
|
|
43
|
+
val file = File(cactusDir, path)
|
|
44
|
+
|
|
45
|
+
if (!file.exists()) {
|
|
46
|
+
throw Error("No such file: $path")
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
file.readText()
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
override fun deleteFile(path: String): Promise<Unit> {
|
|
54
|
+
return Promise.async {
|
|
55
|
+
val cactusDir = cactusFile()
|
|
56
|
+
val file = File(cactusDir, path)
|
|
57
|
+
|
|
58
|
+
if (!file.exists()) {
|
|
59
|
+
throw Error("No such file: $path")
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
file.deleteRecursively()
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
override fun modelExists(model: String): Promise<Boolean> {
|
|
67
|
+
return Promise.async { modelFile(model).exists() }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
override fun getModelPath(model: String): Promise<String> {
|
|
71
|
+
return Promise.async { modelFile(model).absolutePath }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
override fun downloadModel(
|
|
75
|
+
model: String, from: String, callback: ((progress: Double) -> Unit)?
|
|
76
|
+
): Promise<Unit> {
|
|
77
|
+
return Promise.async {
|
|
78
|
+
val modelFile = modelFile(model)
|
|
79
|
+
|
|
80
|
+
if (modelFile.exists()) {
|
|
81
|
+
callback?.invoke(1.0)
|
|
82
|
+
return@async
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
val url = try {
|
|
86
|
+
URL(from)
|
|
87
|
+
} catch (_: Throwable) {
|
|
88
|
+
throw Error("Invalid URL")
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
val tmpZip = File.createTempFile("dl_", ".zip", context.cacheDir)
|
|
92
|
+
var connection: HttpURLConnection? = null
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
connection = (url.openConnection() as HttpURLConnection).apply {
|
|
96
|
+
connectTimeout = 30_000
|
|
97
|
+
readTimeout = 5 * 60_000
|
|
98
|
+
instanceFollowRedirects = true
|
|
99
|
+
}
|
|
100
|
+
connection.connect()
|
|
101
|
+
val code = connection.responseCode
|
|
102
|
+
|
|
103
|
+
if (code !in 200..299) {
|
|
104
|
+
connection.disconnect()
|
|
105
|
+
throw Error("Download failed with HTTP status code: $code")
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
val contentLength = connection.getHeaderFieldLong("Content-Length", -1L)
|
|
109
|
+
var downloaded = 0L
|
|
110
|
+
var lastPct = -1.0
|
|
111
|
+
|
|
112
|
+
callback?.invoke(0.0)
|
|
113
|
+
|
|
114
|
+
connection.inputStream.use { input ->
|
|
115
|
+
BufferedInputStream(input).use { bis ->
|
|
116
|
+
FileOutputStream(tmpZip).use { fos ->
|
|
117
|
+
BufferedOutputStream(fos).use { bos ->
|
|
118
|
+
val buf = ByteArray(256 * 1024)
|
|
119
|
+
|
|
120
|
+
while (true) {
|
|
121
|
+
val read = bis.read(buf)
|
|
122
|
+
|
|
123
|
+
if (read == -1) {
|
|
124
|
+
break
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
bos.write(buf, 0, read)
|
|
128
|
+
downloaded += read
|
|
129
|
+
|
|
130
|
+
if (contentLength > 0) {
|
|
131
|
+
// cap at 0.99; 1.0 will be sent after unzip
|
|
132
|
+
val pct = floor(
|
|
133
|
+
(downloaded.toDouble() / contentLength.toDouble()).coerceIn(
|
|
134
|
+
0.0, 1.0
|
|
135
|
+
) * 99
|
|
136
|
+
) / 100.0
|
|
137
|
+
|
|
138
|
+
if (pct - lastPct >= 0.01) {
|
|
139
|
+
callback?.invoke(pct)
|
|
140
|
+
lastPct = pct
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
modelFile.mkdirs()
|
|
150
|
+
unzipItem(tmpZip, modelFile)
|
|
151
|
+
|
|
152
|
+
callback?.invoke(1.0)
|
|
153
|
+
} catch (t: Throwable) {
|
|
154
|
+
modelFile.deleteRecursively()
|
|
155
|
+
throw Error("Failed to download and unzip model: ${t.message}")
|
|
156
|
+
} finally {
|
|
157
|
+
tmpZip.delete()
|
|
158
|
+
connection?.disconnect()
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private fun unzipItem(zipFile: File, outDir: File) {
|
|
164
|
+
val outRoot = outDir.canonicalFile
|
|
165
|
+
ZipInputStream(BufferedInputStream(FileInputStream(zipFile))).use { zis ->
|
|
166
|
+
var entry: ZipEntry? = zis.nextEntry
|
|
167
|
+
val buffer = ByteArray(256 * 1024)
|
|
168
|
+
|
|
169
|
+
while (entry != null) {
|
|
170
|
+
val outPath = File(outDir, entry.name)
|
|
171
|
+
|
|
172
|
+
// ZIP Slip protection
|
|
173
|
+
val canonical = outPath.canonicalFile
|
|
174
|
+
if (!canonical.path.startsWith(outRoot.path + File.separator)) {
|
|
175
|
+
throw SecurityException("Blocked zip entry outside target dir: ${entry.name}")
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (entry.isDirectory) {
|
|
179
|
+
canonical.mkdirs()
|
|
180
|
+
} else {
|
|
181
|
+
canonical.parentFile?.mkdirs()
|
|
182
|
+
FileOutputStream(canonical).use { fos ->
|
|
183
|
+
BufferedOutputStream(fos).use { bos ->
|
|
184
|
+
while (true) {
|
|
185
|
+
val read = zis.read(buffer)
|
|
186
|
+
if (read == -1) break
|
|
187
|
+
bos.write(buffer, 0, read)
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
zis.closeEntry()
|
|
194
|
+
entry = zis.nextEntry
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
override fun deleteModel(model: String): Promise<Unit> {
|
|
200
|
+
return Promise.async {
|
|
201
|
+
val modelFile = modelFile(model)
|
|
202
|
+
|
|
203
|
+
if (!modelFile.exists()) {
|
|
204
|
+
throw Error("No such model: $model")
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
modelFile.deleteRecursively()
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private fun cactusFile(): File {
|
|
212
|
+
val documentsDir =
|
|
213
|
+
context.getExternalFilesDir(android.os.Environment.DIRECTORY_DOCUMENTS) ?: context.filesDir
|
|
214
|
+
val cactusDir = File(documentsDir, "cactus")
|
|
215
|
+
|
|
216
|
+
if (!cactusDir.exists()) {
|
|
217
|
+
cactusDir.mkdirs()
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return cactusDir
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
private fun modelFile(model: String): File {
|
|
224
|
+
val cactusDir = cactusFile()
|
|
225
|
+
return File(cactusDir, "models/$model")
|
|
226
|
+
}
|
|
227
|
+
}
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
#include "HybridCactus.hpp"
|
|
2
|
+
|
|
3
|
+
namespace margelo::nitro::cactus
|
|
4
|
+
{
|
|
5
|
+
HybridCactus::HybridCactus() : HybridObject(TAG) {}
|
|
6
|
+
|
|
7
|
+
std::shared_ptr<Promise<void>> HybridCactus::init(const std::string &modelPath, double contextSize) {
|
|
8
|
+
return Promise<void>::async([this, modelPath, contextSize]() -> void {
|
|
9
|
+
std::lock_guard<std::mutex> lock(this->_modelMutex);
|
|
10
|
+
|
|
11
|
+
if (this->_model) {
|
|
12
|
+
throw std::runtime_error("Cactus model is already initialized");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const cactus_model_t model = cactus_init(modelPath.c_str(), contextSize);
|
|
16
|
+
|
|
17
|
+
if (!model) {
|
|
18
|
+
throw std::runtime_error("Failed to initialize Cactus model");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
this->_model = model;
|
|
22
|
+
this->_contextSize = contextSize;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
std::shared_ptr<Promise<std::string>> HybridCactus::complete(const std::string &messagesJson, double responseBufferSize, const std::optional<std::string> &optionsJson, const std::optional<std::string> &toolsJson, const std::optional<std::function<void(const std::string & /* token */, double /* tokenId */)>> &callback) {
|
|
27
|
+
return Promise<std::string>::async([this, messagesJson, optionsJson, toolsJson, callback, responseBufferSize]() -> std::string {
|
|
28
|
+
std::lock_guard<std::mutex> lock(this->_modelMutex);
|
|
29
|
+
|
|
30
|
+
if (!this->_model) {
|
|
31
|
+
throw std::runtime_error("Cactus model is not initialized");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
struct CallbackCtx {
|
|
35
|
+
const std::function<void(const std::string & /* token */, double /* tokenId */)> *callback;
|
|
36
|
+
} callbackCtx{ callback.has_value() ? &callback.value() : nullptr };
|
|
37
|
+
|
|
38
|
+
auto cactusTokenCallback = [](const char* token, uint32_t tokenId, void* userData) {
|
|
39
|
+
auto* callbackCtx = static_cast<CallbackCtx*>(userData);
|
|
40
|
+
if (!callbackCtx || !callbackCtx->callback || !(*callbackCtx->callback)) return;
|
|
41
|
+
(*callbackCtx->callback)(token, tokenId);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
std::string responseBuffer;
|
|
45
|
+
responseBuffer.resize(responseBufferSize);
|
|
46
|
+
|
|
47
|
+
int result = cactus_complete(
|
|
48
|
+
this->_model,
|
|
49
|
+
messagesJson.c_str(),
|
|
50
|
+
responseBuffer.data(),
|
|
51
|
+
responseBufferSize,
|
|
52
|
+
optionsJson ? optionsJson->c_str() : nullptr,
|
|
53
|
+
toolsJson ? toolsJson->c_str() : nullptr,
|
|
54
|
+
cactusTokenCallback,
|
|
55
|
+
&callbackCtx
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
if (result < 0) {
|
|
59
|
+
throw std::runtime_error("Cactus completion failed");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Remove null terminator
|
|
63
|
+
responseBuffer.resize(strlen(responseBuffer.c_str()));
|
|
64
|
+
|
|
65
|
+
return responseBuffer;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
std::shared_ptr<Promise<std::vector<double>>> HybridCactus::embed(const std::string &text, double embeddingBufferSize) {
|
|
70
|
+
return Promise<std::vector<double>>::async([this, text, embeddingBufferSize]() -> std::vector<double> {
|
|
71
|
+
std::lock_guard<std::mutex> lock(this->_modelMutex);
|
|
72
|
+
|
|
73
|
+
if (!this->_model) {
|
|
74
|
+
throw std::runtime_error("Cactus model is not initialized");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
std::vector<float> embeddingBuffer(embeddingBufferSize);
|
|
78
|
+
size_t embeddingDim;
|
|
79
|
+
|
|
80
|
+
int result = cactus_embed(this->_model, text.c_str(), embeddingBuffer.data(), embeddingBufferSize * sizeof(float), &embeddingDim);
|
|
81
|
+
|
|
82
|
+
if (result < 0) {
|
|
83
|
+
throw std::runtime_error("Cactus embedding failed");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
embeddingBuffer.resize(embeddingDim);
|
|
87
|
+
|
|
88
|
+
return std::vector<double>(embeddingBuffer.begin(), embeddingBuffer.end());
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
std::shared_ptr<Promise<void>> HybridCactus::reset() {
|
|
93
|
+
return Promise<void>::async([this]() -> void {
|
|
94
|
+
std::lock_guard<std::mutex> lock(this->_modelMutex);
|
|
95
|
+
|
|
96
|
+
if (!this->_model) {
|
|
97
|
+
throw std::runtime_error("Cactus model is not initialized");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
cactus_reset(this->_model);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
std::shared_ptr<Promise<void>> HybridCactus::stop() {
|
|
105
|
+
return Promise<void>::async([this]() -> void {
|
|
106
|
+
cactus_stop(this->_model);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
std::shared_ptr<Promise<void>> HybridCactus::destroy() {
|
|
111
|
+
return Promise<void>::async([this]() -> void {
|
|
112
|
+
std::lock_guard<std::mutex> lock(this->_modelMutex);
|
|
113
|
+
|
|
114
|
+
if (!this->_model) {
|
|
115
|
+
throw std::runtime_error("Cactus model is not initialized");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
cactus_destroy(this->_model);
|
|
119
|
+
this->_model = nullptr;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
} // namespace margelo::nitro::cactus
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include "HybridCactusSpec.hpp"
|
|
3
|
+
|
|
4
|
+
#include "cactus_ffi.h"
|
|
5
|
+
|
|
6
|
+
#include <mutex>
|
|
7
|
+
|
|
8
|
+
namespace margelo::nitro::cactus
|
|
9
|
+
{
|
|
10
|
+
|
|
11
|
+
class HybridCactus : public HybridCactusSpec
|
|
12
|
+
{
|
|
13
|
+
public:
|
|
14
|
+
HybridCactus();
|
|
15
|
+
|
|
16
|
+
std::shared_ptr<Promise<void>> init(const std::string &modelPath, double contextSize) override;
|
|
17
|
+
|
|
18
|
+
std::shared_ptr<Promise<std::string>> complete(const std::string &messagesJson, double responseBufferSize, const std::optional<std::string> &optionsJson, const std::optional<std::string> &toolsJson, const std::optional<std::function<void(const std::string & /* token */, double /* tokenId */)>> &callback) override;
|
|
19
|
+
|
|
20
|
+
std::shared_ptr<Promise<std::vector<double>>> embed(const std::string &text, double embeddingBufferSize) override;
|
|
21
|
+
|
|
22
|
+
std::shared_ptr<Promise<void>> reset() override;
|
|
23
|
+
|
|
24
|
+
std::shared_ptr<Promise<void>> stop() override;
|
|
25
|
+
|
|
26
|
+
std::shared_ptr<Promise<void>> destroy() override;
|
|
27
|
+
|
|
28
|
+
private:
|
|
29
|
+
cactus_model_t _model = nullptr;
|
|
30
|
+
size_t _contextSize;
|
|
31
|
+
|
|
32
|
+
std::mutex _modelMutex;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
} // namespace margelo::nitro::cactus
|