cactus-react-native 0.2.10 → 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 +283 -722
- 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.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 -139
- 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 -814
- 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_v8.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2_dotprod.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2_dotprod_i8mm.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2_i8mm.so +0 -0
- package/android/src/newarch/java/com/cactus/CactusModule.java +0 -206
- 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 -8
- 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 -29
- 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 -4
- 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 -24
- 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 -10
- 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 -662
- 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 -42
- package/src/vlm.ts +0 -276
package/README.md
CHANGED
|
@@ -1,828 +1,389 @@
|
|
|
1
|
-
|
|
1
|
+

|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Resources
|
|
4
|
+
|
|
5
|
+
[](https://github.com/cactus-compute/cactus) [](https://huggingface.co/Cactus-Compute/models?sort=downloads) [](https://discord.gg/bNurx3AXTJ) [](https://cactuscompute.com/docs/react-native)
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
"dependencies": {
|
|
10
|
-
"cactus-react-native": "^0.2.4",
|
|
11
|
-
"react-native-fs": "^2.20.0"
|
|
12
|
-
}
|
|
13
|
-
}
|
|
9
|
+
```bash
|
|
10
|
+
npm install cactus-react-native react-native-nitro-modules
|
|
14
11
|
```
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
- iOS: `cd ios && npx pod-install`
|
|
18
|
-
- Android: Ensure `minSdkVersion` 24+
|
|
13
|
+
## Language Model
|
|
19
14
|
|
|
20
|
-
|
|
15
|
+
### Completion
|
|
21
16
|
|
|
22
|
-
|
|
23
|
-
import { CactusLM } from 'cactus-react-native';
|
|
24
|
-
import RNFS from 'react-native-fs';
|
|
17
|
+
#### Class
|
|
25
18
|
|
|
26
|
-
|
|
19
|
+
```typescript
|
|
20
|
+
import { CactusLM, type Message } from 'cactus-react-native';
|
|
27
21
|
|
|
28
|
-
const
|
|
29
|
-
model: modelPath,
|
|
30
|
-
n_ctx: 2048,
|
|
31
|
-
n_threads: 4,
|
|
32
|
-
});
|
|
22
|
+
const cactusLM = new CactusLM();
|
|
33
23
|
|
|
34
|
-
|
|
24
|
+
const messages: Message[] = [{ role: 'user', content: 'Hello, World!' }];
|
|
25
|
+
const onToken = (token: string) => {
|
|
26
|
+
console.log('Received token:', token);
|
|
27
|
+
};
|
|
35
28
|
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
console.log(result.text);
|
|
39
|
-
lm.release();
|
|
29
|
+
const result = await cactusLM.complete({ messages, onToken });
|
|
30
|
+
console.log('Completion result:', result);
|
|
40
31
|
```
|
|
41
32
|
|
|
42
|
-
|
|
33
|
+
#### Hook
|
|
43
34
|
|
|
44
|
-
```
|
|
45
|
-
import
|
|
46
|
-
import { View, Text, TextInput, TouchableOpacity, ScrollView, ActivityIndicator } from 'react-native';
|
|
47
|
-
import { CactusLM } from 'cactus-react-native';
|
|
48
|
-
import RNFS from 'react-native-fs';
|
|
35
|
+
```tsx
|
|
36
|
+
import { useCactusLM, type Message } from 'cactus-react-native';
|
|
49
37
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
content: string;
|
|
53
|
-
}
|
|
38
|
+
const App = () => {
|
|
39
|
+
const cactusLM = useCactusLM();
|
|
54
40
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const [messages, setMessages] = useState<Message[]>([]);
|
|
58
|
-
const [input, setInput] = useState('');
|
|
59
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
60
|
-
const [isGenerating, setIsGenerating] = useState(false);
|
|
61
|
-
|
|
62
|
-
useEffect(() => {
|
|
63
|
-
initializeModel();
|
|
64
|
-
return () => {
|
|
65
|
-
lm?.release();
|
|
66
|
-
};
|
|
67
|
-
}, []);
|
|
68
|
-
|
|
69
|
-
const initializeModel = async () => {
|
|
70
|
-
try {
|
|
71
|
-
const modelUrl = 'https://huggingface.co/Cactus-Compute/Qwen3-600m-Instruct-GGUF/resolve/main/Qwen3-0.6B-Q8_0.gguf';
|
|
72
|
-
const modelPath = await downloadModel(modelUrl, 'qwen-600m.gguf');
|
|
73
|
-
|
|
74
|
-
const { lm: model, error } = await CactusLM.init({
|
|
75
|
-
model: modelPath,
|
|
76
|
-
n_ctx: 2048,
|
|
77
|
-
n_threads: 4,
|
|
78
|
-
n_gpu_layers: 99,
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
if (error) throw error;
|
|
82
|
-
setLM(model);
|
|
83
|
-
} catch (error) {
|
|
84
|
-
console.error('Failed to initialize model:', error);
|
|
85
|
-
} finally {
|
|
86
|
-
setIsLoading(false);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const downloadModel = async (url: string, filename: string): Promise<string> => {
|
|
91
|
-
const path = `${RNFS.DocumentDirectoryPath}/${filename}`;
|
|
92
|
-
|
|
93
|
-
if (await RNFS.exists(path)) return path;
|
|
94
|
-
|
|
95
|
-
console.log('Downloading model...');
|
|
96
|
-
await RNFS.downloadFile({
|
|
97
|
-
fromUrl: url,
|
|
98
|
-
toFile: path,
|
|
99
|
-
progress: (res) => {
|
|
100
|
-
const progress = res.bytesWritten / res.contentLength;
|
|
101
|
-
console.log(`Download progress: ${(progress * 100).toFixed(1)}%`);
|
|
102
|
-
},
|
|
103
|
-
}).promise;
|
|
104
|
-
|
|
105
|
-
return path;
|
|
106
|
-
};
|
|
41
|
+
const handleComplete = async () => {
|
|
42
|
+
const messages: Message[] = [{ role: 'user', content: 'Hello, World!' }];
|
|
107
43
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const userMessage: Message = { role: 'user', content: input.trim() };
|
|
112
|
-
const newMessages = [...messages, userMessage];
|
|
113
|
-
setMessages([...newMessages, { role: 'assistant', content: '' }]);
|
|
114
|
-
setInput('');
|
|
115
|
-
setIsGenerating(true);
|
|
116
|
-
|
|
117
|
-
try {
|
|
118
|
-
let response = '';
|
|
119
|
-
await lm.completion(newMessages, {
|
|
120
|
-
n_predict: 200,
|
|
121
|
-
temperature: 0.7,
|
|
122
|
-
stop: ['</s>', '<|end|>'],
|
|
123
|
-
}, (token) => {
|
|
124
|
-
response += token.token;
|
|
125
|
-
setMessages(prev => [
|
|
126
|
-
...prev.slice(0, -1),
|
|
127
|
-
{ role: 'assistant', content: response }
|
|
128
|
-
]);
|
|
129
|
-
});
|
|
130
|
-
} catch (error) {
|
|
131
|
-
console.error('Generation failed:', error);
|
|
132
|
-
setMessages(prev => [
|
|
133
|
-
...prev.slice(0, -1),
|
|
134
|
-
{ role: 'assistant', content: 'Error generating response' }
|
|
135
|
-
]);
|
|
136
|
-
} finally {
|
|
137
|
-
setIsGenerating(false);
|
|
138
|
-
}
|
|
44
|
+
const result = await cactusLM.complete({ messages });
|
|
45
|
+
console.log('Completion result:', result);
|
|
139
46
|
};
|
|
140
47
|
|
|
141
|
-
if (isLoading) {
|
|
142
|
-
return (
|
|
143
|
-
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
|
|
144
|
-
<ActivityIndicator size="large" />
|
|
145
|
-
<Text style={{ marginTop: 16 }}>Loading model...</Text>
|
|
146
|
-
</View>
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
48
|
return (
|
|
151
|
-
|
|
152
|
-
<
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
key={index}
|
|
156
|
-
style={{
|
|
157
|
-
backgroundColor: msg.role === 'user' ? '#007AFF' : '#ffffff',
|
|
158
|
-
padding: 12,
|
|
159
|
-
marginVertical: 4,
|
|
160
|
-
borderRadius: 12,
|
|
161
|
-
alignSelf: msg.role === 'user' ? 'flex-end' : 'flex-start',
|
|
162
|
-
maxWidth: '80%',
|
|
163
|
-
shadowColor: '#000',
|
|
164
|
-
shadowOffset: { width: 0, height: 1 },
|
|
165
|
-
shadowOpacity: 0.2,
|
|
166
|
-
shadowRadius: 2,
|
|
167
|
-
elevation: 2,
|
|
168
|
-
}}
|
|
169
|
-
>
|
|
170
|
-
<Text style={{
|
|
171
|
-
color: msg.role === 'user' ? '#ffffff' : '#000000',
|
|
172
|
-
fontSize: 16,
|
|
173
|
-
}}>
|
|
174
|
-
{msg.content}
|
|
175
|
-
</Text>
|
|
176
|
-
</View>
|
|
177
|
-
))}
|
|
178
|
-
</ScrollView>
|
|
179
|
-
|
|
180
|
-
<View style={{
|
|
181
|
-
flexDirection: 'row',
|
|
182
|
-
padding: 16,
|
|
183
|
-
backgroundColor: '#ffffff',
|
|
184
|
-
borderTopWidth: 1,
|
|
185
|
-
borderTopColor: '#e0e0e0',
|
|
186
|
-
}}>
|
|
187
|
-
<TextInput
|
|
188
|
-
style={{
|
|
189
|
-
flex: 1,
|
|
190
|
-
borderWidth: 1,
|
|
191
|
-
borderColor: '#e0e0e0',
|
|
192
|
-
borderRadius: 20,
|
|
193
|
-
paddingHorizontal: 16,
|
|
194
|
-
paddingVertical: 10,
|
|
195
|
-
fontSize: 16,
|
|
196
|
-
backgroundColor: '#f8f8f8',
|
|
197
|
-
}}
|
|
198
|
-
value={input}
|
|
199
|
-
onChangeText={setInput}
|
|
200
|
-
placeholder="Type a message..."
|
|
201
|
-
multiline
|
|
202
|
-
onSubmitEditing={sendMessage}
|
|
203
|
-
/>
|
|
204
|
-
<TouchableOpacity
|
|
205
|
-
onPress={sendMessage}
|
|
206
|
-
disabled={isGenerating || !input.trim()}
|
|
207
|
-
style={{
|
|
208
|
-
backgroundColor: isGenerating ? '#cccccc' : '#007AFF',
|
|
209
|
-
borderRadius: 20,
|
|
210
|
-
paddingHorizontal: 16,
|
|
211
|
-
paddingVertical: 10,
|
|
212
|
-
marginLeft: 8,
|
|
213
|
-
justifyContent: 'center',
|
|
214
|
-
}}
|
|
215
|
-
>
|
|
216
|
-
<Text style={{ color: '#ffffff', fontWeight: 'bold' }}>
|
|
217
|
-
{isGenerating ? '...' : 'Send'}
|
|
218
|
-
</Text>
|
|
219
|
-
</TouchableOpacity>
|
|
220
|
-
</View>
|
|
221
|
-
</View>
|
|
49
|
+
<>
|
|
50
|
+
<Button title="Complete" onPress={handleComplete} />
|
|
51
|
+
<Text>{cactusLM.completion}</Text>
|
|
52
|
+
</>
|
|
222
53
|
);
|
|
223
|
-
}
|
|
54
|
+
};
|
|
224
55
|
```
|
|
225
56
|
|
|
226
|
-
|
|
57
|
+
### Tool Calling
|
|
227
58
|
|
|
228
|
-
|
|
59
|
+
#### Class
|
|
229
60
|
|
|
230
61
|
```typescript
|
|
231
|
-
import { CactusLM } from 'cactus-react-native';
|
|
62
|
+
import { CactusLM, type Message, type Tool } from 'cactus-react-native';
|
|
232
63
|
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
await lm.release();
|
|
251
|
-
```
|
|
64
|
+
const tools: Tool[] = [
|
|
65
|
+
{
|
|
66
|
+
type: 'function',
|
|
67
|
+
name: 'get_weather',
|
|
68
|
+
description: 'Get current weather for a location',
|
|
69
|
+
parameters: {
|
|
70
|
+
type: 'object',
|
|
71
|
+
properties: {
|
|
72
|
+
location: {
|
|
73
|
+
type: 'string',
|
|
74
|
+
description: 'City name',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
required: ['location'],
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
];
|
|
252
81
|
|
|
253
|
-
|
|
82
|
+
const cactusLM = new CactusLM();
|
|
254
83
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
n_ctx: 2048,
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
const messages = [{ role: 'user', content: 'Describe this image' }];
|
|
265
|
-
const result = await vlm.completion(messages, {
|
|
266
|
-
images: ['/path/to/image.jpg'],
|
|
267
|
-
n_predict: 200,
|
|
268
|
-
temperature: 0.3,
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
await vlm.release();
|
|
84
|
+
const messages: Message[] = [
|
|
85
|
+
{ role: 'user', content: "What's the weather in San Francisco?" },
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
const result = await cactusLM.complete({ messages, tools });
|
|
89
|
+
console.log('Response:', result.response);
|
|
272
90
|
```
|
|
273
91
|
|
|
274
|
-
|
|
92
|
+
#### Hook
|
|
275
93
|
|
|
276
94
|
```typescript
|
|
277
|
-
import {
|
|
95
|
+
import { useCactusLM, type Message, type Tool } from 'cactus-react-native';
|
|
278
96
|
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
97
|
+
const tools: Tool[] = [
|
|
98
|
+
{
|
|
99
|
+
type: 'function',
|
|
100
|
+
name: 'get_weather',
|
|
101
|
+
description: 'Get current weather for a location',
|
|
102
|
+
parameters: {
|
|
103
|
+
type: 'object',
|
|
104
|
+
properties: {
|
|
105
|
+
location: {
|
|
106
|
+
type: 'string',
|
|
107
|
+
description: 'City name',
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
required: ['location'],
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
];
|
|
114
|
+
|
|
115
|
+
const App = () => {
|
|
116
|
+
const cactusLM = useCactusLM();
|
|
283
117
|
|
|
284
|
-
const
|
|
118
|
+
const handleComplete = async () => {
|
|
119
|
+
const messages: Message[] = [
|
|
120
|
+
{ role: 'user', content: "What's the weather in San Francisco?" },
|
|
121
|
+
];
|
|
285
122
|
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
123
|
+
const result = await cactusLM.complete({ messages, tools });
|
|
124
|
+
console.log('Response:', result.response);
|
|
125
|
+
console.log('Function calls:', result.functionCalls);
|
|
126
|
+
};
|
|
290
127
|
|
|
291
|
-
|
|
128
|
+
return <Button title="Complete" onPress={handleComplete} />;
|
|
129
|
+
};
|
|
292
130
|
```
|
|
293
131
|
|
|
294
|
-
|
|
132
|
+
### Embedding
|
|
295
133
|
|
|
296
|
-
|
|
134
|
+
#### Class
|
|
297
135
|
|
|
298
136
|
```typescript
|
|
299
|
-
|
|
300
|
-
private models = new Map<string, CactusLM | CactusVLM>();
|
|
301
|
-
|
|
302
|
-
async loadLM(name: string, modelPath: string): Promise<CactusLM> {
|
|
303
|
-
if (this.models.has(name)) {
|
|
304
|
-
return this.models.get(name) as CactusLM;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
const { lm, error } = await CactusLM.init({
|
|
308
|
-
model: modelPath,
|
|
309
|
-
n_ctx: 2048,
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
if (error) throw error;
|
|
313
|
-
this.models.set(name, lm);
|
|
314
|
-
return lm;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
async loadVLM(name: string, modelPath: string, mmprojPath: string): Promise<CactusVLM> {
|
|
318
|
-
if (this.models.has(name)) {
|
|
319
|
-
return this.models.get(name) as CactusVLM;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
const { vlm, error } = await CactusVLM.init({
|
|
323
|
-
model: modelPath,
|
|
324
|
-
mmproj: mmprojPath,
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
if (error) throw error;
|
|
328
|
-
this.models.set(name, vlm);
|
|
329
|
-
return vlm;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
async releaseModel(name: string): Promise<void> {
|
|
333
|
-
const model = this.models.get(name);
|
|
334
|
-
if (model) {
|
|
335
|
-
await model.release();
|
|
336
|
-
this.models.delete(name);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
async releaseAll(): Promise<void> {
|
|
341
|
-
await Promise.all(
|
|
342
|
-
Array.from(this.models.values()).map(model => model.release())
|
|
343
|
-
);
|
|
344
|
-
this.models.clear();
|
|
345
|
-
}
|
|
346
|
-
}
|
|
137
|
+
import { CactusLM } from 'cactus-react-native';
|
|
347
138
|
|
|
348
|
-
const
|
|
139
|
+
const cactusLM = new CactusLM();
|
|
140
|
+
|
|
141
|
+
const result = await cactusLM.embed({ text: 'Hello, World!' });
|
|
142
|
+
console.log('Embedding vector:', result.embedding);
|
|
143
|
+
console.log('Embedding vector length:', result.embedding.length);
|
|
349
144
|
```
|
|
350
145
|
|
|
351
|
-
|
|
146
|
+
#### Hook
|
|
352
147
|
|
|
353
148
|
```typescript
|
|
354
|
-
import {
|
|
355
|
-
import RNFS from 'react-native-fs';
|
|
149
|
+
import { useCactusLM } from 'cactus-react-native';
|
|
356
150
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
isDownloading: boolean;
|
|
360
|
-
error: string | null;
|
|
361
|
-
}
|
|
151
|
+
const App = () => {
|
|
152
|
+
const cactusLM = useCactusLM();
|
|
362
153
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
const stats = await RNFS.stat(path);
|
|
371
|
-
if (stats.size > 0) return path;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
setDownloads(prev => new Map(prev.set(filename, {
|
|
375
|
-
progress: 0,
|
|
376
|
-
isDownloading: true,
|
|
377
|
-
error: null,
|
|
378
|
-
})));
|
|
379
|
-
|
|
380
|
-
try {
|
|
381
|
-
await RNFS.downloadFile({
|
|
382
|
-
fromUrl: url,
|
|
383
|
-
toFile: path,
|
|
384
|
-
progress: (res) => {
|
|
385
|
-
const progress = res.bytesWritten / res.contentLength;
|
|
386
|
-
setDownloads(prev => new Map(prev.set(filename, {
|
|
387
|
-
progress,
|
|
388
|
-
isDownloading: true,
|
|
389
|
-
error: null,
|
|
390
|
-
})));
|
|
391
|
-
},
|
|
392
|
-
}).promise;
|
|
393
|
-
|
|
394
|
-
setDownloads(prev => new Map(prev.set(filename, {
|
|
395
|
-
progress: 1,
|
|
396
|
-
isDownloading: false,
|
|
397
|
-
error: null,
|
|
398
|
-
})));
|
|
399
|
-
|
|
400
|
-
return path;
|
|
401
|
-
} catch (error) {
|
|
402
|
-
setDownloads(prev => new Map(prev.set(filename, {
|
|
403
|
-
progress: 0,
|
|
404
|
-
isDownloading: false,
|
|
405
|
-
error: error.message,
|
|
406
|
-
})));
|
|
407
|
-
throw error;
|
|
408
|
-
}
|
|
409
|
-
}, []);
|
|
410
|
-
|
|
411
|
-
return { downloadModel, downloads };
|
|
154
|
+
const handleEmbed = async () => {
|
|
155
|
+
const result = await cactusLM.embed({ text: 'Hello, World!' });
|
|
156
|
+
console.log('Embedding vector:', result.embedding);
|
|
157
|
+
console.log('Embedding vector length:', result.embedding.length);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
return <Button title="Embed" onPress={handleEmbed} />;
|
|
412
161
|
};
|
|
413
162
|
```
|
|
414
163
|
|
|
415
|
-
|
|
164
|
+
## API Reference
|
|
416
165
|
|
|
417
|
-
|
|
418
|
-
import React, { useState, useEffect } from 'react';
|
|
419
|
-
import { View, Text, TouchableOpacity, Image, Alert } from 'react-native';
|
|
420
|
-
import { launchImageLibrary } from 'react-native-image-picker';
|
|
421
|
-
import { CactusVLM } from 'cactus-react-native';
|
|
422
|
-
import RNFS from 'react-native-fs';
|
|
423
|
-
|
|
424
|
-
export default function VisionChat() {
|
|
425
|
-
const [vlm, setVLM] = useState<CactusVLM | null>(null);
|
|
426
|
-
const [imagePath, setImagePath] = useState<string | null>(null);
|
|
427
|
-
const [response, setResponse] = useState('');
|
|
428
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
429
|
-
const [isAnalyzing, setIsAnalyzing] = useState(false);
|
|
430
|
-
|
|
431
|
-
useEffect(() => {
|
|
432
|
-
initializeVLM();
|
|
433
|
-
return () => {
|
|
434
|
-
vlm?.release();
|
|
435
|
-
};
|
|
436
|
-
}, []);
|
|
437
|
-
|
|
438
|
-
const initializeVLM = async () => {
|
|
439
|
-
try {
|
|
440
|
-
const modelUrl = 'https://huggingface.co/Cactus-Compute/SmolVLM2-500m-Instruct-GGUF/resolve/main/SmolVLM2-500M-Video-Instruct-Q8_0.gguf';
|
|
441
|
-
const mmprojUrl = 'https://huggingface.co/Cactus-Compute/SmolVLM2-500m-Instruct-GGUF/resolve/main/mmproj-SmolVLM2-500M-Video-Instruct-Q8_0.gguf';
|
|
442
|
-
|
|
443
|
-
const [modelPath, mmprojPath] = await Promise.all([
|
|
444
|
-
downloadFile(modelUrl, 'smolvlm-model.gguf'),
|
|
445
|
-
downloadFile(mmprojUrl, 'smolvlm-mmproj.gguf'),
|
|
446
|
-
]);
|
|
447
|
-
|
|
448
|
-
const { vlm: model, error } = await CactusVLM.init({
|
|
449
|
-
model: modelPath,
|
|
450
|
-
mmproj: mmprojPath,
|
|
451
|
-
n_ctx: 2048,
|
|
452
|
-
});
|
|
453
|
-
|
|
454
|
-
if (error) throw error;
|
|
455
|
-
setVLM(model);
|
|
456
|
-
} catch (error) {
|
|
457
|
-
console.error('Failed to initialize VLM:', error);
|
|
458
|
-
Alert.alert('Error', 'Failed to initialize vision model');
|
|
459
|
-
} finally {
|
|
460
|
-
setIsLoading(false);
|
|
461
|
-
}
|
|
462
|
-
};
|
|
166
|
+
### `CactusLM` Class
|
|
463
167
|
|
|
464
|
-
|
|
465
|
-
const path = `${RNFS.DocumentDirectoryPath}/${filename}`;
|
|
466
|
-
|
|
467
|
-
if (await RNFS.exists(path)) return path;
|
|
468
|
-
|
|
469
|
-
await RNFS.downloadFile({ fromUrl: url, toFile: path }).promise;
|
|
470
|
-
return path;
|
|
471
|
-
};
|
|
168
|
+
#### Constructor
|
|
472
169
|
|
|
473
|
-
|
|
474
|
-
launchImageLibrary(
|
|
475
|
-
{
|
|
476
|
-
mediaType: 'photo',
|
|
477
|
-
quality: 0.8,
|
|
478
|
-
includeBase64: false,
|
|
479
|
-
},
|
|
480
|
-
(response) => {
|
|
481
|
-
if (response.assets && response.assets[0]) {
|
|
482
|
-
setImagePath(response.assets[0].uri!);
|
|
483
|
-
setResponse('');
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
);
|
|
487
|
-
};
|
|
170
|
+
**`new CactusLM(params?: CactusLMParams)`**
|
|
488
171
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
setIsAnalyzing(true);
|
|
493
|
-
try {
|
|
494
|
-
const messages = [{ role: 'user', content: 'Describe this image in detail' }];
|
|
495
|
-
|
|
496
|
-
let analysisResponse = '';
|
|
497
|
-
const result = await vlm.completion(messages, {
|
|
498
|
-
images: [imagePath],
|
|
499
|
-
n_predict: 300,
|
|
500
|
-
temperature: 0.3,
|
|
501
|
-
}, (token) => {
|
|
502
|
-
analysisResponse += token.token;
|
|
503
|
-
setResponse(analysisResponse);
|
|
504
|
-
});
|
|
505
|
-
|
|
506
|
-
setResponse(analysisResponse || result.text);
|
|
507
|
-
} catch (error) {
|
|
508
|
-
console.error('Analysis failed:', error);
|
|
509
|
-
Alert.alert('Error', 'Failed to analyze image');
|
|
510
|
-
} finally {
|
|
511
|
-
setIsAnalyzing(false);
|
|
512
|
-
}
|
|
513
|
-
};
|
|
172
|
+
- `model` - Model slug (default: `'qwen3-0.6'`)
|
|
173
|
+
- `contextSize` - Context window size (default: `2048`)
|
|
514
174
|
|
|
515
|
-
|
|
516
|
-
return (
|
|
517
|
-
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
|
|
518
|
-
<Text>Loading vision model...</Text>
|
|
519
|
-
</View>
|
|
520
|
-
);
|
|
521
|
-
}
|
|
175
|
+
#### Methods
|
|
522
176
|
|
|
523
|
-
|
|
524
|
-
<View style={{ flex: 1, padding: 16 }}>
|
|
525
|
-
<Text style={{ fontSize: 24, fontWeight: 'bold', marginBottom: 20 }}>
|
|
526
|
-
Vision Chat
|
|
527
|
-
</Text>
|
|
528
|
-
|
|
529
|
-
{imagePath && (
|
|
530
|
-
<Image
|
|
531
|
-
source={{ uri: imagePath }}
|
|
532
|
-
style={{
|
|
533
|
-
width: '100%',
|
|
534
|
-
height: 200,
|
|
535
|
-
borderRadius: 8,
|
|
536
|
-
marginBottom: 16,
|
|
537
|
-
}}
|
|
538
|
-
resizeMode="contain"
|
|
539
|
-
/>
|
|
540
|
-
)}
|
|
541
|
-
|
|
542
|
-
<View style={{ flexDirection: 'row', marginBottom: 16 }}>
|
|
543
|
-
<TouchableOpacity
|
|
544
|
-
onPress={pickImage}
|
|
545
|
-
style={{
|
|
546
|
-
backgroundColor: '#007AFF',
|
|
547
|
-
padding: 12,
|
|
548
|
-
borderRadius: 8,
|
|
549
|
-
marginRight: 8,
|
|
550
|
-
flex: 1,
|
|
551
|
-
}}
|
|
552
|
-
>
|
|
553
|
-
<Text style={{ color: 'white', textAlign: 'center', fontWeight: 'bold' }}>
|
|
554
|
-
Pick Image
|
|
555
|
-
</Text>
|
|
556
|
-
</TouchableOpacity>
|
|
557
|
-
|
|
558
|
-
<TouchableOpacity
|
|
559
|
-
onPress={analyzeImage}
|
|
560
|
-
disabled={!imagePath || isAnalyzing}
|
|
561
|
-
style={{
|
|
562
|
-
backgroundColor: !imagePath || isAnalyzing ? '#cccccc' : '#34C759',
|
|
563
|
-
padding: 12,
|
|
564
|
-
borderRadius: 8,
|
|
565
|
-
flex: 1,
|
|
566
|
-
}}
|
|
567
|
-
>
|
|
568
|
-
<Text style={{ color: 'white', textAlign: 'center', fontWeight: 'bold' }}>
|
|
569
|
-
{isAnalyzing ? 'Analyzing...' : 'Analyze'}
|
|
570
|
-
</Text>
|
|
571
|
-
</TouchableOpacity>
|
|
572
|
-
</View>
|
|
573
|
-
|
|
574
|
-
<View style={{
|
|
575
|
-
flex: 1,
|
|
576
|
-
backgroundColor: '#f8f8f8',
|
|
577
|
-
borderRadius: 8,
|
|
578
|
-
padding: 16,
|
|
579
|
-
}}>
|
|
580
|
-
<Text style={{ fontSize: 16, lineHeight: 24 }}>
|
|
581
|
-
{response || 'Select an image and tap Analyze to get started'}
|
|
582
|
-
</Text>
|
|
583
|
-
</View>
|
|
584
|
-
</View>
|
|
585
|
-
);
|
|
586
|
-
}
|
|
587
|
-
```
|
|
177
|
+
**`download(params?: CactusLMDownloadParams): Promise<void>`**
|
|
588
178
|
|
|
589
|
-
|
|
179
|
+
- Downloads the model.
|
|
180
|
+
- `onProgress` - Callback for download progress (0-1).
|
|
590
181
|
|
|
591
|
-
|
|
592
|
-
const { vlm } = await CactusVLM.init({
|
|
593
|
-
model: '/path/to/model.gguf',
|
|
594
|
-
mmproj: '/path/to/mmproj.gguf',
|
|
595
|
-
}, undefined, 'your_cactus_token');
|
|
596
|
-
|
|
597
|
-
const result = await vlm.completion(messages, {
|
|
598
|
-
images: ['/path/to/image.jpg'],
|
|
599
|
-
mode: 'localfirst', // ("remotefirst", "local", "remote")
|
|
600
|
-
});
|
|
601
|
-
```
|
|
182
|
+
**`init(): Promise<void>`**
|
|
602
183
|
|
|
603
|
-
|
|
184
|
+
- Initializes the model and prepares it for inference.
|
|
604
185
|
|
|
605
|
-
|
|
606
|
-
const { lm } = await CactusLM.init({
|
|
607
|
-
model: '/path/to/model.gguf',
|
|
608
|
-
embedding: true,
|
|
609
|
-
});
|
|
610
|
-
|
|
611
|
-
const embedding1 = await lm.embedding('machine learning');
|
|
612
|
-
const embedding2 = await lm.embedding('artificial intelligence');
|
|
613
|
-
|
|
614
|
-
function cosineSimilarity(a: number[], b: number[]): number {
|
|
615
|
-
const dotProduct = a.reduce((sum, ai, i) => sum + ai * b[i], 0);
|
|
616
|
-
const magnitudeA = Math.sqrt(a.reduce((sum, ai) => sum + ai * ai, 0));
|
|
617
|
-
const magnitudeB = Math.sqrt(b.reduce((sum, bi) => sum + bi * bi, 0));
|
|
618
|
-
return dotProduct / (magnitudeA * magnitudeB);
|
|
619
|
-
}
|
|
186
|
+
**`complete(params: CactusLMCompleteParams): Promise<CactusLMCompleteResult>`**
|
|
620
187
|
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
188
|
+
- Performs text completion with optional streaming and tool support (initializes the model if needed).
|
|
189
|
+
- `messages` - Array of `Message` objects.
|
|
190
|
+
- `options` - Generation options:
|
|
191
|
+
|
|
192
|
+
- `temperature` - Sampling temperature (default: model-optimized).
|
|
193
|
+
- `topP` - Nucleus sampling threshold (default: model-optimized).
|
|
194
|
+
- `topK` - Top-K sampling limit (default: model-optimized).
|
|
195
|
+
- `maxTokens` - Maximum number of tokens to generate (default: `512`).
|
|
196
|
+
- `stopSequences` - Array of strings to stop generation (default: `undefined`).
|
|
197
|
+
- `tools` - Array of `Tool` objects for function calling (default: `undefined`).
|
|
198
|
+
- `onToken` - Callback for streaming tokens.
|
|
624
199
|
|
|
625
|
-
|
|
200
|
+
**`embed(params: CactusLMEmbedParams): Promise<CactusLMEmbedResult>`**
|
|
626
201
|
|
|
627
|
-
|
|
202
|
+
- Generates embeddings for the given text (initializes the model if needed).
|
|
203
|
+
- `text` - Text to embed.
|
|
204
|
+
|
|
205
|
+
**`stop(): Promise<void>`**
|
|
206
|
+
|
|
207
|
+
- Stops ongoing generation.
|
|
208
|
+
|
|
209
|
+
**`reset(): Promise<void>`**
|
|
210
|
+
|
|
211
|
+
- Resets the model's internal state, clearing any cached context.
|
|
212
|
+
|
|
213
|
+
**`destroy(): Promise<void>`**
|
|
214
|
+
|
|
215
|
+
- Releases all resources associated with the model.
|
|
216
|
+
|
|
217
|
+
**`getModels(params?: CactusLMGetModelsParams): Promise<CactusModel[]>`**
|
|
218
|
+
|
|
219
|
+
- Fetches available models and persists the results locally.
|
|
220
|
+
- `forceRefresh` - If `true`, forces a fetch from the server and updates the local data (default: `false`).
|
|
221
|
+
|
|
222
|
+
### `useCactusLM` Hook
|
|
223
|
+
|
|
224
|
+
#### State
|
|
225
|
+
|
|
226
|
+
- `completion: string` - Current generated text.
|
|
227
|
+
- `isGenerating: boolean` - Whether the model is currently generating.
|
|
228
|
+
- `isInitializing: boolean` - Whether the model is initializing.
|
|
229
|
+
- `isDownloaded: boolean` - Whether the model is downloaded locally.
|
|
230
|
+
- `isDownloading: boolean` - Whether the model is being downloaded.
|
|
231
|
+
- `downloadProgress: number` - Download progress (0-1). `0` if not downloading.
|
|
232
|
+
- `error: string | null` - Last error message, or `null` if there is no error.
|
|
233
|
+
|
|
234
|
+
#### Methods
|
|
235
|
+
|
|
236
|
+
- `download(params?: CactusLMDownloadParams): Promise<void>`
|
|
237
|
+
- `init(): Promise<void>`
|
|
238
|
+
- `complete(params: CactusLMCompleteParams): Promise<CactusLMCompleteResult>`
|
|
239
|
+
- `embed(params: CactusLMEmbedParams): Promise<CactusLMEmbedResult>`
|
|
240
|
+
- `stop(): Promise<void>`
|
|
241
|
+
- `reset(): Promise<void>`
|
|
242
|
+
- `destroy(): Promise<void>`
|
|
243
|
+
- `getModels(params?: CactusLMGetModelsParams): Promise<CactusModel[]>`
|
|
244
|
+
|
|
245
|
+
## Type Definitions
|
|
246
|
+
|
|
247
|
+
### `CactusLMParams`
|
|
628
248
|
|
|
629
249
|
```typescript
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
{ model: modelPath, n_ctx: 2048, n_gpu_layers: 99 },
|
|
634
|
-
{ model: modelPath, n_ctx: 2048, n_gpu_layers: 0 },
|
|
635
|
-
{ model: modelPath, n_ctx: 1024, n_gpu_layers: 0 },
|
|
636
|
-
];
|
|
637
|
-
|
|
638
|
-
for (const config of configs) {
|
|
639
|
-
try {
|
|
640
|
-
const { lm, error } = await CactusLM.init(config);
|
|
641
|
-
if (error) throw error;
|
|
642
|
-
return lm;
|
|
643
|
-
} catch (error) {
|
|
644
|
-
console.warn('Config failed:', config, error.message);
|
|
645
|
-
if (configs.indexOf(config) === configs.length - 1) {
|
|
646
|
-
throw new Error(`All configurations failed. Last error: ${error.message}`);
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
throw new Error('Model initialization failed');
|
|
250
|
+
interface CactusLMParams {
|
|
251
|
+
model?: string;
|
|
252
|
+
contextSize?: number;
|
|
652
253
|
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### `CactusLMDownloadParams`
|
|
653
257
|
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
return await lm.completion(messages, { n_predict: 200 });
|
|
658
|
-
} catch (error) {
|
|
659
|
-
if (error.message.includes('Context is busy') && i < retries - 1) {
|
|
660
|
-
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
661
|
-
continue;
|
|
662
|
-
}
|
|
663
|
-
throw error;
|
|
664
|
-
}
|
|
665
|
-
}
|
|
258
|
+
```typescript
|
|
259
|
+
interface CactusLMDownloadParams {
|
|
260
|
+
onProgress?: (progress: number) => void;
|
|
666
261
|
}
|
|
667
262
|
```
|
|
668
263
|
|
|
669
|
-
###
|
|
264
|
+
### `Message`
|
|
670
265
|
|
|
671
266
|
```typescript
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
private modelManager = new ModelManager();
|
|
676
|
-
|
|
677
|
-
constructor() {
|
|
678
|
-
AppState.addEventListener('change', this.handleAppStateChange);
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
private handleAppStateChange = (nextAppState: AppStateStatus) => {
|
|
682
|
-
if (nextAppState === 'background') {
|
|
683
|
-
// Release non-essential models when app goes to background
|
|
684
|
-
this.modelManager.releaseAll();
|
|
685
|
-
}
|
|
686
|
-
};
|
|
687
|
-
|
|
688
|
-
async getModel(name: string, modelPath: string): Promise<CactusLM> {
|
|
689
|
-
try {
|
|
690
|
-
return await this.modelManager.loadLM(name, modelPath);
|
|
691
|
-
} catch (error) {
|
|
692
|
-
// Handle low memory by releasing other models
|
|
693
|
-
await this.modelManager.releaseAll();
|
|
694
|
-
return await this.modelManager.loadLM(name, modelPath);
|
|
695
|
-
}
|
|
696
|
-
}
|
|
267
|
+
interface Message {
|
|
268
|
+
role: 'user' | 'assistant' | 'system';
|
|
269
|
+
content: string;
|
|
697
270
|
}
|
|
698
271
|
```
|
|
699
272
|
|
|
700
|
-
###
|
|
273
|
+
### `Options`
|
|
701
274
|
|
|
702
275
|
```typescript
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
n_gpu_layers: OS === 'ios' ? 99 : 0, // iOS generally has better GPU support
|
|
711
|
-
n_threads: isHighEndDevice ? 6 : 4,
|
|
712
|
-
n_batch: isHighEndDevice ? 512 : 256,
|
|
713
|
-
};
|
|
714
|
-
};
|
|
715
|
-
|
|
716
|
-
const config = getOptimalConfig();
|
|
717
|
-
const { lm } = await CactusLM.init({
|
|
718
|
-
model: modelPath,
|
|
719
|
-
...config,
|
|
720
|
-
});
|
|
276
|
+
interface Options {
|
|
277
|
+
temperature?: number;
|
|
278
|
+
topP?: number;
|
|
279
|
+
topK?: number;
|
|
280
|
+
maxTokens?: number;
|
|
281
|
+
stopSequences?: string[];
|
|
282
|
+
}
|
|
721
283
|
```
|
|
722
284
|
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
The `CactusAgent` class extends `CactusLM` with built-in tool calling capabilities:
|
|
285
|
+
### `Tool`
|
|
726
286
|
|
|
727
287
|
```typescript
|
|
728
|
-
|
|
288
|
+
interface Tool {
|
|
289
|
+
type: 'function';
|
|
290
|
+
name: string;
|
|
291
|
+
description: string;
|
|
292
|
+
parameters: {
|
|
293
|
+
type: 'object';
|
|
294
|
+
properties: {
|
|
295
|
+
[key: string]: {
|
|
296
|
+
type: string;
|
|
297
|
+
description: string;
|
|
298
|
+
};
|
|
299
|
+
};
|
|
300
|
+
required: string[];
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
```
|
|
729
304
|
|
|
730
|
-
|
|
731
|
-
model: '/path/to/model.gguf', // we recommend Qwen 3 family, 0.6B is great
|
|
732
|
-
n_ctx: 2048,
|
|
733
|
-
});
|
|
305
|
+
### `CactusLMCompleteParams`
|
|
734
306
|
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
307
|
+
```typescript
|
|
308
|
+
interface CactusLMCompleteParams {
|
|
309
|
+
messages: Message[];
|
|
310
|
+
options?: Options;
|
|
311
|
+
tools?: Tool[];
|
|
312
|
+
onToken?: (token: string) => void;
|
|
313
|
+
}
|
|
314
|
+
```
|
|
742
315
|
|
|
743
|
-
|
|
744
|
-
const result = await agent.completionWithTools(messages, {
|
|
745
|
-
n_predict: 200,
|
|
746
|
-
temperature: 0.7,
|
|
747
|
-
});
|
|
316
|
+
### `CactusLMCompleteResult`
|
|
748
317
|
|
|
749
|
-
|
|
318
|
+
```typescript
|
|
319
|
+
interface CactusLMCompleteResult {
|
|
320
|
+
success: boolean;
|
|
321
|
+
response: string;
|
|
322
|
+
functionCalls?: {
|
|
323
|
+
name: string;
|
|
324
|
+
arguments: { [key: string]: any };
|
|
325
|
+
}[];
|
|
326
|
+
timeToFirstTokenMs: number;
|
|
327
|
+
totalTimeMs: number;
|
|
328
|
+
tokensPerSecond: number;
|
|
329
|
+
prefillTokens: number;
|
|
330
|
+
decodeTokens: number;
|
|
331
|
+
totalTokens: number;
|
|
332
|
+
}
|
|
750
333
|
```
|
|
751
334
|
|
|
752
|
-
###
|
|
335
|
+
### `CactusLMEmbedParams`
|
|
753
336
|
|
|
754
337
|
```typescript
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
try {
|
|
759
|
-
return `Result: ${eval(expression)}`;
|
|
760
|
-
} catch (e) {
|
|
761
|
-
return 'Invalid expression';
|
|
762
|
-
}
|
|
763
|
-
},
|
|
764
|
-
'Evaluate mathematical expressions',
|
|
765
|
-
{
|
|
766
|
-
expression: { type: 'string', description: 'Math expression to evaluate', required: true }
|
|
767
|
-
}
|
|
768
|
-
);
|
|
338
|
+
interface CactusLMEmbedParams {
|
|
339
|
+
text: string;
|
|
340
|
+
}
|
|
769
341
|
```
|
|
770
342
|
|
|
771
|
-
|
|
343
|
+
### `CactusLMEmbedResult`
|
|
772
344
|
|
|
773
|
-
|
|
345
|
+
```typescript
|
|
346
|
+
interface CactusLMEmbedResult {
|
|
347
|
+
embedding: number[];
|
|
348
|
+
}
|
|
349
|
+
```
|
|
774
350
|
|
|
775
|
-
|
|
776
|
-
- `model: string` - Path to GGUF model file
|
|
777
|
-
- `n_ctx?: number` - Context size (default: 2048)
|
|
778
|
-
- `n_threads?: number` - CPU threads (default: 4)
|
|
779
|
-
- `n_gpu_layers?: number` - GPU layers (default: 99)
|
|
780
|
-
- `embedding?: boolean` - Enable embeddings (default: false)
|
|
781
|
-
- `n_batch?: number` - Batch size (default: 512)
|
|
351
|
+
### `CactusLMGetModelsParams`
|
|
782
352
|
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
- `top_k?: number` - Top-k sampling (default: 40)
|
|
789
|
-
- `stop?: string[]` - Stop sequences
|
|
790
|
-
- `callback?: (token) => void` - Streaming callback
|
|
353
|
+
```typescript
|
|
354
|
+
interface CactusLMGetModelsParams {
|
|
355
|
+
forceRefresh?: boolean;
|
|
356
|
+
}
|
|
357
|
+
```
|
|
791
358
|
|
|
792
|
-
|
|
793
|
-
- `text: string` - Text to embed
|
|
794
|
-
- `mode?: string` - 'local' | 'localfirst' | 'remotefirst' | 'remote'
|
|
359
|
+
### `CactusModel`
|
|
795
360
|
|
|
796
|
-
|
|
361
|
+
```typescript
|
|
362
|
+
interface CactusModel {
|
|
363
|
+
name: string;
|
|
364
|
+
slug: string;
|
|
365
|
+
quantization: number;
|
|
366
|
+
sizeMb: number;
|
|
367
|
+
downloadUrl: string;
|
|
368
|
+
supportsToolCalling: boolean;
|
|
369
|
+
supportsVision: boolean;
|
|
370
|
+
createdAt: Date;
|
|
371
|
+
isDownloaded: boolean;
|
|
372
|
+
}
|
|
373
|
+
```
|
|
797
374
|
|
|
798
|
-
|
|
799
|
-
- All CactusLM params plus:
|
|
800
|
-
- `mmproj: string` - Path to multimodal projector
|
|
375
|
+
## Configuration
|
|
801
376
|
|
|
802
|
-
|
|
803
|
-
- All CactusLM completion params plus:
|
|
804
|
-
- `images?: string[]` - Array of image paths
|
|
805
|
-
- `mode?: string` - Cloud fallback mode
|
|
377
|
+
### Telemetry
|
|
806
378
|
|
|
807
|
-
|
|
379
|
+
Cactus offers powerful telemetry for all your projects. Create a token on the [Cactus dashboard](https://www.cactuscompute.com/dashboard).
|
|
808
380
|
|
|
809
381
|
```typescript
|
|
810
|
-
|
|
811
|
-
role: 'system' | 'user' | 'assistant';
|
|
812
|
-
content: string;
|
|
813
|
-
}
|
|
382
|
+
import { CactusConfig } from 'cactus-react-native';
|
|
814
383
|
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
tokens_predicted: number;
|
|
818
|
-
tokens_evaluated: number;
|
|
819
|
-
timings: {
|
|
820
|
-
predicted_per_second: number;
|
|
821
|
-
prompt_per_second: number;
|
|
822
|
-
};
|
|
823
|
-
}
|
|
384
|
+
// Enable Telemetry for your project
|
|
385
|
+
CactusConfig.telemetryToken = 'your-token-here';
|
|
824
386
|
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
```
|
|
387
|
+
// Disable telemetry
|
|
388
|
+
CactusConfig.isTelemetryEnabled = false;
|
|
389
|
+
```
|