cactus-react-native 0.2.11 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cactus.podspec +34 -0
- package/LICENSE +38 -0
- package/README.md +354 -69
- package/android/CMakeLists.txt +40 -0
- package/android/build.gradle +68 -44
- package/android/gradle.properties +5 -5
- package/android/src/main/AndroidManifest.xml +1 -3
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/cactus/CactusPackage.kt +22 -0
- package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusCrypto.kt +38 -0
- package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusDeviceInfo.kt +24 -0
- package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusFileSystem.kt +227 -0
- package/android/src/main/jniLibs/arm64-v8a/{libcactus_v8_2_dotprod.so → libcactus.a} +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_util.so +0 -0
- package/cpp/HybridCactus.cpp +123 -0
- package/cpp/HybridCactus.hpp +35 -0
- package/cpp/HybridCactusUtil.cpp +45 -0
- package/cpp/HybridCactusUtil.hpp +26 -0
- package/cpp/cactus_ffi.h +55 -0
- package/cpp/cactus_util.h +25 -0
- package/ios/HybridCactusCrypto.swift +37 -0
- package/ios/HybridCactusDeviceInfo.swift +32 -0
- package/ios/HybridCactusFileSystem.swift +234 -0
- package/ios/cactus.xcframework/{info.plist → Info.plist} +2 -37
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus.h +8 -229
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_ffi.h +28 -229
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/engine.h +347 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ffi_utils.h +286 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/graph.h +319 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel.h +254 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel_utils.h +343 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Info.plist +0 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/cactus +0 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus.h +11 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_ffi.h +55 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/engine.h +347 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/ffi_utils.h +286 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/graph.h +319 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel.h +254 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel_utils.h +343 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Info.plist +0 -0
- package/ios/cactus.xcframework/{tvos-arm64_x86_64-simulator → ios-arm64-simulator}/cactus.framework/_CodeSignature/CodeResources +1 -1
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/cactus +0 -0
- package/ios/cactus_util.xcframework/Info.plist +39 -0
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/cactus_util.h +25 -0
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/ios_utils.h +10 -0
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/logging.h +25 -0
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Info.plist +0 -0
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/cactus_util +0 -0
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/cactus_util.h +25 -0
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/ios_utils.h +10 -0
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/logging.h +25 -0
- package/ios/{cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework → cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework}/Info.plist +0 -0
- package/ios/{cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework → cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework}/_CodeSignature/CodeResources +36 -2
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/cactus_util +0 -0
- package/lib/module/api/Database.js +60 -0
- package/lib/module/api/Database.js.map +1 -0
- package/lib/module/classes/CactusLM.js +149 -0
- package/lib/module/classes/CactusLM.js.map +1 -0
- package/lib/module/config/CactusConfig.js +6 -0
- package/lib/module/config/CactusConfig.js.map +1 -0
- package/lib/module/constants/packageVersion.js +4 -0
- package/lib/module/constants/packageVersion.js.map +1 -0
- package/lib/module/hooks/useCactusLM.js +233 -0
- package/lib/module/hooks/useCactusLM.js.map +1 -0
- package/lib/module/index.js +9 -409
- package/lib/module/index.js.map +1 -1
- package/lib/module/native/Cactus.js +50 -0
- package/lib/module/native/Cactus.js.map +1 -0
- package/lib/module/native/CactusCrypto.js +10 -0
- package/lib/module/native/CactusCrypto.js.map +1 -0
- package/lib/module/native/CactusDeviceInfo.js +13 -0
- package/lib/module/native/CactusDeviceInfo.js.map +1 -0
- package/lib/module/native/CactusFileSystem.js +35 -0
- package/lib/module/native/CactusFileSystem.js.map +1 -0
- package/lib/module/native/CactusUtil.js +23 -0
- package/lib/module/native/CactusUtil.js.map +1 -0
- package/lib/module/native/index.js +8 -0
- package/lib/module/native/index.js.map +1 -0
- package/lib/module/specs/Cactus.nitro.js +4 -0
- package/lib/module/specs/Cactus.nitro.js.map +1 -0
- package/lib/module/specs/CactusCrypto.nitro.js +4 -0
- package/lib/module/specs/CactusCrypto.nitro.js.map +1 -0
- package/lib/module/specs/CactusDeviceInfo.nitro.js +4 -0
- package/lib/module/specs/CactusDeviceInfo.nitro.js.map +1 -0
- package/lib/module/specs/CactusFileSystem.nitro.js +4 -0
- package/lib/module/specs/CactusFileSystem.nitro.js.map +1 -0
- package/lib/module/specs/CactusUtil.nitro.js +4 -0
- package/lib/module/specs/CactusUtil.nitro.js.map +1 -0
- package/lib/module/telemetry/Telemetry.js +100 -0
- package/lib/module/telemetry/Telemetry.js.map +1 -0
- package/lib/module/types/CactusLM.js +2 -0
- package/lib/module/types/CactusLM.js.map +1 -0
- package/lib/module/types/CactusModel.js +2 -0
- package/lib/module/types/CactusModel.js.map +1 -0
- package/lib/module/utils/error.js +4 -0
- package/lib/module/utils/error.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/api/Database.d.ts +11 -0
- package/lib/typescript/src/api/Database.d.ts.map +1 -0
- package/lib/typescript/src/classes/CactusLM.d.ts +25 -0
- package/lib/typescript/src/classes/CactusLM.d.ts.map +1 -0
- package/lib/typescript/src/config/CactusConfig.d.ts +5 -0
- package/lib/typescript/src/config/CactusConfig.d.ts.map +1 -0
- package/lib/typescript/src/constants/packageVersion.d.ts +2 -0
- package/lib/typescript/src/constants/packageVersion.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useCactusLM.d.ts +20 -0
- package/lib/typescript/src/hooks/useCactusLM.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +6 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/native/Cactus.d.ts +11 -0
- package/lib/typescript/src/native/Cactus.d.ts.map +1 -0
- package/lib/typescript/src/native/CactusCrypto.d.ts +5 -0
- package/lib/typescript/src/native/CactusCrypto.d.ts.map +1 -0
- package/lib/typescript/src/native/CactusDeviceInfo.d.ts +7 -0
- package/lib/typescript/src/native/CactusDeviceInfo.d.ts.map +1 -0
- package/lib/typescript/src/native/CactusFileSystem.d.ts +13 -0
- package/lib/typescript/src/native/CactusFileSystem.d.ts.map +1 -0
- package/lib/typescript/src/native/CactusUtil.d.ts +6 -0
- package/lib/typescript/src/native/CactusUtil.d.ts.map +1 -0
- package/lib/typescript/src/native/index.d.ts +6 -0
- package/lib/typescript/src/native/index.d.ts.map +1 -0
- package/lib/typescript/src/specs/Cactus.nitro.d.ts +13 -0
- package/lib/typescript/src/specs/Cactus.nitro.d.ts.map +1 -0
- package/lib/typescript/src/specs/CactusCrypto.nitro.d.ts +8 -0
- package/lib/typescript/src/specs/CactusCrypto.nitro.d.ts.map +1 -0
- package/lib/typescript/src/specs/CactusDeviceInfo.nitro.d.ts +16 -0
- package/lib/typescript/src/specs/CactusDeviceInfo.nitro.d.ts.map +1 -0
- package/lib/typescript/src/specs/CactusFileSystem.nitro.d.ts +16 -0
- package/lib/typescript/src/specs/CactusFileSystem.nitro.d.ts.map +1 -0
- package/lib/typescript/src/specs/CactusUtil.nitro.d.ts +10 -0
- package/lib/typescript/src/specs/CactusUtil.nitro.d.ts.map +1 -0
- package/lib/typescript/src/telemetry/Telemetry.d.ts +30 -0
- package/lib/typescript/src/telemetry/Telemetry.d.ts.map +1 -0
- package/lib/typescript/src/types/CactusLM.d.ts +65 -0
- package/lib/typescript/src/types/CactusLM.d.ts.map +1 -0
- package/lib/typescript/src/types/CactusModel.d.ts +12 -0
- package/lib/typescript/src/types/CactusModel.d.ts.map +1 -0
- package/lib/typescript/src/utils/error.d.ts +2 -0
- package/lib/typescript/src/utils/error.d.ts.map +1 -0
- package/nitro.json +31 -0
- package/nitrogen/generated/android/c++/JDeviceInfo.hpp +74 -0
- package/nitrogen/generated/android/c++/JFunc_void_double.hpp +74 -0
- package/nitrogen/generated/android/c++/JHybridCactusCryptoSpec.cpp +65 -0
- package/nitrogen/generated/android/c++/JHybridCactusCryptoSpec.hpp +65 -0
- package/nitrogen/generated/android/c++/JHybridCactusDeviceInfoSpec.cpp +85 -0
- package/nitrogen/generated/android/c++/JHybridCactusDeviceInfoSpec.hpp +66 -0
- package/nitrogen/generated/android/c++/JHybridCactusFileSystemSpec.cpp +192 -0
- package/nitrogen/generated/android/c++/JHybridCactusFileSystemSpec.hpp +73 -0
- package/nitrogen/generated/android/cactus+autolinking.cmake +87 -0
- package/nitrogen/generated/android/cactus+autolinking.gradle +27 -0
- package/nitrogen/generated/android/cactusOnLoad.cpp +86 -0
- package/nitrogen/generated/android/cactusOnLoad.hpp +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/DeviceInfo.kt +50 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/Func_void_double.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusCryptoSpec.kt +58 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusDeviceInfoSpec.kt +62 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusFileSystemSpec.kt +95 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/cactusOnLoad.kt +35 -0
- package/nitrogen/generated/ios/Cactus+autolinking.rb +60 -0
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.cpp +122 -0
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.hpp +373 -0
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Umbrella.hpp +60 -0
- package/nitrogen/generated/ios/CactusAutolinking.mm +69 -0
- package/nitrogen/generated/ios/CactusAutolinking.swift +55 -0
- package/nitrogen/generated/ios/c++/HybridCactusCryptoSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridCactusCryptoSpecSwift.hpp +77 -0
- package/nitrogen/generated/ios/c++/HybridCactusDeviceInfoSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridCactusDeviceInfoSpecSwift.hpp +88 -0
- package/nitrogen/generated/ios/c++/HybridCactusFileSystemSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridCactusFileSystemSpecSwift.hpp +143 -0
- package/nitrogen/generated/ios/swift/DeviceInfo.swift +98 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_DeviceInfo.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_double.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__optional_std__string_.swift +54 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +47 -0
- package/nitrogen/generated/ios/swift/HybridCactusCryptoSpec.swift +57 -0
- package/nitrogen/generated/ios/swift/HybridCactusCryptoSpec_cxx.swift +139 -0
- package/nitrogen/generated/ios/swift/HybridCactusDeviceInfoSpec.swift +58 -0
- package/nitrogen/generated/ios/swift/HybridCactusDeviceInfoSpec_cxx.swift +164 -0
- package/nitrogen/generated/ios/swift/HybridCactusFileSystemSpec.swift +65 -0
- package/nitrogen/generated/ios/swift/HybridCactusFileSystemSpec_cxx.swift +303 -0
- package/nitrogen/generated/shared/c++/DeviceInfo.hpp +92 -0
- package/nitrogen/generated/shared/c++/HybridCactusCryptoSpec.cpp +21 -0
- package/nitrogen/generated/shared/c++/HybridCactusCryptoSpec.hpp +63 -0
- package/nitrogen/generated/shared/c++/HybridCactusDeviceInfoSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridCactusDeviceInfoSpec.hpp +67 -0
- package/nitrogen/generated/shared/c++/HybridCactusFileSystemSpec.cpp +29 -0
- package/nitrogen/generated/shared/c++/HybridCactusFileSystemSpec.hpp +73 -0
- package/nitrogen/generated/shared/c++/HybridCactusSpec.cpp +26 -0
- package/nitrogen/generated/shared/c++/HybridCactusSpec.hpp +71 -0
- package/nitrogen/generated/shared/c++/HybridCactusUtilSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridCactusUtilSpec.hpp +66 -0
- package/package.json +84 -143
- package/src/api/Database.ts +83 -0
- package/src/classes/CactusLM.ts +203 -0
- package/src/config/CactusConfig.ts +4 -0
- package/src/constants/packageVersion.ts +1 -0
- package/src/hooks/useCactusLM.ts +282 -0
- package/src/index.tsx +23 -0
- package/src/native/Cactus.ts +79 -0
- package/src/native/CactusCrypto.ts +11 -0
- package/src/native/CactusDeviceInfo.ts +18 -0
- package/src/native/CactusFileSystem.ts +47 -0
- package/src/native/CactusUtil.ts +27 -0
- package/src/native/index.ts +5 -0
- package/src/specs/Cactus.nitro.ts +16 -0
- package/src/specs/CactusCrypto.nitro.ts +6 -0
- package/src/specs/CactusDeviceInfo.nitro.ts +15 -0
- package/src/specs/CactusFileSystem.nitro.ts +21 -0
- package/src/specs/CactusUtil.nitro.ts +8 -0
- package/src/telemetry/Telemetry.ts +159 -0
- package/src/types/CactusLM.ts +71 -0
- package/src/types/CactusModel.ts +14 -0
- package/src/utils/error.ts +2 -0
- package/LICENSE.txt +0 -20
- package/android/src/main/CMakeLists.txt +0 -140
- package/android/src/main/java/com/cactus/Cactus.java +0 -1190
- package/android/src/main/java/com/cactus/CactusPackage.java +0 -48
- package/android/src/main/java/com/cactus/LlamaContext.java +0 -748
- package/android/src/main/jni-utils.h +0 -100
- package/android/src/main/jni.cpp +0 -1605
- package/android/src/main/jniLibs/arm64-v8a/libcactus.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_v8.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2_dotprod_i8mm.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2_i8mm.so +0 -0
- package/android/src/newarch/java/com/cactus/CactusModule.java +0 -204
- package/android/src/oldarch/java/com/cactus/CactusModule.java +0 -205
- package/cactus-react-native.podspec +0 -42
- package/ios/CMakeLists.txt +0 -131
- package/ios/Cactus.h +0 -6
- package/ios/Cactus.mm +0 -681
- package/ios/CactusContext.h +0 -81
- package/ios/CactusContext.mm +0 -1032
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/chat.h +0 -145
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/common.h +0 -674
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-alloc.h +0 -76
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-backend-impl.h +0 -255
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-backend.h +0 -354
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-common.h +0 -1857
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpp.h +0 -39
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpu.h +0 -143
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-impl.h +0 -601
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-metal-impl.h +0 -622
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-metal.h +0 -66
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-opt.h +0 -237
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-quants.h +0 -100
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-threading.h +0 -14
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml.h +0 -2202
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/gguf.h +0 -202
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/json-schema-to-grammar.h +0 -21
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/json.hpp +0 -24766
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-adapter.h +0 -76
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-arch.h +0 -437
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-batch.h +0 -89
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-chat.h +0 -58
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-context.h +0 -276
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-cparams.h +0 -39
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-cpp.h +0 -30
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-grammar.h +0 -173
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-graph.h +0 -640
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-hparams.h +0 -190
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-impl.h +0 -61
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-io.h +0 -35
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-kv-cache.h +0 -515
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-memory.h +0 -32
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-mmap.h +0 -68
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-model-loader.h +0 -169
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-model-saver.h +0 -37
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-model.h +0 -425
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-sampling.h +0 -32
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-vocab.h +0 -131
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama.h +0 -1376
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/log.h +0 -103
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/minja/chat-template.hpp +0 -542
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/minja/minja.hpp +0 -2974
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/sampling.h +0 -107
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/unicode-data.h +0 -20
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/unicode.h +0 -66
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/ggml-llama.metallib +0 -0
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/cactus.h +0 -232
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/cactus_ffi.h +0 -256
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/chat.h +0 -145
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/common.h +0 -674
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-alloc.h +0 -76
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-backend-impl.h +0 -255
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-backend.h +0 -354
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-common.h +0 -1857
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpp.h +0 -39
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu.h +0 -143
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-impl.h +0 -601
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-metal-impl.h +0 -622
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-metal.h +0 -66
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-opt.h +0 -237
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-quants.h +0 -100
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-threading.h +0 -14
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml.h +0 -2202
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/gguf.h +0 -202
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/json-schema-to-grammar.h +0 -21
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/json.hpp +0 -24766
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-adapter.h +0 -76
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-arch.h +0 -437
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-batch.h +0 -89
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-chat.h +0 -58
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-context.h +0 -276
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-cparams.h +0 -39
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-cpp.h +0 -30
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-grammar.h +0 -173
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-graph.h +0 -640
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-hparams.h +0 -190
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-impl.h +0 -61
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-io.h +0 -35
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-kv-cache.h +0 -515
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-memory.h +0 -32
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-mmap.h +0 -68
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-model-loader.h +0 -169
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-model-saver.h +0 -37
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-model.h +0 -425
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-sampling.h +0 -32
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-vocab.h +0 -131
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama.h +0 -1376
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/log.h +0 -103
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/minja/chat-template.hpp +0 -542
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/minja/minja.hpp +0 -2974
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/sampling.h +0 -107
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/unicode-data.h +0 -20
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/unicode.h +0 -66
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/cactus +0 -0
- package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/ggml-llama-sim.metallib +0 -0
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/cactus.h +0 -232
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/cactus_ffi.h +0 -256
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/chat.h +0 -145
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/common.h +0 -674
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-alloc.h +0 -76
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-backend-impl.h +0 -255
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-backend.h +0 -354
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-common.h +0 -1857
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpp.h +0 -39
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpu.h +0 -143
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-impl.h +0 -601
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-metal-impl.h +0 -622
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-metal.h +0 -66
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-opt.h +0 -237
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-quants.h +0 -100
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-threading.h +0 -14
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml.h +0 -2202
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/gguf.h +0 -202
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/json-schema-to-grammar.h +0 -21
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/json.hpp +0 -24766
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-adapter.h +0 -76
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-arch.h +0 -437
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-batch.h +0 -89
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-chat.h +0 -58
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-context.h +0 -276
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-cparams.h +0 -39
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-cpp.h +0 -30
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-grammar.h +0 -173
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-graph.h +0 -640
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-hparams.h +0 -190
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-impl.h +0 -61
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-io.h +0 -35
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-kv-cache.h +0 -515
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-memory.h +0 -32
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-mmap.h +0 -68
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-model-loader.h +0 -169
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-model-saver.h +0 -37
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-model.h +0 -425
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-sampling.h +0 -32
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-vocab.h +0 -131
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama.h +0 -1376
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/log.h +0 -103
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/minja/chat-template.hpp +0 -542
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/minja/minja.hpp +0 -2974
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/sampling.h +0 -107
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/unicode-data.h +0 -20
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/unicode.h +0 -66
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Info.plist +0 -0
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/cactus +0 -0
- package/ios/cactus.xcframework/tvos-arm64/cactus.framework/ggml-llama.metallib +0 -0
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/cactus.h +0 -232
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/cactus_ffi.h +0 -256
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/chat.h +0 -145
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/common.h +0 -674
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-alloc.h +0 -76
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-backend-impl.h +0 -255
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-backend.h +0 -354
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-common.h +0 -1857
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpp.h +0 -39
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu.h +0 -143
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-impl.h +0 -601
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-metal-impl.h +0 -622
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-metal.h +0 -66
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-opt.h +0 -237
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-quants.h +0 -100
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-threading.h +0 -14
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml.h +0 -2202
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/gguf.h +0 -202
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/json-schema-to-grammar.h +0 -21
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/json.hpp +0 -24766
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-adapter.h +0 -76
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-arch.h +0 -437
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-batch.h +0 -89
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-chat.h +0 -58
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-context.h +0 -276
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-cparams.h +0 -39
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-cpp.h +0 -30
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-grammar.h +0 -173
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-graph.h +0 -640
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-hparams.h +0 -190
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-impl.h +0 -61
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-io.h +0 -35
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-kv-cache.h +0 -515
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-memory.h +0 -32
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-mmap.h +0 -68
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-model-loader.h +0 -169
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-model-saver.h +0 -37
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-model.h +0 -425
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-sampling.h +0 -32
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-vocab.h +0 -131
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama.h +0 -1376
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/log.h +0 -103
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/minja/chat-template.hpp +0 -542
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/minja/minja.hpp +0 -2974
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/sampling.h +0 -107
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/unicode-data.h +0 -20
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/unicode.h +0 -66
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Info.plist +0 -0
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/cactus +0 -0
- package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/ggml-llama-sim.metallib +0 -0
- package/lib/commonjs/NativeCactus.js +0 -9
- package/lib/commonjs/NativeCactus.js.map +0 -1
- package/lib/commonjs/agent.js +0 -73
- package/lib/commonjs/agent.js.map +0 -1
- package/lib/commonjs/chat.js +0 -73
- package/lib/commonjs/chat.js.map +0 -1
- package/lib/commonjs/index.js +0 -523
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/lm.js +0 -272
- package/lib/commonjs/lm.js.map +0 -1
- package/lib/commonjs/package.json +0 -1
- package/lib/commonjs/projectId.js +0 -9
- package/lib/commonjs/projectId.js.map +0 -1
- package/lib/commonjs/remote.js +0 -100
- package/lib/commonjs/remote.js.map +0 -1
- package/lib/commonjs/telemetry.js +0 -102
- package/lib/commonjs/telemetry.js.map +0 -1
- package/lib/commonjs/tools.js +0 -72
- package/lib/commonjs/tools.js.map +0 -1
- package/lib/commonjs/tts.js +0 -141
- package/lib/commonjs/tts.js.map +0 -1
- package/lib/commonjs/vlm.js +0 -221
- package/lib/commonjs/vlm.js.map +0 -1
- package/lib/module/NativeCactus.js +0 -5
- package/lib/module/NativeCactus.js.map +0 -1
- package/lib/module/agent.js +0 -68
- package/lib/module/agent.js.map +0 -1
- package/lib/module/chat.js +0 -67
- package/lib/module/chat.js.map +0 -1
- package/lib/module/lm.js +0 -267
- package/lib/module/lm.js.map +0 -1
- package/lib/module/projectId.js +0 -5
- package/lib/module/projectId.js.map +0 -1
- package/lib/module/remote.js +0 -91
- package/lib/module/remote.js.map +0 -1
- package/lib/module/telemetry.js +0 -97
- package/lib/module/telemetry.js.map +0 -1
- package/lib/module/tools.js +0 -66
- package/lib/module/tools.js.map +0 -1
- package/lib/module/tts.js +0 -135
- package/lib/module/tts.js.map +0 -1
- package/lib/module/vlm.js +0 -216
- package/lib/module/vlm.js.map +0 -1
- package/lib/typescript/NativeCactus.d.ts +0 -252
- package/lib/typescript/NativeCactus.d.ts.map +0 -1
- package/lib/typescript/agent.d.ts +0 -31
- package/lib/typescript/agent.d.ts.map +0 -1
- package/lib/typescript/chat.d.ts +0 -23
- package/lib/typescript/chat.d.ts.map +0 -1
- package/lib/typescript/index.d.ts +0 -114
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/lm.d.ts +0 -36
- package/lib/typescript/lm.d.ts.map +0 -1
- package/lib/typescript/projectId.d.ts +0 -2
- package/lib/typescript/projectId.d.ts.map +0 -1
- package/lib/typescript/remote.d.ts +0 -8
- package/lib/typescript/remote.d.ts.map +0 -1
- package/lib/typescript/telemetry.d.ts +0 -25
- package/lib/typescript/telemetry.d.ts.map +0 -1
- package/lib/typescript/tools.d.ts +0 -36
- package/lib/typescript/tools.d.ts.map +0 -1
- package/lib/typescript/tts.d.ts +0 -54
- package/lib/typescript/tts.d.ts.map +0 -1
- package/lib/typescript/vlm.d.ts +0 -33
- package/lib/typescript/vlm.d.ts.map +0 -1
- package/scripts/postInstall.js +0 -33
- package/src/NativeCactus.ts +0 -317
- package/src/agent.ts +0 -112
- package/src/chat.ts +0 -91
- package/src/index.ts +0 -663
- package/src/lm.ts +0 -324
- package/src/projectId.ts +0 -1
- package/src/remote.ts +0 -113
- package/src/telemetry.ts +0 -137
- package/src/tools.ts +0 -94
- package/src/tts.ts +0 -236
- package/src/vlm.ts +0 -276
package/src/index.ts
DELETED
|
@@ -1,663 +0,0 @@
|
|
|
1
|
-
import { NativeEventEmitter, DeviceEventEmitter, Platform } from 'react-native'
|
|
2
|
-
import type { DeviceEventEmitterStatic } from 'react-native'
|
|
3
|
-
import Cactus from './NativeCactus'
|
|
4
|
-
|
|
5
|
-
import type {
|
|
6
|
-
NativeContextParams,
|
|
7
|
-
NativeLlamaContext,
|
|
8
|
-
NativeCompletionParams,
|
|
9
|
-
NativeCompletionTokenProb,
|
|
10
|
-
NativeCompletionResult,
|
|
11
|
-
NativeTokenizeResult,
|
|
12
|
-
NativeEmbeddingResult,
|
|
13
|
-
NativeSessionLoadResult,
|
|
14
|
-
NativeEmbeddingParams,
|
|
15
|
-
NativeCompletionTokenProbItem,
|
|
16
|
-
NativeCompletionResultTimings,
|
|
17
|
-
JinjaFormattedChatResult,
|
|
18
|
-
NativeTTSType,
|
|
19
|
-
NativeAudioCompletionResult,
|
|
20
|
-
NativeAudioTokensResult,
|
|
21
|
-
NativeAudioDecodeResult,
|
|
22
|
-
NativeDeviceInfo,
|
|
23
|
-
} from './NativeCactus'
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
import type { CactusMessagePart, CactusOAICompatibleMessage } from './chat'
|
|
27
|
-
import { formatChat } from './chat'
|
|
28
|
-
import { Tools, parseAndExecuteTool } from './tools'
|
|
29
|
-
import { Telemetry, type TelemetryParams } from './telemetry'
|
|
30
|
-
export type {
|
|
31
|
-
NativeContextParams,
|
|
32
|
-
NativeLlamaContext,
|
|
33
|
-
NativeCompletionParams,
|
|
34
|
-
NativeCompletionTokenProb,
|
|
35
|
-
NativeCompletionResult,
|
|
36
|
-
NativeTokenizeResult,
|
|
37
|
-
NativeEmbeddingResult,
|
|
38
|
-
NativeSessionLoadResult,
|
|
39
|
-
NativeEmbeddingParams,
|
|
40
|
-
NativeCompletionTokenProbItem,
|
|
41
|
-
NativeCompletionResultTimings,
|
|
42
|
-
CactusMessagePart,
|
|
43
|
-
CactusOAICompatibleMessage,
|
|
44
|
-
JinjaFormattedChatResult,
|
|
45
|
-
NativeAudioDecodeResult,
|
|
46
|
-
NativeTTSType,
|
|
47
|
-
}
|
|
48
|
-
export * from './remote'
|
|
49
|
-
export {
|
|
50
|
-
Tools,
|
|
51
|
-
parseAndExecuteTool
|
|
52
|
-
} from './tools'
|
|
53
|
-
|
|
54
|
-
const EVENT_ON_INIT_CONTEXT_PROGRESS = '@Cactus_onInitContextProgress'
|
|
55
|
-
const EVENT_ON_TOKEN = '@Cactus_onToken'
|
|
56
|
-
const EVENT_ON_NATIVE_LOG = '@Cactus_onNativeLog'
|
|
57
|
-
|
|
58
|
-
let EventEmitter: NativeEventEmitter | DeviceEventEmitterStatic
|
|
59
|
-
if (Platform.OS === 'ios') {
|
|
60
|
-
// @ts-ignore
|
|
61
|
-
EventEmitter = new NativeEventEmitter(Cactus)
|
|
62
|
-
}
|
|
63
|
-
if (Platform.OS === 'android') {
|
|
64
|
-
EventEmitter = DeviceEventEmitter
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const logListeners: Array<(level: string, text: string) => void> = []
|
|
68
|
-
|
|
69
|
-
// @ts-ignore
|
|
70
|
-
if (EventEmitter) {
|
|
71
|
-
EventEmitter.addListener(
|
|
72
|
-
EVENT_ON_NATIVE_LOG,
|
|
73
|
-
(evt: { level: string; text: string }) => {
|
|
74
|
-
logListeners.forEach((listener) => listener(evt.level, evt.text))
|
|
75
|
-
},
|
|
76
|
-
)
|
|
77
|
-
Cactus?.toggleNativeLog?.(false)?.catch?.(() => {})
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export type TokenData = {
|
|
81
|
-
token: string
|
|
82
|
-
completion_probabilities?: Array<NativeCompletionTokenProb>
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
type TokenNativeEvent = {
|
|
86
|
-
contextId: number
|
|
87
|
-
tokenResult: TokenData
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export type ContextParams = Omit<
|
|
91
|
-
NativeContextParams,
|
|
92
|
-
'cache_type_k' | 'cache_type_v' | 'pooling_type'
|
|
93
|
-
> & {
|
|
94
|
-
cache_type_k?:
|
|
95
|
-
| 'f16'
|
|
96
|
-
| 'f32'
|
|
97
|
-
| 'q8_0'
|
|
98
|
-
| 'q4_0'
|
|
99
|
-
| 'q4_1'
|
|
100
|
-
| 'iq4_nl'
|
|
101
|
-
| 'q5_0'
|
|
102
|
-
| 'q5_1'
|
|
103
|
-
cache_type_v?:
|
|
104
|
-
| 'f16'
|
|
105
|
-
| 'f32'
|
|
106
|
-
| 'q8_0'
|
|
107
|
-
| 'q4_0'
|
|
108
|
-
| 'q4_1'
|
|
109
|
-
| 'iq4_nl'
|
|
110
|
-
| 'q5_0'
|
|
111
|
-
| 'q5_1'
|
|
112
|
-
pooling_type?: 'none' | 'mean' | 'cls' | 'last' | 'rank'
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export type EmbeddingParams = NativeEmbeddingParams
|
|
116
|
-
|
|
117
|
-
export type CompletionResponseFormat = {
|
|
118
|
-
type: 'text' | 'json_object' | 'json_schema'
|
|
119
|
-
json_schema?: {
|
|
120
|
-
strict?: boolean
|
|
121
|
-
schema: object
|
|
122
|
-
}
|
|
123
|
-
schema?: object // for json_object type
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export type CompletionBaseParams = {
|
|
127
|
-
prompt?: string
|
|
128
|
-
messages?: CactusOAICompatibleMessage[]
|
|
129
|
-
chatTemplate?: string // deprecated
|
|
130
|
-
chat_template?: string
|
|
131
|
-
jinja?: boolean
|
|
132
|
-
tools?: object
|
|
133
|
-
parallel_tool_calls?: object
|
|
134
|
-
tool_choice?: string
|
|
135
|
-
response_format?: CompletionResponseFormat
|
|
136
|
-
}
|
|
137
|
-
export type CompletionParams = Omit<
|
|
138
|
-
NativeCompletionParams,
|
|
139
|
-
'emit_partial_completion' | 'prompt'
|
|
140
|
-
> &
|
|
141
|
-
CompletionBaseParams
|
|
142
|
-
|
|
143
|
-
export type BenchResult = {
|
|
144
|
-
modelDesc: string
|
|
145
|
-
modelSize: number
|
|
146
|
-
modelNParams: number
|
|
147
|
-
ppAvg: number
|
|
148
|
-
ppStd: number
|
|
149
|
-
tgAvg: number
|
|
150
|
-
tgStd: number
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const getJsonSchema = (responseFormat?: CompletionResponseFormat) => {
|
|
154
|
-
if (responseFormat?.type === 'json_schema') {
|
|
155
|
-
return responseFormat.json_schema?.schema
|
|
156
|
-
}
|
|
157
|
-
if (responseFormat?.type === 'json_object') {
|
|
158
|
-
return responseFormat.schema || {}
|
|
159
|
-
}
|
|
160
|
-
return null
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const telemetryParams: TelemetryParams = {
|
|
164
|
-
n_gpu_layers: null,
|
|
165
|
-
n_ctx: null,
|
|
166
|
-
model: null
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export class LlamaContext {
|
|
170
|
-
id: number
|
|
171
|
-
|
|
172
|
-
gpu: boolean = false
|
|
173
|
-
|
|
174
|
-
reasonNoGPU: string = ''
|
|
175
|
-
|
|
176
|
-
model: NativeLlamaContext['model']
|
|
177
|
-
|
|
178
|
-
constructor({ contextId, gpu, reasonNoGPU, model }: NativeLlamaContext) {
|
|
179
|
-
this.id = contextId
|
|
180
|
-
this.gpu = gpu
|
|
181
|
-
this.reasonNoGPU = reasonNoGPU
|
|
182
|
-
this.model = model
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
async loadSession(filepath: string): Promise<NativeSessionLoadResult> {
|
|
186
|
-
let path = filepath
|
|
187
|
-
if (path.startsWith('file://')) path = path.slice(7)
|
|
188
|
-
return Cactus.loadSession(this.id, path)
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
async saveSession(
|
|
192
|
-
filepath: string,
|
|
193
|
-
options?: { tokenSize: number },
|
|
194
|
-
): Promise<number> {
|
|
195
|
-
return Cactus.saveSession(this.id, filepath, options?.tokenSize || -1)
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
isLlamaChatSupported(): boolean {
|
|
199
|
-
return !!this.model.chatTemplates.llamaChat
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
isJinjaSupported(): boolean {
|
|
203
|
-
const { minja } = this.model.chatTemplates
|
|
204
|
-
return !!minja?.toolUse || !!minja?.default
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
async getFormattedChat(
|
|
208
|
-
messages: CactusOAICompatibleMessage[],
|
|
209
|
-
template?: string | null,
|
|
210
|
-
params?: {
|
|
211
|
-
jinja?: boolean
|
|
212
|
-
response_format?: CompletionResponseFormat
|
|
213
|
-
tools?: object
|
|
214
|
-
parallel_tool_calls?: object
|
|
215
|
-
tool_choice?: string
|
|
216
|
-
},
|
|
217
|
-
): Promise<JinjaFormattedChatResult | string> {
|
|
218
|
-
const chat = formatChat(messages)
|
|
219
|
-
const useJinja = this.isJinjaSupported() && params?.jinja
|
|
220
|
-
let tmpl = this.isLlamaChatSupported() || useJinja ? undefined : 'chatml'
|
|
221
|
-
if (template) tmpl = template // Force replace if provided
|
|
222
|
-
const jsonSchema = getJsonSchema(params?.response_format)
|
|
223
|
-
return Cactus.getFormattedChat(this.id, JSON.stringify(chat), tmpl, {
|
|
224
|
-
jinja: useJinja,
|
|
225
|
-
json_schema: jsonSchema ? JSON.stringify(jsonSchema) : undefined,
|
|
226
|
-
tools: params?.tools ? JSON.stringify(params.tools) : undefined,
|
|
227
|
-
parallel_tool_calls: params?.parallel_tool_calls
|
|
228
|
-
? JSON.stringify(params.parallel_tool_calls)
|
|
229
|
-
: undefined,
|
|
230
|
-
tool_choice: params?.tool_choice,
|
|
231
|
-
})
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
async completionWithTools(
|
|
235
|
-
params: CompletionParams & {tools: Tools},
|
|
236
|
-
callback?: (data: TokenData) => void,
|
|
237
|
-
recursionCount: number = 0,
|
|
238
|
-
recursionLimit: number = 3
|
|
239
|
-
): Promise<NativeCompletionResult> {
|
|
240
|
-
if (!params.messages) {
|
|
241
|
-
return this.completion(params, callback);
|
|
242
|
-
}
|
|
243
|
-
if (!params.tools) {
|
|
244
|
-
return this.completion(params, callback);
|
|
245
|
-
}
|
|
246
|
-
if (recursionCount >= recursionLimit) {
|
|
247
|
-
return this.completion({
|
|
248
|
-
...params,
|
|
249
|
-
jinja: true,
|
|
250
|
-
tools: params.tools.getSchemas()
|
|
251
|
-
}, callback);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const messages = [...params.messages];
|
|
255
|
-
|
|
256
|
-
const result = await this.completion({
|
|
257
|
-
...params,
|
|
258
|
-
messages: messages,
|
|
259
|
-
jinja: true,
|
|
260
|
-
tools: params.tools.getSchemas()
|
|
261
|
-
}, callback);
|
|
262
|
-
|
|
263
|
-
const {toolCalled, toolName, toolInput, toolOutput} =
|
|
264
|
-
await parseAndExecuteTool(result, params.tools);
|
|
265
|
-
|
|
266
|
-
if (toolCalled && toolName && toolInput) {
|
|
267
|
-
const assistantMessage = {
|
|
268
|
-
role: 'assistant',
|
|
269
|
-
content: result.content,
|
|
270
|
-
tool_calls: result.tool_calls
|
|
271
|
-
} as CactusOAICompatibleMessage;
|
|
272
|
-
|
|
273
|
-
messages.push(assistantMessage);
|
|
274
|
-
|
|
275
|
-
const toolCallId = result.tool_calls?.[0]?.id;
|
|
276
|
-
const toolMessage = {
|
|
277
|
-
role: 'tool',
|
|
278
|
-
content: JSON.stringify(toolOutput),
|
|
279
|
-
tool_call_id: toolCallId
|
|
280
|
-
} as CactusOAICompatibleMessage;
|
|
281
|
-
|
|
282
|
-
messages.push(toolMessage);
|
|
283
|
-
|
|
284
|
-
return await this.completionWithTools(
|
|
285
|
-
{...params, messages: messages},
|
|
286
|
-
callback,
|
|
287
|
-
recursionCount + 1,
|
|
288
|
-
recursionLimit
|
|
289
|
-
);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
return result;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
async completion(
|
|
296
|
-
params: CompletionParams,
|
|
297
|
-
callback?: (data: TokenData) => void,
|
|
298
|
-
): Promise<NativeCompletionResult> {
|
|
299
|
-
const nativeParams = {
|
|
300
|
-
...params,
|
|
301
|
-
prompt: params.prompt || '',
|
|
302
|
-
emit_partial_completion: !!callback,
|
|
303
|
-
}
|
|
304
|
-
if (params.messages) {
|
|
305
|
-
|
|
306
|
-
const formattedResult = await this.getFormattedChat(
|
|
307
|
-
params.messages,
|
|
308
|
-
params.chat_template || params.chatTemplate,
|
|
309
|
-
{
|
|
310
|
-
jinja: params.jinja,
|
|
311
|
-
tools: params.tools,
|
|
312
|
-
parallel_tool_calls: params.parallel_tool_calls,
|
|
313
|
-
tool_choice: params.tool_choice,
|
|
314
|
-
},
|
|
315
|
-
)
|
|
316
|
-
if (typeof formattedResult === 'string') {
|
|
317
|
-
nativeParams.prompt = formattedResult || ''
|
|
318
|
-
} else {
|
|
319
|
-
nativeParams.prompt = formattedResult.prompt || ''
|
|
320
|
-
if (typeof formattedResult.chat_format === 'number')
|
|
321
|
-
nativeParams.chat_format = formattedResult.chat_format
|
|
322
|
-
if (formattedResult.grammar)
|
|
323
|
-
nativeParams.grammar = formattedResult.grammar
|
|
324
|
-
if (typeof formattedResult.grammar_lazy === 'boolean')
|
|
325
|
-
nativeParams.grammar_lazy = formattedResult.grammar_lazy
|
|
326
|
-
if (formattedResult.grammar_triggers)
|
|
327
|
-
nativeParams.grammar_triggers = formattedResult.grammar_triggers
|
|
328
|
-
if (formattedResult.preserved_tokens)
|
|
329
|
-
nativeParams.preserved_tokens = formattedResult.preserved_tokens
|
|
330
|
-
if (formattedResult.additional_stops) {
|
|
331
|
-
if (!nativeParams.stop) nativeParams.stop = []
|
|
332
|
-
nativeParams.stop.push(...formattedResult.additional_stops)
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
} else {
|
|
336
|
-
nativeParams.prompt = params.prompt || ''
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
if (nativeParams.response_format && !nativeParams.grammar) {
|
|
340
|
-
const jsonSchema = getJsonSchema(params.response_format)
|
|
341
|
-
if (jsonSchema) nativeParams.json_schema = JSON.stringify(jsonSchema)
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
const startTime = Date.now();
|
|
345
|
-
let firstTokenTime: number | null = null;
|
|
346
|
-
const deviceInfo = await getDeviceInfo(this.id);
|
|
347
|
-
|
|
348
|
-
const wrappedCallback = callback ? (data: any) => {
|
|
349
|
-
if (firstTokenTime === null) firstTokenTime = Date.now();
|
|
350
|
-
callback(data);
|
|
351
|
-
} : undefined;
|
|
352
|
-
|
|
353
|
-
let tokenListener: any =
|
|
354
|
-
wrappedCallback &&
|
|
355
|
-
EventEmitter.addListener(EVENT_ON_TOKEN, (evt: TokenNativeEvent) => {
|
|
356
|
-
const { contextId, tokenResult } = evt
|
|
357
|
-
if (contextId !== this.id) return
|
|
358
|
-
wrappedCallback(tokenResult)
|
|
359
|
-
})
|
|
360
|
-
|
|
361
|
-
if (!nativeParams.prompt) throw new Error('Prompt is required')
|
|
362
|
-
|
|
363
|
-
const promise = Cactus.completion(this.id, nativeParams)
|
|
364
|
-
return promise
|
|
365
|
-
.then((completionResult) => {
|
|
366
|
-
Telemetry.track({
|
|
367
|
-
event: 'completion',
|
|
368
|
-
tok_per_sec: (completionResult as any).timings?.predicted_per_second,
|
|
369
|
-
toks_generated: (completionResult as any).timings?.predicted_n,
|
|
370
|
-
ttft: firstTokenTime ? firstTokenTime - startTime : null,
|
|
371
|
-
}, telemetryParams, deviceInfo);
|
|
372
|
-
tokenListener?.remove()
|
|
373
|
-
tokenListener = null
|
|
374
|
-
return completionResult
|
|
375
|
-
})
|
|
376
|
-
.catch((err: any) => {
|
|
377
|
-
tokenListener?.remove()
|
|
378
|
-
tokenListener = null
|
|
379
|
-
throw err
|
|
380
|
-
})
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
stopCompletion(): Promise<void> {
|
|
384
|
-
return Cactus.stopCompletion(this.id)
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
tokenize(text: string): Promise<NativeTokenizeResult> {
|
|
388
|
-
return Cactus.tokenize(this.id, text)
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
detokenize(tokens: number[]): Promise<string> {
|
|
392
|
-
return Cactus.detokenize(this.id, tokens)
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
async embedding(
|
|
396
|
-
text: string,
|
|
397
|
-
params?: EmbeddingParams,
|
|
398
|
-
): Promise<NativeEmbeddingResult> {
|
|
399
|
-
const startTime = Date.now();
|
|
400
|
-
const embeddingResult = await Cactus.embedding(this.id, text, params || {})
|
|
401
|
-
const totalTime = Date.now() - startTime;
|
|
402
|
-
const deviceInfo = await getDeviceInfo(this.id);
|
|
403
|
-
Telemetry.track({
|
|
404
|
-
event: 'embedding',
|
|
405
|
-
mode: 'local',
|
|
406
|
-
embedding_time: totalTime,
|
|
407
|
-
}, telemetryParams, deviceInfo);
|
|
408
|
-
return embeddingResult;
|
|
409
|
-
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
async bench(
|
|
413
|
-
pp: number,
|
|
414
|
-
tg: number,
|
|
415
|
-
pl: number,
|
|
416
|
-
nr: number,
|
|
417
|
-
): Promise<BenchResult> {
|
|
418
|
-
const result = await Cactus.bench(this.id, pp, tg, pl, nr)
|
|
419
|
-
const [modelDesc, modelSize, modelNParams, ppAvg, ppStd, tgAvg, tgStd] =
|
|
420
|
-
JSON.parse(result)
|
|
421
|
-
return {
|
|
422
|
-
modelDesc,
|
|
423
|
-
modelSize,
|
|
424
|
-
modelNParams,
|
|
425
|
-
ppAvg,
|
|
426
|
-
ppStd,
|
|
427
|
-
tgAvg,
|
|
428
|
-
tgStd,
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
async applyLoraAdapters(
|
|
433
|
-
loraList: Array<{ path: string; scaled?: number }>,
|
|
434
|
-
): Promise<void> {
|
|
435
|
-
let loraAdapters: Array<{ path: string; scaled?: number }> = []
|
|
436
|
-
if (loraList)
|
|
437
|
-
loraAdapters = loraList.map((l) => ({
|
|
438
|
-
path: l.path.replace(/file:\/\//, ''),
|
|
439
|
-
scaled: l.scaled,
|
|
440
|
-
}))
|
|
441
|
-
return Cactus.applyLoraAdapters(this.id, loraAdapters)
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
async removeLoraAdapters(): Promise<void> {
|
|
445
|
-
return Cactus.removeLoraAdapters(this.id)
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
async getLoadedLoraAdapters(): Promise<
|
|
449
|
-
Array<{ path: string; scaled?: number }>
|
|
450
|
-
> {
|
|
451
|
-
return Cactus.getLoadedLoraAdapters(this.id)
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
async release(): Promise<void> {
|
|
455
|
-
return Cactus.releaseContext(this.id)
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
async rewind(): Promise<void> {
|
|
459
|
-
return Cactus.rewind(this.id)
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
export async function toggleNativeLog(enabled: boolean): Promise<void> {
|
|
464
|
-
return Cactus.toggleNativeLog(enabled)
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
export function addNativeLogListener(
|
|
468
|
-
listener: (level: string, text: string) => void,
|
|
469
|
-
): { remove: () => void } {
|
|
470
|
-
logListeners.push(listener)
|
|
471
|
-
return {
|
|
472
|
-
remove: () => {
|
|
473
|
-
logListeners.splice(logListeners.indexOf(listener), 1)
|
|
474
|
-
},
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
export async function setContextLimit(limit: number): Promise<void> {
|
|
479
|
-
return Cactus.setContextLimit(limit)
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
let contextIdCounter = 0
|
|
483
|
-
const contextIdRandom = () =>
|
|
484
|
-
process.env.NODE_ENV === 'test' ? 0 : Math.floor(Math.random() * 100000)
|
|
485
|
-
|
|
486
|
-
const modelInfoSkip = [
|
|
487
|
-
// Large fields
|
|
488
|
-
'tokenizer.ggml.tokens',
|
|
489
|
-
'tokenizer.ggml.token_type',
|
|
490
|
-
'tokenizer.ggml.merges',
|
|
491
|
-
'tokenizer.ggml.scores'
|
|
492
|
-
]
|
|
493
|
-
export async function loadLlamaModelInfo(model: string): Promise<Object> {
|
|
494
|
-
let path = model
|
|
495
|
-
if (path.startsWith('file://')) path = path.slice(7)
|
|
496
|
-
return Cactus.modelInfo(path, modelInfoSkip)
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
const poolTypeMap = {
|
|
500
|
-
none: 0,
|
|
501
|
-
mean: 1,
|
|
502
|
-
cls: 2,
|
|
503
|
-
last: 3,
|
|
504
|
-
rank: 4,
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
export async function initLlama(
|
|
508
|
-
{
|
|
509
|
-
model,
|
|
510
|
-
is_model_asset: isModelAsset,
|
|
511
|
-
pooling_type: poolingType,
|
|
512
|
-
lora,
|
|
513
|
-
lora_list: loraList,
|
|
514
|
-
...rest
|
|
515
|
-
}: ContextParams,
|
|
516
|
-
onProgress?: (progress: number) => void,
|
|
517
|
-
): Promise<LlamaContext> {
|
|
518
|
-
let path = model
|
|
519
|
-
if (path.startsWith('file://')) path = path.slice(7)
|
|
520
|
-
|
|
521
|
-
let loraPath = lora
|
|
522
|
-
if (loraPath?.startsWith('file://')) loraPath = loraPath.slice(7)
|
|
523
|
-
|
|
524
|
-
let loraAdapters: Array<{ path: string; scaled?: number }> = []
|
|
525
|
-
if (loraList)
|
|
526
|
-
loraAdapters = loraList.map((l) => ({
|
|
527
|
-
path: l.path.replace(/file:\/\//, ''),
|
|
528
|
-
scaled: l.scaled,
|
|
529
|
-
}))
|
|
530
|
-
|
|
531
|
-
telemetryParams.n_gpu_layers = rest.n_gpu_layers || null;
|
|
532
|
-
telemetryParams.n_ctx = rest.n_ctx || null;
|
|
533
|
-
telemetryParams.model = model;
|
|
534
|
-
|
|
535
|
-
const contextId = contextIdCounter + contextIdRandom()
|
|
536
|
-
contextIdCounter += 1
|
|
537
|
-
|
|
538
|
-
let removeProgressListener: any = null
|
|
539
|
-
if (onProgress) {
|
|
540
|
-
removeProgressListener = EventEmitter.addListener(
|
|
541
|
-
EVENT_ON_INIT_CONTEXT_PROGRESS,
|
|
542
|
-
(evt: { contextId: number; progress: number }) => {
|
|
543
|
-
if (evt.contextId !== contextId) return
|
|
544
|
-
onProgress(evt.progress)
|
|
545
|
-
},
|
|
546
|
-
)
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
const poolType = poolTypeMap[poolingType as keyof typeof poolTypeMap]
|
|
550
|
-
const {
|
|
551
|
-
gpu,
|
|
552
|
-
reasonNoGPU,
|
|
553
|
-
model: modelDetails,
|
|
554
|
-
androidLib,
|
|
555
|
-
} = await Cactus.initContext(contextId, {
|
|
556
|
-
model: path,
|
|
557
|
-
is_model_asset: !!isModelAsset,
|
|
558
|
-
use_progress_callback: !!onProgress,
|
|
559
|
-
pooling_type: poolType,
|
|
560
|
-
lora: loraPath,
|
|
561
|
-
lora_list: loraAdapters,
|
|
562
|
-
...rest,
|
|
563
|
-
}).catch((err: any) => {
|
|
564
|
-
removeProgressListener?.remove()
|
|
565
|
-
throw err
|
|
566
|
-
})
|
|
567
|
-
removeProgressListener?.remove()
|
|
568
|
-
return new LlamaContext({
|
|
569
|
-
contextId,
|
|
570
|
-
gpu,
|
|
571
|
-
reasonNoGPU,
|
|
572
|
-
model: modelDetails,
|
|
573
|
-
androidLib,
|
|
574
|
-
})
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
export async function releaseAllLlama(): Promise<void> {
|
|
578
|
-
return Cactus.releaseAllContexts()
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
export const initContext = async (params: NativeContextParams) => {
|
|
582
|
-
return await Cactus.initContext(contextIdCounter++, params);
|
|
583
|
-
};
|
|
584
|
-
|
|
585
|
-
export const initMultimodal = async (contextId: number, mmprojPath: string, useGpu: boolean = false) => {
|
|
586
|
-
return await Cactus.initMultimodal(contextId, mmprojPath, useGpu);
|
|
587
|
-
};
|
|
588
|
-
|
|
589
|
-
export const isMultimodalEnabled = async (contextId: number) => {
|
|
590
|
-
return await Cactus.isMultimodalEnabled(contextId);
|
|
591
|
-
};
|
|
592
|
-
|
|
593
|
-
export const isMultimodalSupportVision = async (contextId: number) => {
|
|
594
|
-
return await Cactus.isMultimodalSupportVision(contextId);
|
|
595
|
-
};
|
|
596
|
-
|
|
597
|
-
export const isMultimodalSupportAudio = async (contextId: number) => {
|
|
598
|
-
return await Cactus.isMultimodalSupportAudio(contextId);
|
|
599
|
-
};
|
|
600
|
-
|
|
601
|
-
export const releaseMultimodal = async (contextId: number) => {
|
|
602
|
-
return await Cactus.releaseMultimodal(contextId);
|
|
603
|
-
};
|
|
604
|
-
|
|
605
|
-
export const multimodalCompletion = async (contextId: number, prompt: string, mediaPaths: string[], params: NativeCompletionParams): Promise<NativeCompletionResult> => {
|
|
606
|
-
const result = await Cactus.multimodalCompletion(contextId, prompt, mediaPaths, params);
|
|
607
|
-
|
|
608
|
-
const deviceInfo = await getDeviceInfo(contextId);
|
|
609
|
-
|
|
610
|
-
Telemetry.track({
|
|
611
|
-
event: 'completion',
|
|
612
|
-
tok_per_sec: (result as any).timings?.predicted_per_second,
|
|
613
|
-
toks_generated: (result as any).timings?.predicted_n,
|
|
614
|
-
num_images: mediaPaths?.length,
|
|
615
|
-
}, telemetryParams, deviceInfo);
|
|
616
|
-
|
|
617
|
-
return result;
|
|
618
|
-
};
|
|
619
|
-
|
|
620
|
-
export const initVocoder = async (contextId: number, vocoderModelPath: string) => {
|
|
621
|
-
return await Cactus.initVocoder(contextId, vocoderModelPath);
|
|
622
|
-
};
|
|
623
|
-
|
|
624
|
-
export const isVocoderEnabled = async (contextId: number) => {
|
|
625
|
-
return await Cactus.isVocoderEnabled(contextId);
|
|
626
|
-
};
|
|
627
|
-
|
|
628
|
-
export const getTTSType = async (contextId: number): Promise<NativeTTSType> => {
|
|
629
|
-
return await Cactus.getTTSType(contextId);
|
|
630
|
-
};
|
|
631
|
-
|
|
632
|
-
export const getFormattedAudioCompletion = async (contextId: number, speakerJsonStr: string, textToSpeak: string): Promise<NativeAudioCompletionResult> => {
|
|
633
|
-
return await Cactus.getFormattedAudioCompletion(contextId, speakerJsonStr, textToSpeak);
|
|
634
|
-
};
|
|
635
|
-
|
|
636
|
-
export const getAudioCompletionGuideTokens = async (contextId: number, textToSpeak: string): Promise<NativeAudioTokensResult> => {
|
|
637
|
-
return await Cactus.getAudioCompletionGuideTokens(contextId, textToSpeak);
|
|
638
|
-
};
|
|
639
|
-
|
|
640
|
-
export const decodeAudioTokens = async (contextId: number, tokens: number[]): Promise<NativeAudioDecodeResult> => {
|
|
641
|
-
return await Cactus.decodeAudioTokens(contextId, tokens);
|
|
642
|
-
};
|
|
643
|
-
|
|
644
|
-
export const releaseVocoder = async (contextId: number) => {
|
|
645
|
-
return await Cactus.releaseVocoder(contextId);
|
|
646
|
-
};
|
|
647
|
-
|
|
648
|
-
export const tokenize = async (contextId: number, text: string, mediaPaths?: string[]): Promise<NativeTokenizeResult> => {
|
|
649
|
-
if (mediaPaths && mediaPaths.length > 0) {
|
|
650
|
-
return await Cactus.tokenize(contextId, text, mediaPaths);
|
|
651
|
-
} else {
|
|
652
|
-
return await Cactus.tokenize(contextId, text);
|
|
653
|
-
}
|
|
654
|
-
};
|
|
655
|
-
|
|
656
|
-
export const getDeviceInfo = async (contextId: number): Promise<NativeDeviceInfo> => {
|
|
657
|
-
return await Cactus.getDeviceInfo(contextId);
|
|
658
|
-
};
|
|
659
|
-
|
|
660
|
-
export { CactusLM } from './lm';
|
|
661
|
-
export { CactusVLM } from './vlm';
|
|
662
|
-
export { CactusTTS } from './tts';
|
|
663
|
-
export { CactusAgent } from './agent';
|