cactus-react-native 0.2.11 → 1.0.2
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 +550 -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.so → libcactus.a} +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_util.so +0 -0
- package/cpp/HybridCactus.cpp +135 -0
- package/cpp/HybridCactus.hpp +42 -0
- package/cpp/HybridCactusUtil.cpp +47 -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 +545 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ffi_utils.h +400 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/graph.h +338 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel.h +275 -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 +545 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/ffi_utils.h +400 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/graph.h +338 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel.h +275 -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 +151 -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 +238 -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 +26 -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 +67 -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 +205 -0
- package/src/config/CactusConfig.ts +4 -0
- package/src/constants/packageVersion.ts +1 -0
- package/src/hooks/useCactusLM.ts +285 -0
- package/src/index.tsx +23 -0
- package/src/native/Cactus.ts +83 -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 +20 -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 +73 -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_2.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2_dotprod.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2_dotprod_i8mm.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2_i8mm.so +0 -0
- package/android/src/newarch/java/com/cactus/CactusModule.java +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
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { Cactus, CactusFileSystem } from '../native';
|
|
2
|
+
import type {
|
|
3
|
+
CactusLMDownloadParams,
|
|
4
|
+
CactusLMCompleteParams,
|
|
5
|
+
CactusLMCompleteResult,
|
|
6
|
+
CactusLMEmbedParams,
|
|
7
|
+
CactusLMEmbedResult,
|
|
8
|
+
CactusLMGetModelsParams,
|
|
9
|
+
CactusLMParams,
|
|
10
|
+
} from '../types/CactusLM';
|
|
11
|
+
import type { CactusModel } from '../types/CactusModel';
|
|
12
|
+
import { Telemetry } from '../telemetry/Telemetry';
|
|
13
|
+
import { CactusConfig } from '../config/CactusConfig';
|
|
14
|
+
import { Database } from '../api/Database';
|
|
15
|
+
import { getErrorMessage } from '../utils/error';
|
|
16
|
+
|
|
17
|
+
export class CactusLM {
|
|
18
|
+
private readonly cactus = new Cactus();
|
|
19
|
+
|
|
20
|
+
private readonly model: string;
|
|
21
|
+
private readonly contextSize: number;
|
|
22
|
+
private readonly corpusDir?: string;
|
|
23
|
+
|
|
24
|
+
private isDownloading = false;
|
|
25
|
+
private isInitialized = false;
|
|
26
|
+
private isGenerating = false;
|
|
27
|
+
|
|
28
|
+
private static readonly defaultModel = 'qwen3-0.6';
|
|
29
|
+
private static readonly defaultContextSize = 2048;
|
|
30
|
+
private static readonly defaultCompleteOptions = {
|
|
31
|
+
maxTokens: 512,
|
|
32
|
+
};
|
|
33
|
+
private static readonly defaultEmbedBufferSize = 2048;
|
|
34
|
+
|
|
35
|
+
private static readonly modelsInfoPath = 'models/info.json';
|
|
36
|
+
|
|
37
|
+
constructor({ model, contextSize, corpusDir }: CactusLMParams = {}) {
|
|
38
|
+
this.model = model ?? CactusLM.defaultModel;
|
|
39
|
+
this.contextSize = contextSize ?? CactusLM.defaultContextSize;
|
|
40
|
+
this.corpusDir = corpusDir;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public async download({
|
|
44
|
+
onProgress,
|
|
45
|
+
}: CactusLMDownloadParams = {}): Promise<void> {
|
|
46
|
+
if (this.isDownloading) {
|
|
47
|
+
throw new Error('CactusLM is already downloading');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (await CactusFileSystem.modelExists(this.model)) {
|
|
51
|
+
onProgress?.(1.0);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
this.isDownloading = true;
|
|
56
|
+
try {
|
|
57
|
+
await CactusFileSystem.downloadModel(this.model, onProgress);
|
|
58
|
+
await this.getModels({ forceRefresh: true });
|
|
59
|
+
} finally {
|
|
60
|
+
this.isDownloading = false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public async init(): Promise<void> {
|
|
65
|
+
if (this.isInitialized) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!Telemetry.isInitialized()) {
|
|
70
|
+
await Telemetry.init(CactusConfig.telemetryToken);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!(await CactusFileSystem.modelExists(this.model))) {
|
|
74
|
+
throw new Error(`Model "${this.model}" is not downloaded`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const modelPath = await CactusFileSystem.getModelPath(this.model);
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
await this.cactus.init(modelPath, this.contextSize, this.corpusDir);
|
|
81
|
+
Telemetry.logInit(this.model, true);
|
|
82
|
+
this.isInitialized = true;
|
|
83
|
+
} catch (error) {
|
|
84
|
+
Telemetry.logInit(this.model, false, getErrorMessage(error));
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public async complete({
|
|
90
|
+
messages,
|
|
91
|
+
options,
|
|
92
|
+
tools,
|
|
93
|
+
onToken,
|
|
94
|
+
}: CactusLMCompleteParams): Promise<CactusLMCompleteResult> {
|
|
95
|
+
if (this.isGenerating) {
|
|
96
|
+
throw new Error('CactusLM is already generating');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
await this.init();
|
|
100
|
+
|
|
101
|
+
options = { ...CactusLM.defaultCompleteOptions, ...options };
|
|
102
|
+
const responseBufferSize =
|
|
103
|
+
8 * (options.maxTokens ?? CactusLM.defaultCompleteOptions.maxTokens) +
|
|
104
|
+
256;
|
|
105
|
+
|
|
106
|
+
this.isGenerating = true;
|
|
107
|
+
try {
|
|
108
|
+
const result = await this.cactus.complete(
|
|
109
|
+
messages,
|
|
110
|
+
responseBufferSize,
|
|
111
|
+
options,
|
|
112
|
+
tools,
|
|
113
|
+
onToken
|
|
114
|
+
);
|
|
115
|
+
Telemetry.logCompletion(
|
|
116
|
+
this.model,
|
|
117
|
+
result.success,
|
|
118
|
+
result.success ? undefined : result.response,
|
|
119
|
+
result
|
|
120
|
+
);
|
|
121
|
+
return result;
|
|
122
|
+
} catch (error) {
|
|
123
|
+
Telemetry.logCompletion(this.model, false, getErrorMessage(error));
|
|
124
|
+
throw error;
|
|
125
|
+
} finally {
|
|
126
|
+
this.isGenerating = false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
public async embed({
|
|
131
|
+
text,
|
|
132
|
+
}: CactusLMEmbedParams): Promise<CactusLMEmbedResult> {
|
|
133
|
+
if (this.isGenerating) {
|
|
134
|
+
throw new Error('CactusLM is already generating');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
await this.init();
|
|
138
|
+
|
|
139
|
+
this.isGenerating = true;
|
|
140
|
+
try {
|
|
141
|
+
const embedding = await this.cactus.embed(
|
|
142
|
+
text,
|
|
143
|
+
CactusLM.defaultEmbedBufferSize
|
|
144
|
+
);
|
|
145
|
+
Telemetry.logEmbedding(this.model, true);
|
|
146
|
+
return { embedding };
|
|
147
|
+
} catch (error) {
|
|
148
|
+
Telemetry.logEmbedding(this.model, false, getErrorMessage(error));
|
|
149
|
+
throw error;
|
|
150
|
+
} finally {
|
|
151
|
+
this.isGenerating = false;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
public stop(): Promise<void> {
|
|
156
|
+
return this.cactus.stop();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
public async reset(): Promise<void> {
|
|
160
|
+
await this.stop();
|
|
161
|
+
return this.cactus.reset();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
public async destroy(): Promise<void> {
|
|
165
|
+
if (!this.isInitialized) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
await this.stop();
|
|
170
|
+
await this.cactus.destroy();
|
|
171
|
+
|
|
172
|
+
this.isInitialized = false;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
public async getModels({
|
|
176
|
+
forceRefresh = false,
|
|
177
|
+
}: CactusLMGetModelsParams = {}): Promise<CactusModel[]> {
|
|
178
|
+
if (
|
|
179
|
+
!forceRefresh &&
|
|
180
|
+
(await CactusFileSystem.fileExists(CactusLM.modelsInfoPath))
|
|
181
|
+
) {
|
|
182
|
+
try {
|
|
183
|
+
return JSON.parse(
|
|
184
|
+
await CactusFileSystem.readFile(CactusLM.modelsInfoPath)
|
|
185
|
+
);
|
|
186
|
+
} catch {
|
|
187
|
+
// Delete corrupted models info
|
|
188
|
+
await CactusFileSystem.deleteFile(CactusLM.modelsInfoPath);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const models = await Database.getModels();
|
|
193
|
+
|
|
194
|
+
for (const model of models) {
|
|
195
|
+
model.isDownloaded = await CactusFileSystem.modelExists(model.slug);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
await CactusFileSystem.writeFile(
|
|
199
|
+
CactusLM.modelsInfoPath,
|
|
200
|
+
JSON.stringify(models)
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
return models;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const packageVersion = '1.0.2';
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState, useRef } from 'react';
|
|
2
|
+
import { CactusLM } from '../classes/CactusLM';
|
|
3
|
+
import { CactusFileSystem } from '../native';
|
|
4
|
+
import { getErrorMessage } from '../utils/error';
|
|
5
|
+
import type {
|
|
6
|
+
CactusLMParams,
|
|
7
|
+
CactusLMCompleteResult,
|
|
8
|
+
CactusLMEmbedParams,
|
|
9
|
+
CactusLMEmbedResult,
|
|
10
|
+
CactusLMGetModelsParams,
|
|
11
|
+
CactusLMCompleteParams,
|
|
12
|
+
CactusLMDownloadParams,
|
|
13
|
+
} from '../types/CactusLM';
|
|
14
|
+
import type { CactusModel } from '../types/CactusModel';
|
|
15
|
+
|
|
16
|
+
export const useCactusLM = ({
|
|
17
|
+
model = 'qwen3-0.6',
|
|
18
|
+
contextSize = 2048,
|
|
19
|
+
corpusDir = undefined,
|
|
20
|
+
}: CactusLMParams = {}) => {
|
|
21
|
+
const [cactusLM, setCactusLM] = useState(
|
|
22
|
+
() => new CactusLM({ model, contextSize, corpusDir })
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
// State
|
|
26
|
+
const [completion, setCompletion] = useState('');
|
|
27
|
+
const [isGenerating, setIsGenerating] = useState(false);
|
|
28
|
+
const [isInitializing, setIsInitializing] = useState(false);
|
|
29
|
+
const [isDownloaded, setIsDownloaded] = useState(false);
|
|
30
|
+
const [isDownloading, setIsDownloading] = useState(false);
|
|
31
|
+
const [downloadProgress, setDownloadProgress] = useState(0);
|
|
32
|
+
const [error, setError] = useState<string | null>(null);
|
|
33
|
+
|
|
34
|
+
const currentModelRef = useRef(model);
|
|
35
|
+
const currentDownloadIdRef = useRef(0);
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
currentModelRef.current = model;
|
|
39
|
+
}, [model]);
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
setCactusLM(new CactusLM({ model, contextSize, corpusDir }));
|
|
43
|
+
|
|
44
|
+
setCompletion('');
|
|
45
|
+
setIsGenerating(false);
|
|
46
|
+
setIsInitializing(false);
|
|
47
|
+
setIsDownloaded(false);
|
|
48
|
+
setIsDownloading(false);
|
|
49
|
+
setDownloadProgress(0);
|
|
50
|
+
setError(null);
|
|
51
|
+
|
|
52
|
+
let mounted = true;
|
|
53
|
+
CactusFileSystem.modelExists(model)
|
|
54
|
+
.then((exists) => {
|
|
55
|
+
if (!mounted) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
setIsDownloaded(exists);
|
|
59
|
+
})
|
|
60
|
+
.catch((e) => {
|
|
61
|
+
if (!mounted) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
setIsDownloaded(false);
|
|
65
|
+
setError(getErrorMessage(e));
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return () => {
|
|
69
|
+
mounted = false;
|
|
70
|
+
};
|
|
71
|
+
}, [model, contextSize, corpusDir]);
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
return () => {
|
|
75
|
+
cactusLM.destroy().catch(() => {});
|
|
76
|
+
};
|
|
77
|
+
}, [cactusLM]);
|
|
78
|
+
|
|
79
|
+
const download = useCallback(
|
|
80
|
+
async ({ onProgress }: CactusLMDownloadParams = {}) => {
|
|
81
|
+
if (isDownloading) {
|
|
82
|
+
const message = 'CactusLM is already downloading';
|
|
83
|
+
setError(message);
|
|
84
|
+
throw new Error(message);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const thisModel = currentModelRef.current;
|
|
88
|
+
const thisDownloadId = ++currentDownloadIdRef.current;
|
|
89
|
+
|
|
90
|
+
setError(null);
|
|
91
|
+
setDownloadProgress(0);
|
|
92
|
+
setIsDownloading(true);
|
|
93
|
+
try {
|
|
94
|
+
await cactusLM.download({
|
|
95
|
+
onProgress: (progress) => {
|
|
96
|
+
if (
|
|
97
|
+
currentModelRef.current !== thisModel ||
|
|
98
|
+
currentDownloadIdRef.current !== thisDownloadId
|
|
99
|
+
) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
setDownloadProgress(progress);
|
|
104
|
+
onProgress?.(progress);
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
if (
|
|
109
|
+
currentModelRef.current !== thisModel ||
|
|
110
|
+
currentDownloadIdRef.current !== thisDownloadId
|
|
111
|
+
) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
setIsDownloaded(true);
|
|
116
|
+
} catch (e) {
|
|
117
|
+
if (
|
|
118
|
+
currentModelRef.current !== thisModel ||
|
|
119
|
+
currentDownloadIdRef.current !== thisDownloadId
|
|
120
|
+
) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
setError(getErrorMessage(e));
|
|
125
|
+
throw e;
|
|
126
|
+
} finally {
|
|
127
|
+
if (
|
|
128
|
+
currentModelRef.current !== thisModel ||
|
|
129
|
+
currentDownloadIdRef.current !== thisDownloadId
|
|
130
|
+
) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
setIsDownloading(false);
|
|
135
|
+
setDownloadProgress(0);
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
[cactusLM, isDownloading]
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const init = useCallback(async () => {
|
|
142
|
+
if (isInitializing) {
|
|
143
|
+
const message = 'CactusLM is already initializing';
|
|
144
|
+
setError(message);
|
|
145
|
+
throw new Error(message);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
setError(null);
|
|
149
|
+
setIsInitializing(true);
|
|
150
|
+
try {
|
|
151
|
+
await cactusLM.init();
|
|
152
|
+
} catch (e) {
|
|
153
|
+
setError(getErrorMessage(e));
|
|
154
|
+
throw e;
|
|
155
|
+
} finally {
|
|
156
|
+
setIsInitializing(false);
|
|
157
|
+
}
|
|
158
|
+
}, [cactusLM, isInitializing]);
|
|
159
|
+
|
|
160
|
+
const complete = useCallback(
|
|
161
|
+
async ({
|
|
162
|
+
messages,
|
|
163
|
+
options,
|
|
164
|
+
tools,
|
|
165
|
+
onToken,
|
|
166
|
+
}: CactusLMCompleteParams): Promise<CactusLMCompleteResult> => {
|
|
167
|
+
if (isGenerating) {
|
|
168
|
+
const message = 'CactusLM is already generating';
|
|
169
|
+
setError(message);
|
|
170
|
+
throw new Error(message);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
setError(null);
|
|
174
|
+
setCompletion('');
|
|
175
|
+
setIsGenerating(true);
|
|
176
|
+
try {
|
|
177
|
+
return await cactusLM.complete({
|
|
178
|
+
messages,
|
|
179
|
+
options,
|
|
180
|
+
tools,
|
|
181
|
+
onToken: (token) => {
|
|
182
|
+
setCompletion((prev) => prev + token);
|
|
183
|
+
onToken?.(token);
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
} catch (e) {
|
|
187
|
+
setError(getErrorMessage(e));
|
|
188
|
+
throw e;
|
|
189
|
+
} finally {
|
|
190
|
+
setIsGenerating(false);
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
[cactusLM, isGenerating]
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
const embed = useCallback(
|
|
197
|
+
async ({ text }: CactusLMEmbedParams): Promise<CactusLMEmbedResult> => {
|
|
198
|
+
if (isGenerating) {
|
|
199
|
+
const message = 'CactusLM is already generating';
|
|
200
|
+
setError(message);
|
|
201
|
+
throw new Error(message);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
setError(null);
|
|
205
|
+
setIsGenerating(true);
|
|
206
|
+
try {
|
|
207
|
+
return await cactusLM.embed({ text });
|
|
208
|
+
} catch (e) {
|
|
209
|
+
setError(getErrorMessage(e));
|
|
210
|
+
throw e;
|
|
211
|
+
} finally {
|
|
212
|
+
setIsGenerating(false);
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
[cactusLM, isGenerating]
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
const stop = useCallback(async () => {
|
|
219
|
+
setError(null);
|
|
220
|
+
try {
|
|
221
|
+
await cactusLM.stop();
|
|
222
|
+
} catch (e) {
|
|
223
|
+
setError(getErrorMessage(e));
|
|
224
|
+
throw e;
|
|
225
|
+
}
|
|
226
|
+
}, [cactusLM]);
|
|
227
|
+
|
|
228
|
+
const reset = useCallback(async () => {
|
|
229
|
+
setError(null);
|
|
230
|
+
try {
|
|
231
|
+
await cactusLM.reset();
|
|
232
|
+
} catch (e) {
|
|
233
|
+
setError(getErrorMessage(e));
|
|
234
|
+
throw e;
|
|
235
|
+
} finally {
|
|
236
|
+
setCompletion('');
|
|
237
|
+
}
|
|
238
|
+
}, [cactusLM]);
|
|
239
|
+
|
|
240
|
+
const destroy = useCallback(async () => {
|
|
241
|
+
setError(null);
|
|
242
|
+
try {
|
|
243
|
+
await cactusLM.destroy();
|
|
244
|
+
} catch (e) {
|
|
245
|
+
setError(getErrorMessage(e));
|
|
246
|
+
throw e;
|
|
247
|
+
} finally {
|
|
248
|
+
setCompletion('');
|
|
249
|
+
}
|
|
250
|
+
}, [cactusLM]);
|
|
251
|
+
|
|
252
|
+
const getModels = useCallback(
|
|
253
|
+
async ({ forceRefresh }: CactusLMGetModelsParams = {}): Promise<
|
|
254
|
+
CactusModel[]
|
|
255
|
+
> => {
|
|
256
|
+
setError(null);
|
|
257
|
+
try {
|
|
258
|
+
return await cactusLM.getModels({ forceRefresh });
|
|
259
|
+
} catch (e) {
|
|
260
|
+
setError(getErrorMessage(e));
|
|
261
|
+
throw e;
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
[cactusLM]
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
return {
|
|
268
|
+
completion,
|
|
269
|
+
isGenerating,
|
|
270
|
+
isInitializing,
|
|
271
|
+
isDownloaded,
|
|
272
|
+
isDownloading,
|
|
273
|
+
downloadProgress,
|
|
274
|
+
error,
|
|
275
|
+
|
|
276
|
+
download,
|
|
277
|
+
init,
|
|
278
|
+
complete,
|
|
279
|
+
embed,
|
|
280
|
+
reset,
|
|
281
|
+
stop,
|
|
282
|
+
destroy,
|
|
283
|
+
getModels,
|
|
284
|
+
};
|
|
285
|
+
};
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Classes
|
|
2
|
+
export { CactusLM } from './classes/CactusLM';
|
|
3
|
+
|
|
4
|
+
// Hooks
|
|
5
|
+
export { useCactusLM } from './hooks/useCactusLM';
|
|
6
|
+
|
|
7
|
+
// Types
|
|
8
|
+
export type { CactusModel } from './types/CactusModel';
|
|
9
|
+
export type {
|
|
10
|
+
CactusLMParams,
|
|
11
|
+
CactusLMDownloadParams,
|
|
12
|
+
Message,
|
|
13
|
+
Options,
|
|
14
|
+
Tool,
|
|
15
|
+
CactusLMCompleteParams,
|
|
16
|
+
CactusLMCompleteResult,
|
|
17
|
+
CactusLMEmbedParams,
|
|
18
|
+
CactusLMEmbedResult,
|
|
19
|
+
CactusLMGetModelsParams,
|
|
20
|
+
} from './types/CactusLM';
|
|
21
|
+
|
|
22
|
+
// Config
|
|
23
|
+
export { CactusConfig } from './config/CactusConfig';
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
2
|
+
import type { Cactus as CactusSpec } from '../specs/Cactus.nitro';
|
|
3
|
+
import type {
|
|
4
|
+
CactusLMCompleteResult,
|
|
5
|
+
Message,
|
|
6
|
+
Options,
|
|
7
|
+
Tool,
|
|
8
|
+
} from '../types/CactusLM';
|
|
9
|
+
|
|
10
|
+
export class Cactus {
|
|
11
|
+
private readonly hybridCactus =
|
|
12
|
+
NitroModules.createHybridObject<CactusSpec>('Cactus');
|
|
13
|
+
|
|
14
|
+
public init(
|
|
15
|
+
modelPath: string,
|
|
16
|
+
contextSize: number,
|
|
17
|
+
corpusDir?: string
|
|
18
|
+
): Promise<void> {
|
|
19
|
+
return this.hybridCactus.init(modelPath, contextSize, corpusDir);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public async complete(
|
|
23
|
+
messages: Message[],
|
|
24
|
+
responseBufferSize: number,
|
|
25
|
+
options?: Options,
|
|
26
|
+
tools?: Tool[],
|
|
27
|
+
callback?: (token: string, tokenId: number) => void
|
|
28
|
+
): Promise<CactusLMCompleteResult> {
|
|
29
|
+
const messagesJson = JSON.stringify(messages);
|
|
30
|
+
const optionsJson = options
|
|
31
|
+
? JSON.stringify({
|
|
32
|
+
temperature: options.temperature,
|
|
33
|
+
top_p: options.topP,
|
|
34
|
+
top_k: options.topK,
|
|
35
|
+
max_tokens: options.maxTokens,
|
|
36
|
+
stop_sequences: options.stopSequences,
|
|
37
|
+
})
|
|
38
|
+
: undefined;
|
|
39
|
+
const toolsJson = JSON.stringify(tools);
|
|
40
|
+
|
|
41
|
+
const response = await this.hybridCactus.complete(
|
|
42
|
+
messagesJson,
|
|
43
|
+
responseBufferSize,
|
|
44
|
+
optionsJson,
|
|
45
|
+
toolsJson,
|
|
46
|
+
callback
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const parsed = JSON.parse(response);
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
success: parsed.success,
|
|
54
|
+
response: parsed.response,
|
|
55
|
+
functionCalls: parsed.function_calls,
|
|
56
|
+
timeToFirstTokenMs: parsed.time_to_first_token_ms,
|
|
57
|
+
totalTimeMs: parsed.total_time_ms,
|
|
58
|
+
tokensPerSecond: parsed.tokens_per_second,
|
|
59
|
+
prefillTokens: parsed.prefill_tokens,
|
|
60
|
+
decodeTokens: parsed.decode_tokens,
|
|
61
|
+
totalTokens: parsed.total_tokens,
|
|
62
|
+
};
|
|
63
|
+
} catch {
|
|
64
|
+
throw new Error('Unable to parse completion response');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public embed(text: string, embeddingBufferSize: number): Promise<number[]> {
|
|
69
|
+
return this.hybridCactus.embed(text, embeddingBufferSize);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public reset(): Promise<void> {
|
|
73
|
+
return this.hybridCactus.reset();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public stop(): Promise<void> {
|
|
77
|
+
return this.hybridCactus.stop();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public destroy(): Promise<void> {
|
|
81
|
+
return this.hybridCactus.destroy();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
2
|
+
import type { CactusCrypto as CactusCryptoSpec } from '../specs/CactusCrypto.nitro';
|
|
3
|
+
|
|
4
|
+
export class CactusCrypto {
|
|
5
|
+
private static readonly hybridCactusCrypto =
|
|
6
|
+
NitroModules.createHybridObject<CactusCryptoSpec>('CactusCrypto');
|
|
7
|
+
|
|
8
|
+
public static uuidv5(namespaceUuid: string, name: string): Promise<string> {
|
|
9
|
+
return this.hybridCactusCrypto.uuidv5(namespaceUuid, name);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
2
|
+
import type {
|
|
3
|
+
CactusDeviceInfo as CactusDeviceInfoSpec,
|
|
4
|
+
DeviceInfo,
|
|
5
|
+
} from '../specs/CactusDeviceInfo.nitro';
|
|
6
|
+
|
|
7
|
+
export class CactusDeviceInfo {
|
|
8
|
+
private static readonly hybridCactusDeviceInfo =
|
|
9
|
+
NitroModules.createHybridObject<CactusDeviceInfoSpec>('CactusDeviceInfo');
|
|
10
|
+
|
|
11
|
+
public static getAppIdentifier(): Promise<string | undefined> {
|
|
12
|
+
return this.hybridCactusDeviceInfo.getAppIdentifier();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public static getDeviceInfo(): Promise<DeviceInfo> {
|
|
16
|
+
return this.hybridCactusDeviceInfo.getDeviceInfo();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
2
|
+
import type { CactusFileSystem as CactusFileSystemSpec } from '../specs/CactusFileSystem.nitro';
|
|
3
|
+
|
|
4
|
+
export class CactusFileSystem {
|
|
5
|
+
private static readonly hybridCactusFileSystem =
|
|
6
|
+
NitroModules.createHybridObject<CactusFileSystemSpec>('CactusFileSystem');
|
|
7
|
+
|
|
8
|
+
public static getCactusDirectory(): Promise<string> {
|
|
9
|
+
return this.hybridCactusFileSystem.getCactusDirectory();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public static fileExists(path: string): Promise<boolean> {
|
|
13
|
+
return this.hybridCactusFileSystem.fileExists(path);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public static writeFile(path: string, content: string): Promise<void> {
|
|
17
|
+
return this.hybridCactusFileSystem.writeFile(path, content);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public static readFile(path: string): Promise<string> {
|
|
21
|
+
return this.hybridCactusFileSystem.readFile(path);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public static deleteFile(path: string): Promise<void> {
|
|
25
|
+
return this.hybridCactusFileSystem.deleteFile(path);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public static modelExists(model: string): Promise<boolean> {
|
|
29
|
+
return this.hybridCactusFileSystem.modelExists(model);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public static getModelPath(model: string): Promise<string> {
|
|
33
|
+
return this.hybridCactusFileSystem.getModelPath(model);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public static downloadModel(
|
|
37
|
+
model: string,
|
|
38
|
+
onProgress?: (progress: number) => void
|
|
39
|
+
): Promise<void> {
|
|
40
|
+
const from = `https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/${model}.zip`;
|
|
41
|
+
return this.hybridCactusFileSystem.downloadModel(model, from, onProgress);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public static deleteModel(model: string): Promise<void> {
|
|
45
|
+
return this.hybridCactusFileSystem.deleteModel(model);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
2
|
+
import type { CactusUtil as CactusUtilSpec } from '../specs/CactusUtil.nitro';
|
|
3
|
+
import { Platform } from 'react-native';
|
|
4
|
+
import { CactusFileSystem } from './CactusFileSystem';
|
|
5
|
+
|
|
6
|
+
export class CactusUtil {
|
|
7
|
+
private static readonly hybridCactusUtil =
|
|
8
|
+
NitroModules.createHybridObject<CactusUtilSpec>('CactusUtil');
|
|
9
|
+
|
|
10
|
+
public static async registerApp(encryptedData: string): Promise<string> {
|
|
11
|
+
if (Platform.OS === 'android') {
|
|
12
|
+
const cactusDirectory = await CactusFileSystem.getCactusDirectory();
|
|
13
|
+
this.hybridCactusUtil.setAndroidDataDirectory(cactusDirectory);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return this.hybridCactusUtil.registerApp(encryptedData);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public static async getDeviceId(): Promise<string | null> {
|
|
20
|
+
if (Platform.OS === 'android') {
|
|
21
|
+
const cactusDirectory = await CactusFileSystem.getCactusDirectory();
|
|
22
|
+
this.hybridCactusUtil.setAndroidDataDirectory(cactusDirectory);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return this.hybridCactusUtil.getDeviceId();
|
|
26
|
+
}
|
|
27
|
+
}
|