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/lm.ts
DELETED
|
@@ -1,324 +0,0 @@
|
|
|
1
|
-
import { initLlama, LlamaContext } from './index'
|
|
2
|
-
// @ts-ignore
|
|
3
|
-
import { Platform } from 'react-native'
|
|
4
|
-
import type {
|
|
5
|
-
ContextParams,
|
|
6
|
-
CompletionParams,
|
|
7
|
-
CactusOAICompatibleMessage,
|
|
8
|
-
NativeCompletionResult,
|
|
9
|
-
EmbeddingParams,
|
|
10
|
-
NativeEmbeddingResult,
|
|
11
|
-
} from './index'
|
|
12
|
-
|
|
13
|
-
import { Telemetry } from './telemetry'
|
|
14
|
-
import { setCactusToken, getVertexAIEmbedding, getTextCompletion } from './remote'
|
|
15
|
-
import { ConversationHistoryManager } from './chat'
|
|
16
|
-
|
|
17
|
-
interface CactusLMReturn {
|
|
18
|
-
lm: CactusLM | null
|
|
19
|
-
error: Error | null
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class CactusLM {
|
|
23
|
-
protected context: LlamaContext
|
|
24
|
-
protected conversationHistoryManager: ConversationHistoryManager
|
|
25
|
-
private initParams: ContextParams
|
|
26
|
-
private static _initCache: Map<string, Promise<CactusLMReturn>> = new Map();
|
|
27
|
-
|
|
28
|
-
private static getCacheKey(params: ContextParams, cactusToken?: string, retryOptions?: { maxRetries?: number; delayMs?: number }): string {
|
|
29
|
-
return JSON.stringify({ params, cactusToken, retryOptions });
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
protected constructor(context: LlamaContext, initParams: ContextParams) {
|
|
33
|
-
this.context = context
|
|
34
|
-
this.initParams = initParams
|
|
35
|
-
this.conversationHistoryManager = new ConversationHistoryManager()
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
private static isContextNotFoundError(e: unknown): boolean {
|
|
39
|
-
const message = String((e as any)?.message ?? e ?? '')
|
|
40
|
-
return /context not found/i.test(message)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
private async reinit(): Promise<void> {
|
|
44
|
-
const newContext = await initLlama(this.initParams)
|
|
45
|
-
this.context = newContext
|
|
46
|
-
this.conversationHistoryManager.reset()
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
private async run<T>(op: () => Promise<T>): Promise<T> {
|
|
50
|
-
try {
|
|
51
|
-
return await op()
|
|
52
|
-
} catch (e) {
|
|
53
|
-
if (!CactusLM.isContextNotFoundError(e)) throw e
|
|
54
|
-
await this.reinit()
|
|
55
|
-
return await op()
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
static async init(
|
|
60
|
-
params: ContextParams,
|
|
61
|
-
onProgress?: (progress: number) => void,
|
|
62
|
-
cactusToken?: string,
|
|
63
|
-
retryOptions?: { maxRetries?: number; delayMs?: number },
|
|
64
|
-
): Promise<CactusLMReturn> {
|
|
65
|
-
|
|
66
|
-
if (cactusToken) {
|
|
67
|
-
setCactusToken(cactusToken);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const key = CactusLM.getCacheKey(params, cactusToken, retryOptions);
|
|
71
|
-
if (CactusLM._initCache.has(key)) {
|
|
72
|
-
return CactusLM._initCache.get(key)!;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const initPromise = (async () => {
|
|
76
|
-
const maxRetries = retryOptions?.maxRetries ?? 3;
|
|
77
|
-
const delayMs = retryOptions?.delayMs ?? 1000;
|
|
78
|
-
|
|
79
|
-
const configs = [
|
|
80
|
-
params,
|
|
81
|
-
{ ...params, n_gpu_layers: 0 }
|
|
82
|
-
];
|
|
83
|
-
|
|
84
|
-
const sleep = (ms: number): Promise<void> => {
|
|
85
|
-
return new Promise(resolve => {
|
|
86
|
-
const start = Date.now();
|
|
87
|
-
const wait = () => {
|
|
88
|
-
if (Date.now() - start >= ms) {
|
|
89
|
-
resolve();
|
|
90
|
-
} else {
|
|
91
|
-
Promise.resolve().then(wait);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
wait();
|
|
95
|
-
});
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
for (const config of configs) {
|
|
99
|
-
let lastError: Error | null = null;
|
|
100
|
-
|
|
101
|
-
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
102
|
-
try {
|
|
103
|
-
const context = await initLlama(config, onProgress);
|
|
104
|
-
return { lm: new CactusLM(context, config), error: null };
|
|
105
|
-
} catch (e) {
|
|
106
|
-
lastError = e as Error;
|
|
107
|
-
const isLastConfig = configs.indexOf(config) === configs.length - 1;
|
|
108
|
-
const isLastAttempt = attempt === maxRetries;
|
|
109
|
-
|
|
110
|
-
Telemetry.error(e as Error, {
|
|
111
|
-
n_gpu_layers: config.n_gpu_layers ?? null,
|
|
112
|
-
n_ctx: config.n_ctx ?? null,
|
|
113
|
-
model: config.model ?? null,
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
if (!isLastAttempt) {
|
|
117
|
-
const delay = delayMs * Math.pow(2, attempt - 1);
|
|
118
|
-
await sleep(delay);
|
|
119
|
-
} else if (!isLastConfig) {
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (configs.indexOf(config) === configs.length - 1 && lastError) {
|
|
126
|
-
return { lm: null, error: lastError };
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return { lm: null, error: new Error('Failed to initialize CactusLM after all retries') };
|
|
130
|
-
})();
|
|
131
|
-
|
|
132
|
-
CactusLM._initCache.set(key, initPromise);
|
|
133
|
-
|
|
134
|
-
const result = await initPromise;
|
|
135
|
-
// Cache only while in-flight; never cache resolved instances
|
|
136
|
-
CactusLM._initCache.delete(key);
|
|
137
|
-
return result;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
completion = async (
|
|
141
|
-
messages: CactusOAICompatibleMessage[],
|
|
142
|
-
params: CompletionParams & { mode?: string } = {},
|
|
143
|
-
callback?: (data: any) => void,
|
|
144
|
-
): Promise<NativeCompletionResult> => {
|
|
145
|
-
const mode = params.mode || 'local';
|
|
146
|
-
|
|
147
|
-
let result: NativeCompletionResult;
|
|
148
|
-
let lastError: Error | null = null;
|
|
149
|
-
|
|
150
|
-
if (mode === 'remote') {
|
|
151
|
-
result = await this._handleRemoteCompletion(messages, callback);
|
|
152
|
-
} else if (mode === 'local') {
|
|
153
|
-
result = await this._handleLocalCompletion(messages, params, callback);
|
|
154
|
-
} else if (mode === 'localfirst') {
|
|
155
|
-
try {
|
|
156
|
-
result = await this._handleLocalCompletion(messages, params, callback);
|
|
157
|
-
} catch (e) {
|
|
158
|
-
lastError = e as Error;
|
|
159
|
-
try {
|
|
160
|
-
result = await this._handleRemoteCompletion(messages, callback);
|
|
161
|
-
} catch (remoteError) {
|
|
162
|
-
throw lastError;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
} else if (mode === 'remotefirst') {
|
|
166
|
-
try {
|
|
167
|
-
result = await this._handleRemoteCompletion(messages, callback);
|
|
168
|
-
} catch (e) {
|
|
169
|
-
lastError = e as Error;
|
|
170
|
-
try {
|
|
171
|
-
result = await this._handleLocalCompletion(messages, params, callback);
|
|
172
|
-
} catch (localError) {
|
|
173
|
-
throw lastError;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
} else {
|
|
177
|
-
throw new Error('Invalid mode: ' + mode + '. Must be "local", "remote", "localfirst", or "remotefirst"');
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return result;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
private _handleLocalCompletion = async(
|
|
184
|
-
messages: CactusOAICompatibleMessage[],
|
|
185
|
-
params: CompletionParams,
|
|
186
|
-
callback?: (data: any) => void,
|
|
187
|
-
): Promise<NativeCompletionResult> => {
|
|
188
|
-
const { newMessages, requiresReset } =
|
|
189
|
-
this.conversationHistoryManager.processNewMessages(messages);
|
|
190
|
-
|
|
191
|
-
if (requiresReset) {
|
|
192
|
-
await this.run(() => this.context.rewind())
|
|
193
|
-
this.conversationHistoryManager.reset();
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (newMessages.length === 0) {
|
|
197
|
-
console.warn('No messages to complete!');
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const result = await this.run(() =>
|
|
201
|
-
this.context.completion({ messages: newMessages, ...params }, callback),
|
|
202
|
-
)
|
|
203
|
-
|
|
204
|
-
this.conversationHistoryManager.update(newMessages, {
|
|
205
|
-
role: 'assistant',
|
|
206
|
-
content: result.content,
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
return result;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
private async _handleRemoteCompletion(
|
|
213
|
-
messages: CactusOAICompatibleMessage[],
|
|
214
|
-
callback?: (data: any) => void,
|
|
215
|
-
): Promise<NativeCompletionResult> {
|
|
216
|
-
const prompt = messages.map((m) => `${m.role}: ${m.content}`).join('\n');
|
|
217
|
-
|
|
218
|
-
const responseText = await getTextCompletion(messages);
|
|
219
|
-
|
|
220
|
-
if (callback) {
|
|
221
|
-
for (let i = 0; i < responseText.length; i++) {
|
|
222
|
-
callback({ token: responseText[i] });
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return {
|
|
227
|
-
text: responseText,
|
|
228
|
-
reasoning_content: '',
|
|
229
|
-
tool_calls: [],
|
|
230
|
-
content: responseText,
|
|
231
|
-
tokens_predicted: responseText.split(' ').length,
|
|
232
|
-
tokens_evaluated: prompt.split(' ').length,
|
|
233
|
-
truncated: false,
|
|
234
|
-
stopped_eos: true,
|
|
235
|
-
stopped_word: '',
|
|
236
|
-
stopped_limit: 0,
|
|
237
|
-
stopping_word: '',
|
|
238
|
-
tokens_cached: 0,
|
|
239
|
-
timings: {
|
|
240
|
-
prompt_n: prompt.split(' ').length,
|
|
241
|
-
prompt_ms: 0,
|
|
242
|
-
prompt_per_token_ms: 0,
|
|
243
|
-
prompt_per_second: 0,
|
|
244
|
-
predicted_n: responseText.split(' ').length,
|
|
245
|
-
predicted_ms: 0,
|
|
246
|
-
predicted_per_token_ms: 0,
|
|
247
|
-
predicted_per_second: 0,
|
|
248
|
-
},
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
async embedding(
|
|
253
|
-
text: string,
|
|
254
|
-
params?: EmbeddingParams,
|
|
255
|
-
mode: string = 'local',
|
|
256
|
-
): Promise<NativeEmbeddingResult> {
|
|
257
|
-
let result: NativeEmbeddingResult;
|
|
258
|
-
let lastError: Error | null = null;
|
|
259
|
-
|
|
260
|
-
if (mode === 'remote') {
|
|
261
|
-
result = await this._handleRemoteEmbedding(text);
|
|
262
|
-
} else if (mode === 'local') {
|
|
263
|
-
result = await this._handleLocalEmbedding(text, params);
|
|
264
|
-
} else if (mode === 'localfirst') {
|
|
265
|
-
try {
|
|
266
|
-
result = await this._handleLocalEmbedding(text, params);
|
|
267
|
-
} catch (e) {
|
|
268
|
-
lastError = e as Error;
|
|
269
|
-
try {
|
|
270
|
-
result = await this._handleRemoteEmbedding(text);
|
|
271
|
-
} catch (remoteError) {
|
|
272
|
-
throw lastError;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
} else if (mode === 'remotefirst') {
|
|
276
|
-
try {
|
|
277
|
-
result = await this._handleRemoteEmbedding(text);
|
|
278
|
-
} catch (e) {
|
|
279
|
-
lastError = e as Error;
|
|
280
|
-
try {
|
|
281
|
-
result = await this._handleLocalEmbedding(text, params);
|
|
282
|
-
} catch (localError) {
|
|
283
|
-
throw lastError;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
} else {
|
|
287
|
-
throw new Error('Invalid mode: ' + mode + '. Must be "local", "remote", "localfirst", or "remotefirst"');
|
|
288
|
-
}
|
|
289
|
-
return result;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
protected async _handleLocalEmbedding(text: string, params?: EmbeddingParams): Promise<NativeEmbeddingResult> {
|
|
293
|
-
return this.run(() => this.context.embedding(text, params))
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
protected async _handleRemoteEmbedding(text: string): Promise<NativeEmbeddingResult> {
|
|
297
|
-
const embeddingValues = await getVertexAIEmbedding(text);
|
|
298
|
-
return {
|
|
299
|
-
embedding: embeddingValues,
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
rewind = async (): Promise<void> => {
|
|
304
|
-
return this.run(() => this.context.rewind())
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
async release(): Promise<void> {
|
|
308
|
-
try {
|
|
309
|
-
return await this.context.release()
|
|
310
|
-
} catch (e) {
|
|
311
|
-
// Treat missing context as already released
|
|
312
|
-
if (CactusLM.isContextNotFoundError(e)) return
|
|
313
|
-
throw e
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
async stopCompletion(): Promise<void> {
|
|
318
|
-
return await this.run(() => this.context.stopCompletion())
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
isJinjaSupported(): boolean {
|
|
322
|
-
return this.context.isJinjaSupported();
|
|
323
|
-
}
|
|
324
|
-
}
|
package/src/projectId.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const PROJECT_ID = 'not-set';
|
package/src/remote.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import type { CactusOAICompatibleMessage } from "./chat";
|
|
2
|
-
|
|
3
|
-
let _cactusToken: string | null = null;
|
|
4
|
-
|
|
5
|
-
export function setCactusToken(token: string | null): void {
|
|
6
|
-
_cactusToken = token;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export async function getVertexAIEmbedding(text: string): Promise<number[]> {
|
|
10
|
-
text = text
|
|
11
|
-
throw new Error('Remote embedding is not currently supported. The Cactus library is in active development - if you need this functionality, please contact us at founders@cactuscompute.com');
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export async function getVertexAICompletion(
|
|
15
|
-
messages: CactusOAICompatibleMessage[],
|
|
16
|
-
imageData?: string,
|
|
17
|
-
imagePath?: string,
|
|
18
|
-
mimeType?: string,
|
|
19
|
-
): Promise<string> {
|
|
20
|
-
if (_cactusToken === null) {
|
|
21
|
-
throw new Error('CactusToken not set. Please call CactusVLM.init with cactusToken parameter.');
|
|
22
|
-
}
|
|
23
|
-
const endpoint = 'https://openrouter.ai/api/v1/chat/completions';
|
|
24
|
-
|
|
25
|
-
const headers = {
|
|
26
|
-
'Authorization': `Bearer ${_cactusToken}`,
|
|
27
|
-
'Content-Type': 'application/json',
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const requestBody = {
|
|
31
|
-
model: 'google/gemini-2.5-flash-lite',
|
|
32
|
-
messages: messages,
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
let imageUrl = ''
|
|
36
|
-
if (imageData) {
|
|
37
|
-
imageUrl = `data:${mimeType || 'image/jpeg'};base64,${imageData}`
|
|
38
|
-
} else if (imagePath) {
|
|
39
|
-
const RNFS = require('react-native-fs');
|
|
40
|
-
const base64Data = await RNFS.readFile(imagePath, 'base64');
|
|
41
|
-
imageUrl = `data:${mimeType || detectMimeType(imagePath)};base64,${base64Data}`
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (imageUrl) {
|
|
45
|
-
if (requestBody.messages[requestBody.messages.length - 1]?.role === 'user') {
|
|
46
|
-
requestBody.messages[requestBody.messages.length - 1] = {
|
|
47
|
-
role: 'user',
|
|
48
|
-
content: [
|
|
49
|
-
{
|
|
50
|
-
type: 'text',
|
|
51
|
-
text: requestBody.messages[requestBody.messages.length - 1]?.content || ''
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
type: 'image_url',
|
|
55
|
-
image_url: {
|
|
56
|
-
url: imageUrl
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
]
|
|
60
|
-
}
|
|
61
|
-
}else{
|
|
62
|
-
console.warn('Image data provided but message is not a user message: ', requestBody.messages);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const response = await fetch(endpoint, {
|
|
67
|
-
method: 'POST',
|
|
68
|
-
headers,
|
|
69
|
-
body: JSON.stringify(requestBody),
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
if (response.status === 401) {
|
|
73
|
-
_cactusToken = null;
|
|
74
|
-
throw new Error('Authentication failed. Please update your cactusToken.');
|
|
75
|
-
} else if (!response.ok) {
|
|
76
|
-
const errorText = await response.text();
|
|
77
|
-
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const responseBody = await response.json();
|
|
81
|
-
const responseText = responseBody.choices[0].message.content;
|
|
82
|
-
|
|
83
|
-
return responseText;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export async function getTextCompletion(messages: CactusOAICompatibleMessage[]): Promise<string> {
|
|
87
|
-
return getVertexAICompletion(messages);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export async function getVisionCompletion(messages: CactusOAICompatibleMessage[], imagePath: string): Promise<string> {
|
|
91
|
-
return getVertexAICompletion(messages, undefined, imagePath);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export async function getVisionCompletionFromData(messages: CactusOAICompatibleMessage[], imageData: string, mimeType?: string): Promise<string> {
|
|
95
|
-
return getVertexAICompletion(messages, imageData, undefined, mimeType);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function detectMimeType(filePath: string): string {
|
|
99
|
-
const extension = filePath.toLowerCase().split('.').pop();
|
|
100
|
-
switch (extension) {
|
|
101
|
-
case 'jpg':
|
|
102
|
-
case 'jpeg':
|
|
103
|
-
return 'image/jpeg';
|
|
104
|
-
case 'png':
|
|
105
|
-
return 'image/png';
|
|
106
|
-
case 'gif':
|
|
107
|
-
return 'image/gif';
|
|
108
|
-
case 'webp':
|
|
109
|
-
return 'image/webp';
|
|
110
|
-
default:
|
|
111
|
-
return 'image/jpeg';
|
|
112
|
-
}
|
|
113
|
-
}
|
package/src/telemetry.ts
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { Platform } from 'react-native'
|
|
2
|
-
const packageJson = require('../package.json');
|
|
3
|
-
import { PROJECT_ID } from './projectId';
|
|
4
|
-
|
|
5
|
-
export interface TelemetryParams {
|
|
6
|
-
n_gpu_layers: number | null
|
|
7
|
-
n_ctx: number | null
|
|
8
|
-
model: string | null
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface TelemetryRecord {
|
|
12
|
-
project_id: string;
|
|
13
|
-
device_id?: string;
|
|
14
|
-
device_manufacturer?: string;
|
|
15
|
-
device_model?: string;
|
|
16
|
-
os: 'iOS' | 'Android';
|
|
17
|
-
os_version: string;
|
|
18
|
-
framework: string;
|
|
19
|
-
framework_version: string;
|
|
20
|
-
telemetry_payload?: Record<string, any>;
|
|
21
|
-
error_payload?: Record<string, any>;
|
|
22
|
-
timestamp: string;
|
|
23
|
-
model_filename: string | null;
|
|
24
|
-
n_ctx: number | null;
|
|
25
|
-
n_gpu_layers: number | null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface TelemetryConfig {
|
|
29
|
-
supabaseUrl: string;
|
|
30
|
-
supabaseKey: string;
|
|
31
|
-
table?: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export class Telemetry {
|
|
35
|
-
private static instance: Telemetry | null = null;
|
|
36
|
-
private config: Required<TelemetryConfig>;
|
|
37
|
-
|
|
38
|
-
private constructor(config: TelemetryConfig) {
|
|
39
|
-
this.config = {
|
|
40
|
-
table: 'telemetry',
|
|
41
|
-
...config
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
private static getFilename(path: string): string {
|
|
46
|
-
try {
|
|
47
|
-
return path.split('/').pop() || path.split('\\').pop() || 'unknown';
|
|
48
|
-
} catch {
|
|
49
|
-
return 'unknown';
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
static autoInit(): void {
|
|
54
|
-
if (!Telemetry.instance) {
|
|
55
|
-
Telemetry.instance = new Telemetry({
|
|
56
|
-
supabaseUrl: 'https://vlqqczxwyaodtcdmdmlw.supabase.co',
|
|
57
|
-
supabaseKey: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InZscXFjenh3eWFvZHRjZG1kbWx3Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTE1MTg2MzIsImV4cCI6MjA2NzA5NDYzMn0.nBzqGuK9j6RZ6mOPWU2boAC_5H9XDs-fPpo5P3WZYbI', // Anon!
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
static init(config: TelemetryConfig): void {
|
|
63
|
-
if (!Telemetry.instance) {
|
|
64
|
-
Telemetry.instance = new Telemetry(config);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
static track(payload: Record<string, any>, options: TelemetryParams, deviceMetadata?: Record<string, any>): void {
|
|
69
|
-
if (!Telemetry.instance) {
|
|
70
|
-
Telemetry.autoInit();
|
|
71
|
-
}
|
|
72
|
-
Telemetry.instance!.trackInternal(payload, options, deviceMetadata);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
static error(error: Error, options: TelemetryParams): void {
|
|
76
|
-
if (!Telemetry.instance) {
|
|
77
|
-
Telemetry.autoInit();
|
|
78
|
-
}
|
|
79
|
-
Telemetry.instance!.errorInternal(error, options);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
private trackInternal(payload: Record<string, any>, options: TelemetryParams, deviceMetadata?: Record<string, any>): void {
|
|
83
|
-
const record: TelemetryRecord = {
|
|
84
|
-
project_id: PROJECT_ID,
|
|
85
|
-
device_id: deviceMetadata?.deviceId,
|
|
86
|
-
device_manufacturer: deviceMetadata?.make,
|
|
87
|
-
device_model: deviceMetadata?.model,
|
|
88
|
-
os: Platform.OS === 'ios' ? 'iOS' : 'Android',
|
|
89
|
-
os_version: Platform.Version.toString(),
|
|
90
|
-
framework: 'react-native',
|
|
91
|
-
framework_version: packageJson.version,
|
|
92
|
-
telemetry_payload: payload,
|
|
93
|
-
timestamp: new Date().toISOString(),
|
|
94
|
-
model_filename: Telemetry.getFilename(options.model || ''),
|
|
95
|
-
n_ctx: options.n_ctx,
|
|
96
|
-
n_gpu_layers: options.n_gpu_layers,
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
this.sendRecord(record).catch(() => {});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
private errorInternal(error: Error, options: TelemetryParams): void {
|
|
103
|
-
const errorPayload = {
|
|
104
|
-
message: error.message,
|
|
105
|
-
stack: error.stack,
|
|
106
|
-
name: error.name,
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const record: TelemetryRecord = {
|
|
110
|
-
project_id: PROJECT_ID,
|
|
111
|
-
os: Platform.OS === 'ios' ? 'iOS' : 'Android',
|
|
112
|
-
os_version: Platform.Version.toString(),
|
|
113
|
-
framework: 'react-native',
|
|
114
|
-
framework_version: packageJson.version,
|
|
115
|
-
error_payload: errorPayload,
|
|
116
|
-
timestamp: new Date().toISOString(),
|
|
117
|
-
model_filename: Telemetry.getFilename(options.model || ''),
|
|
118
|
-
n_ctx: options.n_ctx,
|
|
119
|
-
n_gpu_layers: options.n_gpu_layers
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
this.sendRecord(record).catch(() => {});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
private async sendRecord(record: TelemetryRecord): Promise<void> {
|
|
126
|
-
await (globalThis as any).fetch(`${this.config.supabaseUrl}/rest/v1/${this.config.table}`, {
|
|
127
|
-
method: 'POST',
|
|
128
|
-
headers: {
|
|
129
|
-
'apikey': this.config.supabaseKey,
|
|
130
|
-
'Authorization': `Bearer ${this.config.supabaseKey}`,
|
|
131
|
-
'Content-Type': 'application/json',
|
|
132
|
-
'Prefer': 'return=minimal'
|
|
133
|
-
},
|
|
134
|
-
body: JSON.stringify([record])
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
}
|
package/src/tools.ts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import type { NativeCompletionResult } from "./NativeCactus";
|
|
2
|
-
|
|
3
|
-
export type OpenAIToolSchema = {
|
|
4
|
-
type: "function",
|
|
5
|
-
function: {
|
|
6
|
-
name: string,
|
|
7
|
-
description: string,
|
|
8
|
-
parameters: {
|
|
9
|
-
type: "object",
|
|
10
|
-
properties: {[key: string]: Parameter},
|
|
11
|
-
required: string[]
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface Parameter {
|
|
17
|
-
type: string,
|
|
18
|
-
description: string,
|
|
19
|
-
required?: boolean
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface Tool {
|
|
23
|
-
func: Function,
|
|
24
|
-
description: string,
|
|
25
|
-
parameters: {[key: string]: Parameter},
|
|
26
|
-
required: string[]
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export class Tools {
|
|
30
|
-
private tools = new Map<string, Tool>();
|
|
31
|
-
|
|
32
|
-
add(
|
|
33
|
-
func: Function,
|
|
34
|
-
description: string,
|
|
35
|
-
parameters: {[key: string]: Parameter},
|
|
36
|
-
) {
|
|
37
|
-
this.tools.set(func.name, {
|
|
38
|
-
func,
|
|
39
|
-
description,
|
|
40
|
-
parameters,
|
|
41
|
-
required: Object.entries(parameters)
|
|
42
|
-
.filter(([_, param]) => param.required)
|
|
43
|
-
.map(([key, _]) => key)
|
|
44
|
-
});
|
|
45
|
-
return func;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
getSchemas(): OpenAIToolSchema[] {
|
|
49
|
-
return Array.from(this.tools.entries()).map(([name, { description, parameters, required }]) => ({
|
|
50
|
-
type: "function",
|
|
51
|
-
function: {
|
|
52
|
-
name,
|
|
53
|
-
description,
|
|
54
|
-
parameters: {
|
|
55
|
-
type: "object",
|
|
56
|
-
properties: parameters,
|
|
57
|
-
required
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async execute(name: string, args: any) {
|
|
64
|
-
const tool = this.tools.get(name);
|
|
65
|
-
if (!tool) throw new Error(`Tool ${name} not found`);
|
|
66
|
-
return await tool.func(...Object.values(args));
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export async function parseAndExecuteTool(result: NativeCompletionResult, tools: Tools): Promise<{toolCalled: boolean, toolName?: string, toolInput?: any, toolOutput?: any}> {
|
|
71
|
-
if (!result.tool_calls || result.tool_calls.length === 0) {
|
|
72
|
-
return {toolCalled: false};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
const toolCall = result.tool_calls[0];
|
|
77
|
-
if (!toolCall) {
|
|
78
|
-
return {toolCalled: false};
|
|
79
|
-
}
|
|
80
|
-
const toolName = toolCall.function.name;
|
|
81
|
-
const toolInput = JSON.parse(toolCall.function.arguments);
|
|
82
|
-
|
|
83
|
-
const toolOutput = await tools.execute(toolName, toolInput);
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
toolCalled: true,
|
|
87
|
-
toolName,
|
|
88
|
-
toolInput,
|
|
89
|
-
toolOutput
|
|
90
|
-
};
|
|
91
|
-
} catch (error) {
|
|
92
|
-
return {toolCalled: false};
|
|
93
|
-
}
|
|
94
|
-
}
|