cactus-react-native 1.2.1 → 1.5.0
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/README.md +765 -33
- package/android/CMakeLists.txt +4 -3
- package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusFileSystem.kt +20 -1
- package/android/src/main/jniLibs/arm64-v8a/libcactus.a +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_util.a +0 -0
- package/cpp/HybridCactus.cpp +231 -19
- package/cpp/HybridCactus.hpp +25 -3
- package/cpp/HybridCactusIndex.cpp +325 -0
- package/cpp/HybridCactusIndex.hpp +43 -0
- package/cpp/HybridCactusUtil.cpp +3 -3
- package/cpp/HybridCactusUtil.hpp +2 -1
- package/cpp/cactus_ffi.h +107 -2
- package/cpp/cactus_util.h +1 -1
- package/ios/HybridCactusFileSystem.swift +23 -2
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus.h +2 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_ffi.h +107 -2
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_telemetry.h +656 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/{ffi_utils.h → cactus_utils.h} +145 -18
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/engine.h +135 -7
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/gemma_tools.h +549 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/graph.h +193 -26
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel.h +54 -195
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel_utils.h +399 -140
- 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 +2 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_ffi.h +107 -2
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_telemetry.h +656 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/{ffi_utils.h → cactus_utils.h} +145 -18
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/engine.h +135 -7
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/gemma_tools.h +549 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/graph.h +193 -26
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel.h +54 -195
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel_utils.h +399 -140
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Info.plist +0 -0
- package/ios/cactus.xcframework/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 +4 -4
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/cactus_util.h +1 -1
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/database.h +27 -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 +1 -1
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/database.h +27 -0
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Info.plist +0 -0
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/_CodeSignature/CodeResources +3 -3
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/cactus_util +0 -0
- package/lib/module/api/Database.js +12 -95
- package/lib/module/api/Database.js.map +1 -1
- package/lib/module/classes/CactusIndex.js +45 -0
- package/lib/module/classes/CactusIndex.js.map +1 -0
- package/lib/module/classes/CactusLM.js +65 -17
- package/lib/module/classes/CactusLM.js.map +1 -1
- package/lib/module/classes/CactusSTT.js +104 -17
- package/lib/module/classes/CactusSTT.js.map +1 -1
- package/lib/module/config/CactusConfig.js +2 -0
- package/lib/module/config/CactusConfig.js.map +1 -1
- package/lib/module/constants/packageVersion.js +1 -1
- package/lib/module/hooks/useCactusIndex.js +175 -0
- package/lib/module/hooks/useCactusIndex.js.map +1 -0
- package/lib/module/hooks/useCactusLM.js +68 -7
- package/lib/module/hooks/useCactusLM.js.map +1 -1
- package/lib/module/hooks/useCactusSTT.js +102 -6
- package/lib/module/hooks/useCactusSTT.js.map +1 -1
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/models.js +336 -0
- package/lib/module/models.js.map +1 -0
- package/lib/module/native/Cactus.js +61 -13
- package/lib/module/native/Cactus.js.map +1 -1
- package/lib/module/native/CactusFileSystem.js +3 -0
- package/lib/module/native/CactusFileSystem.js.map +1 -1
- package/lib/module/native/CactusIndex.js +32 -0
- package/lib/module/native/CactusIndex.js.map +1 -0
- package/lib/module/native/CactusUtil.js +16 -3
- package/lib/module/native/CactusUtil.js.map +1 -1
- package/lib/module/native/index.js +1 -0
- package/lib/module/native/index.js.map +1 -1
- package/lib/module/specs/CactusIndex.nitro.js +4 -0
- package/lib/module/specs/CactusIndex.nitro.js.map +1 -0
- package/lib/module/telemetry/Telemetry.js +3 -1
- package/lib/module/telemetry/Telemetry.js.map +1 -1
- package/lib/module/types/CactusIndex.js +2 -0
- package/lib/module/types/{CactusModel.js.map → CactusIndex.js.map} +1 -1
- package/lib/module/types/CactusLM.js +2 -0
- package/lib/module/types/CactusSTT.js +2 -0
- package/lib/module/types/common.js +2 -0
- package/lib/module/types/{CactusSTTModel.js.map → common.js.map} +1 -1
- package/lib/typescript/src/api/Database.d.ts +4 -7
- package/lib/typescript/src/api/Database.d.ts.map +1 -1
- package/lib/typescript/src/classes/CactusIndex.d.ts +15 -0
- package/lib/typescript/src/classes/CactusIndex.d.ts.map +1 -0
- package/lib/typescript/src/classes/CactusLM.d.ts +12 -5
- package/lib/typescript/src/classes/CactusLM.d.ts.map +1 -1
- package/lib/typescript/src/classes/CactusSTT.d.ts +15 -5
- package/lib/typescript/src/classes/CactusSTT.d.ts.map +1 -1
- package/lib/typescript/src/config/CactusConfig.d.ts +1 -0
- package/lib/typescript/src/config/CactusConfig.d.ts.map +1 -1
- package/lib/typescript/src/constants/packageVersion.d.ts +1 -1
- package/lib/typescript/src/hooks/useCactusIndex.d.ts +14 -0
- package/lib/typescript/src/hooks/useCactusIndex.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useCactusLM.d.ts +6 -4
- package/lib/typescript/src/hooks/useCactusLM.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useCactusSTT.d.ts +13 -5
- package/lib/typescript/src/hooks/useCactusSTT.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +6 -4
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/models.d.ts +6 -0
- package/lib/typescript/src/models.d.ts.map +1 -0
- package/lib/typescript/src/native/Cactus.d.ts +10 -3
- package/lib/typescript/src/native/Cactus.d.ts.map +1 -1
- package/lib/typescript/src/native/CactusFileSystem.d.ts +1 -0
- package/lib/typescript/src/native/CactusFileSystem.d.ts.map +1 -1
- package/lib/typescript/src/native/CactusIndex.d.ts +12 -0
- package/lib/typescript/src/native/CactusIndex.d.ts.map +1 -0
- package/lib/typescript/src/native/CactusUtil.d.ts.map +1 -1
- package/lib/typescript/src/native/index.d.ts +1 -0
- package/lib/typescript/src/native/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/Cactus.nitro.d.ts +9 -2
- package/lib/typescript/src/specs/Cactus.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/CactusFileSystem.nitro.d.ts +1 -0
- package/lib/typescript/src/specs/CactusFileSystem.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/CactusIndex.nitro.d.ts +24 -0
- package/lib/typescript/src/specs/CactusIndex.nitro.d.ts.map +1 -0
- package/lib/typescript/src/specs/CactusUtil.nitro.d.ts +1 -1
- package/lib/typescript/src/specs/CactusUtil.nitro.d.ts.map +1 -1
- package/lib/typescript/src/types/CactusIndex.d.ts +34 -0
- package/lib/typescript/src/types/CactusIndex.d.ts.map +1 -0
- package/lib/typescript/src/types/CactusLM.d.ts +19 -0
- package/lib/typescript/src/types/CactusLM.d.ts.map +1 -1
- package/lib/typescript/src/types/CactusSTT.d.ts +21 -1
- package/lib/typescript/src/types/CactusSTT.d.ts.map +1 -1
- package/lib/typescript/src/types/common.d.ts +28 -0
- package/lib/typescript/src/types/common.d.ts.map +1 -0
- package/nitro.json +3 -0
- package/nitrogen/generated/android/c++/JDeviceInfo.hpp +1 -1
- package/nitrogen/generated/android/c++/JFunc_void_double.hpp +1 -1
- package/nitrogen/generated/android/c++/JHybridCactusCryptoSpec.cpp +1 -1
- package/nitrogen/generated/android/c++/JHybridCactusCryptoSpec.hpp +1 -1
- package/nitrogen/generated/android/c++/JHybridCactusDeviceInfoSpec.cpp +1 -1
- package/nitrogen/generated/android/c++/JHybridCactusDeviceInfoSpec.hpp +1 -1
- package/nitrogen/generated/android/c++/JHybridCactusFileSystemSpec.cpp +17 -1
- package/nitrogen/generated/android/c++/JHybridCactusFileSystemSpec.hpp +2 -1
- package/nitrogen/generated/android/c++/JHybridCactusImageSpec.cpp +1 -1
- package/nitrogen/generated/android/c++/JHybridCactusImageSpec.hpp +1 -1
- package/nitrogen/generated/android/cactus+autolinking.cmake +2 -1
- package/nitrogen/generated/android/cactus+autolinking.gradle +1 -1
- package/nitrogen/generated/android/cactusOnLoad.cpp +11 -1
- package/nitrogen/generated/android/cactusOnLoad.hpp +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/DeviceInfo.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/Func_void_double.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusCryptoSpec.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusDeviceInfoSpec.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusFileSystemSpec.kt +5 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusImageSpec.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/cactusOnLoad.kt +1 -1
- package/nitrogen/generated/ios/Cactus+autolinking.rb +1 -1
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.cpp +1 -1
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.hpp +1 -1
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Umbrella.hpp +1 -1
- package/nitrogen/generated/ios/CactusAutolinking.mm +11 -1
- package/nitrogen/generated/ios/CactusAutolinking.swift +1 -1
- package/nitrogen/generated/ios/c++/HybridCactusCryptoSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridCactusCryptoSpecSwift.hpp +1 -1
- package/nitrogen/generated/ios/c++/HybridCactusDeviceInfoSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridCactusDeviceInfoSpecSwift.hpp +1 -1
- package/nitrogen/generated/ios/c++/HybridCactusFileSystemSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridCactusFileSystemSpecSwift.hpp +9 -1
- package/nitrogen/generated/ios/c++/HybridCactusImageSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridCactusImageSpecSwift.hpp +1 -1
- package/nitrogen/generated/ios/swift/DeviceInfo.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_DeviceInfo.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_double.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__optional_std__string_.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridCactusCryptoSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridCactusCryptoSpec_cxx.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridCactusDeviceInfoSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridCactusDeviceInfoSpec_cxx.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridCactusFileSystemSpec.swift +2 -1
- package/nitrogen/generated/ios/swift/HybridCactusFileSystemSpec_cxx.swift +20 -1
- package/nitrogen/generated/ios/swift/HybridCactusImageSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridCactusImageSpec_cxx.swift +1 -1
- package/nitrogen/generated/shared/c++/CactusIndexGetResult.hpp +84 -0
- package/nitrogen/generated/shared/c++/CactusIndexQueryResult.hpp +79 -0
- package/nitrogen/generated/shared/c++/DeviceInfo.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusCryptoSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusCryptoSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusDeviceInfoSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusDeviceInfoSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusFileSystemSpec.cpp +2 -1
- package/nitrogen/generated/shared/c++/HybridCactusFileSystemSpec.hpp +2 -1
- package/nitrogen/generated/shared/c++/HybridCactusImageSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusImageSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusIndexSpec.cpp +27 -0
- package/nitrogen/generated/shared/c++/HybridCactusIndexSpec.hpp +76 -0
- package/nitrogen/generated/shared/c++/HybridCactusSpec.cpp +8 -1
- package/nitrogen/generated/shared/c++/HybridCactusSpec.hpp +11 -3
- package/nitrogen/generated/shared/c++/HybridCactusUtilSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridCactusUtilSpec.hpp +2 -2
- package/package.json +2 -2
- package/src/api/Database.ts +14 -135
- package/src/classes/CactusIndex.ts +58 -0
- package/src/classes/CactusLM.ts +87 -19
- package/src/classes/CactusSTT.ts +134 -20
- package/src/config/CactusConfig.ts +3 -0
- package/src/constants/packageVersion.ts +1 -1
- package/src/hooks/useCactusIndex.ts +195 -0
- package/src/hooks/useCactusLM.ts +88 -8
- package/src/hooks/useCactusSTT.ts +119 -7
- package/src/index.tsx +22 -2
- package/src/models.ts +344 -0
- package/src/native/Cactus.ts +95 -13
- package/src/native/CactusFileSystem.ts +4 -0
- package/src/native/CactusIndex.ts +54 -0
- package/src/native/CactusUtil.ts +19 -3
- package/src/native/index.ts +1 -0
- package/src/specs/Cactus.nitro.ts +18 -2
- package/src/specs/CactusFileSystem.nitro.ts +2 -0
- package/src/specs/CactusIndex.nitro.ts +31 -0
- package/src/specs/CactusUtil.nitro.ts +1 -1
- package/src/telemetry/Telemetry.ts +1 -1
- package/src/types/CactusIndex.ts +40 -0
- package/src/types/CactusLM.ts +24 -0
- package/src/types/CactusSTT.ts +27 -1
- package/src/types/common.ts +28 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus_util.so +0 -0
- package/lib/module/types/CactusModel.js +0 -2
- package/lib/module/types/CactusSTTModel.js +0 -2
- package/lib/typescript/src/types/CactusModel.d.ts +0 -13
- package/lib/typescript/src/types/CactusModel.d.ts.map +0 -1
- package/lib/typescript/src/types/CactusSTTModel.d.ts +0 -8
- package/lib/typescript/src/types/CactusSTTModel.d.ts.map +0 -1
- package/src/types/CactusModel.ts +0 -15
- package/src/types/CactusSTTModel.ts +0 -10
package/src/models.ts
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import type { CactusModel } from './types/common';
|
|
2
|
+
|
|
3
|
+
const models: { [key: string]: CactusModel } = {
|
|
4
|
+
'gemma-3-270m-it': {
|
|
5
|
+
completion: true,
|
|
6
|
+
tools: false,
|
|
7
|
+
vision: false,
|
|
8
|
+
embed: true,
|
|
9
|
+
speech: false,
|
|
10
|
+
quantization: {
|
|
11
|
+
int4: {
|
|
12
|
+
sizeMb: 115,
|
|
13
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int4/gemma-3-270m-it.zip',
|
|
14
|
+
},
|
|
15
|
+
int8: {
|
|
16
|
+
sizeMb: 172,
|
|
17
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int8/gemma-3-270m-it.zip',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
'functiongemma-270m-it': {
|
|
22
|
+
completion: true,
|
|
23
|
+
tools: true,
|
|
24
|
+
vision: false,
|
|
25
|
+
embed: true,
|
|
26
|
+
speech: false,
|
|
27
|
+
quantization: {
|
|
28
|
+
int4: {
|
|
29
|
+
sizeMb: 115,
|
|
30
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int4/functiongemma-270m-it.zip',
|
|
31
|
+
},
|
|
32
|
+
int8: {
|
|
33
|
+
sizeMb: 172,
|
|
34
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int8/functiongemma-270m-it.zip',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
'whisper-small': {
|
|
39
|
+
completion: false,
|
|
40
|
+
tools: false,
|
|
41
|
+
vision: false,
|
|
42
|
+
embed: true,
|
|
43
|
+
speech: true,
|
|
44
|
+
quantization: {
|
|
45
|
+
int4: {
|
|
46
|
+
sizeMb: 104,
|
|
47
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int4/whisper-small.zip',
|
|
48
|
+
pro: {
|
|
49
|
+
apple:
|
|
50
|
+
'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int4/pro/apple/whisper-small.zip',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
int8: {
|
|
54
|
+
sizeMb: 282,
|
|
55
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int8/whisper-small.zip',
|
|
56
|
+
pro: {
|
|
57
|
+
apple:
|
|
58
|
+
'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int8/pro/apple/whisper-small.zip',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
'lfm2-350m': {
|
|
64
|
+
completion: true,
|
|
65
|
+
tools: true,
|
|
66
|
+
vision: false,
|
|
67
|
+
embed: true,
|
|
68
|
+
speech: false,
|
|
69
|
+
quantization: {
|
|
70
|
+
int4: {
|
|
71
|
+
sizeMb: 153,
|
|
72
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int4/lfm2-350m.zip',
|
|
73
|
+
},
|
|
74
|
+
int8: {
|
|
75
|
+
sizeMb: 233,
|
|
76
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int8/lfm2-350m.zip',
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
'smollm2-360m-instruct': {
|
|
81
|
+
completion: true,
|
|
82
|
+
tools: false,
|
|
83
|
+
vision: false,
|
|
84
|
+
embed: true,
|
|
85
|
+
speech: false,
|
|
86
|
+
quantization: {
|
|
87
|
+
int4: {
|
|
88
|
+
sizeMb: 140,
|
|
89
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int4/smollm2-360m-instruct.zip',
|
|
90
|
+
},
|
|
91
|
+
int8: {
|
|
92
|
+
sizeMb: 227,
|
|
93
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int8/smollm2-360m-instruct.zip',
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
'lfm2-vl-450m': {
|
|
98
|
+
completion: true,
|
|
99
|
+
tools: false,
|
|
100
|
+
vision: true,
|
|
101
|
+
embed: true,
|
|
102
|
+
speech: false,
|
|
103
|
+
quantization: {
|
|
104
|
+
int4: {
|
|
105
|
+
sizeMb: 318,
|
|
106
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int4/lfm2-vl-450m.zip',
|
|
107
|
+
pro: {
|
|
108
|
+
apple:
|
|
109
|
+
'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int4/pro/apple/lfm2-vl-450m.zip',
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
int8: {
|
|
113
|
+
sizeMb: 480,
|
|
114
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int8/lfm2-vl-450m.zip',
|
|
115
|
+
pro: {
|
|
116
|
+
apple:
|
|
117
|
+
'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int8/pro/apple/lfm2-vl-450m.zip',
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
'nomic-embed-text-v2-moe': {
|
|
123
|
+
completion: false,
|
|
124
|
+
tools: false,
|
|
125
|
+
vision: false,
|
|
126
|
+
embed: true,
|
|
127
|
+
speech: false,
|
|
128
|
+
quantization: {
|
|
129
|
+
int4: {
|
|
130
|
+
sizeMb: 211,
|
|
131
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int4/nomic-embed-text-v2-moe.zip',
|
|
132
|
+
},
|
|
133
|
+
int8: {
|
|
134
|
+
sizeMb: 456,
|
|
135
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int8/nomic-embed-text-v2-moe.zip',
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
'qwen3-0.6b': {
|
|
140
|
+
completion: true,
|
|
141
|
+
tools: true,
|
|
142
|
+
vision: false,
|
|
143
|
+
embed: true,
|
|
144
|
+
speech: false,
|
|
145
|
+
quantization: {
|
|
146
|
+
int4: {
|
|
147
|
+
sizeMb: 234,
|
|
148
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int4/qwen3-0.6b.zip',
|
|
149
|
+
},
|
|
150
|
+
int8: {
|
|
151
|
+
sizeMb: 394,
|
|
152
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int8/qwen3-0.6b.zip',
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
'qwen3-embedding-0.6b': {
|
|
157
|
+
completion: false,
|
|
158
|
+
tools: false,
|
|
159
|
+
vision: false,
|
|
160
|
+
embed: true,
|
|
161
|
+
speech: false,
|
|
162
|
+
quantization: {
|
|
163
|
+
int4: {
|
|
164
|
+
sizeMb: 234,
|
|
165
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int4/qwen3-embedding-0.6b.zip',
|
|
166
|
+
},
|
|
167
|
+
int8: {
|
|
168
|
+
sizeMb: 394,
|
|
169
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int8/qwen3-embedding-0.6b.zip',
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
'lfm2-700m': {
|
|
174
|
+
completion: true,
|
|
175
|
+
tools: true,
|
|
176
|
+
vision: false,
|
|
177
|
+
embed: true,
|
|
178
|
+
speech: false,
|
|
179
|
+
quantization: {
|
|
180
|
+
int4: {
|
|
181
|
+
sizeMb: 300,
|
|
182
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int4/lfm2-700m.zip',
|
|
183
|
+
},
|
|
184
|
+
int8: {
|
|
185
|
+
sizeMb: 467,
|
|
186
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int8/lfm2-700m.zip',
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
'gemma-3-1b-it': {
|
|
191
|
+
completion: true,
|
|
192
|
+
tools: false,
|
|
193
|
+
vision: false,
|
|
194
|
+
embed: false,
|
|
195
|
+
speech: false,
|
|
196
|
+
quantization: {
|
|
197
|
+
int4: {
|
|
198
|
+
sizeMb: 320,
|
|
199
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int4/gemma-3-1b-it.zip',
|
|
200
|
+
},
|
|
201
|
+
int8: {
|
|
202
|
+
sizeMb: 642,
|
|
203
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int8/gemma-3-1b-it.zip',
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
'whisper-medium': {
|
|
208
|
+
completion: false,
|
|
209
|
+
tools: false,
|
|
210
|
+
vision: false,
|
|
211
|
+
embed: true,
|
|
212
|
+
speech: true,
|
|
213
|
+
quantization: {
|
|
214
|
+
int4: {
|
|
215
|
+
sizeMb: 320,
|
|
216
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int4/whisper-medium.zip',
|
|
217
|
+
pro: {
|
|
218
|
+
apple:
|
|
219
|
+
'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int4/pro/apple/whisper-medium.zip',
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
int8: {
|
|
223
|
+
sizeMb: 646,
|
|
224
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int8/whisper-medium.zip',
|
|
225
|
+
pro: {
|
|
226
|
+
apple:
|
|
227
|
+
'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int8/pro/apple/whisper-medium.zip',
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
'lfm2.5-1.2b-instruct': {
|
|
233
|
+
completion: true,
|
|
234
|
+
tools: true,
|
|
235
|
+
vision: false,
|
|
236
|
+
embed: true,
|
|
237
|
+
speech: false,
|
|
238
|
+
quantization: {
|
|
239
|
+
int4: {
|
|
240
|
+
sizeMb: 474,
|
|
241
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int4/lfm2.5-1.2b-instruct.zip',
|
|
242
|
+
},
|
|
243
|
+
int8: {
|
|
244
|
+
sizeMb: 722,
|
|
245
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int8/lfm2.5-1.2b-instruct.zip',
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
'lfm2-1.2b-rag': {
|
|
250
|
+
completion: true,
|
|
251
|
+
tools: true,
|
|
252
|
+
vision: false,
|
|
253
|
+
embed: true,
|
|
254
|
+
speech: false,
|
|
255
|
+
quantization: {
|
|
256
|
+
int4: {
|
|
257
|
+
sizeMb: 474,
|
|
258
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int4/lfm2-1.2b-rag.zip',
|
|
259
|
+
},
|
|
260
|
+
int8: {
|
|
261
|
+
sizeMb: 722,
|
|
262
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int8/lfm2-1.2b-rag.zip',
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
'lfm2-1.2b-tool': {
|
|
267
|
+
completion: true,
|
|
268
|
+
tools: true,
|
|
269
|
+
vision: false,
|
|
270
|
+
embed: true,
|
|
271
|
+
speech: false,
|
|
272
|
+
quantization: {
|
|
273
|
+
int4: {
|
|
274
|
+
sizeMb: 474,
|
|
275
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int4/lfm2-1.2b-tool.zip',
|
|
276
|
+
},
|
|
277
|
+
int8: {
|
|
278
|
+
sizeMb: 722,
|
|
279
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int8/lfm2-1.2b-tool.zip',
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
'lfm2-vl-1.6b': {
|
|
284
|
+
completion: true,
|
|
285
|
+
tools: false,
|
|
286
|
+
vision: true,
|
|
287
|
+
embed: true,
|
|
288
|
+
speech: false,
|
|
289
|
+
quantization: {
|
|
290
|
+
int4: {
|
|
291
|
+
sizeMb: 954,
|
|
292
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int4/lfm2-vl-1.6b.zip',
|
|
293
|
+
pro: {
|
|
294
|
+
apple:
|
|
295
|
+
'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int4/pro/apple/lfm2-vl-1.6b.zip',
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
int8: {
|
|
299
|
+
sizeMb: 1440,
|
|
300
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int8/lfm2-vl-1.6b.zip',
|
|
301
|
+
pro: {
|
|
302
|
+
apple:
|
|
303
|
+
'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int8/pro/apple/lfm2-vl-1.6b.zip',
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
'qwen3-1.7b': {
|
|
309
|
+
completion: true,
|
|
310
|
+
tools: true,
|
|
311
|
+
vision: false,
|
|
312
|
+
embed: true,
|
|
313
|
+
speech: false,
|
|
314
|
+
quantization: {
|
|
315
|
+
int4: {
|
|
316
|
+
sizeMb: 749,
|
|
317
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int4/qwen3-1.7b.zip',
|
|
318
|
+
},
|
|
319
|
+
int8: {
|
|
320
|
+
sizeMb: 1161,
|
|
321
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int8/qwen3-1.7b.zip',
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
'smollm2-1.7b-instruct': {
|
|
326
|
+
completion: true,
|
|
327
|
+
tools: false,
|
|
328
|
+
vision: false,
|
|
329
|
+
embed: true,
|
|
330
|
+
speech: false,
|
|
331
|
+
quantization: {
|
|
332
|
+
int4: {
|
|
333
|
+
sizeMb: 801,
|
|
334
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int4/smollm2-1.7b-instruct.zip',
|
|
335
|
+
},
|
|
336
|
+
int8: {
|
|
337
|
+
sizeMb: 1161,
|
|
338
|
+
url: 'https://vlqqczxwyaodtcdmdmlw.supabase.co/storage/v1/object/public/cactus-models/v1.5/int8/smollm2-1.7b-instruct.zip',
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
export default models;
|
package/src/native/Cactus.ts
CHANGED
|
@@ -10,6 +10,9 @@ import type {
|
|
|
10
10
|
import type {
|
|
11
11
|
CactusSTTTranscribeResult,
|
|
12
12
|
TranscribeOptions,
|
|
13
|
+
CactusSTTStreamTranscribeProcessResult,
|
|
14
|
+
StreamTranscribeProcessOptions,
|
|
15
|
+
CactusSTTStreamTranscribeFinalizeResult,
|
|
13
16
|
} from '../types/CactusSTT';
|
|
14
17
|
|
|
15
18
|
export class Cactus {
|
|
@@ -32,15 +35,9 @@ export class Cactus {
|
|
|
32
35
|
callback?: (token: string, tokenId: number) => void
|
|
33
36
|
): Promise<CactusLMCompleteResult> {
|
|
34
37
|
const messagesInternal: Message[] = [];
|
|
35
|
-
for (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (!message.images || !isLastMessage) {
|
|
40
|
-
messagesInternal.push({
|
|
41
|
-
...message,
|
|
42
|
-
images: undefined,
|
|
43
|
-
});
|
|
38
|
+
for (const message of messages) {
|
|
39
|
+
if (!message.images) {
|
|
40
|
+
messagesInternal.push(message);
|
|
44
41
|
continue;
|
|
45
42
|
}
|
|
46
43
|
|
|
@@ -66,6 +63,7 @@ export class Cactus {
|
|
|
66
63
|
top_k: options.topK,
|
|
67
64
|
max_tokens: options.maxTokens,
|
|
68
65
|
stop_sequences: options.stopSequences,
|
|
66
|
+
force_tools: options.forceTools,
|
|
69
67
|
})
|
|
70
68
|
: undefined;
|
|
71
69
|
const toolsJson = JSON.stringify(tools);
|
|
@@ -97,13 +95,41 @@ export class Cactus {
|
|
|
97
95
|
}
|
|
98
96
|
}
|
|
99
97
|
|
|
98
|
+
public tokenize(text: string): Promise<number[]> {
|
|
99
|
+
return this.hybridCactus.tokenize(text);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public async scoreWindow(
|
|
103
|
+
tokens: number[],
|
|
104
|
+
start: number,
|
|
105
|
+
end: number,
|
|
106
|
+
context: number
|
|
107
|
+
): Promise<number> {
|
|
108
|
+
const response = await this.hybridCactus.scoreWindow(
|
|
109
|
+
tokens,
|
|
110
|
+
start,
|
|
111
|
+
end,
|
|
112
|
+
context
|
|
113
|
+
);
|
|
114
|
+
try {
|
|
115
|
+
const parsed = JSON.parse(response);
|
|
116
|
+
return parsed.logprob;
|
|
117
|
+
} catch {
|
|
118
|
+
throw new Error('Unable to parse score window response');
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
100
122
|
public async transcribe(
|
|
101
|
-
|
|
123
|
+
audio: string | number[],
|
|
102
124
|
prompt: string,
|
|
103
125
|
responseBufferSize: number,
|
|
104
126
|
options?: TranscribeOptions,
|
|
105
127
|
callback?: (token: string, tokenId: number) => void
|
|
106
128
|
): Promise<CactusSTTTranscribeResult> {
|
|
129
|
+
if (typeof audio === 'string') {
|
|
130
|
+
audio = audio.replace('file://', '');
|
|
131
|
+
}
|
|
132
|
+
|
|
107
133
|
const optionsJson = options
|
|
108
134
|
? JSON.stringify({
|
|
109
135
|
temperature: options.temperature,
|
|
@@ -115,7 +141,7 @@ export class Cactus {
|
|
|
115
141
|
: undefined;
|
|
116
142
|
|
|
117
143
|
const response = await this.hybridCactus.transcribe(
|
|
118
|
-
|
|
144
|
+
audio,
|
|
119
145
|
prompt,
|
|
120
146
|
responseBufferSize,
|
|
121
147
|
optionsJson,
|
|
@@ -140,8 +166,64 @@ export class Cactus {
|
|
|
140
166
|
}
|
|
141
167
|
}
|
|
142
168
|
|
|
143
|
-
public
|
|
144
|
-
return this.hybridCactus.
|
|
169
|
+
public streamTranscribeInit(): Promise<void> {
|
|
170
|
+
return this.hybridCactus.streamTranscribeInit();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
public streamTranscribeInsert(audio: number[]): Promise<void> {
|
|
174
|
+
return this.hybridCactus.streamTranscribeInsert(audio);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
public async streamTranscribeProcess(
|
|
178
|
+
options?: StreamTranscribeProcessOptions
|
|
179
|
+
): Promise<CactusSTTStreamTranscribeProcessResult> {
|
|
180
|
+
const optionsJson = options
|
|
181
|
+
? JSON.stringify({
|
|
182
|
+
confirmation_threshold: options.confirmationThreshold,
|
|
183
|
+
})
|
|
184
|
+
: undefined;
|
|
185
|
+
|
|
186
|
+
const response =
|
|
187
|
+
await this.hybridCactus.streamTranscribeProcess(optionsJson);
|
|
188
|
+
|
|
189
|
+
try {
|
|
190
|
+
const parsed = JSON.parse(response);
|
|
191
|
+
|
|
192
|
+
return {
|
|
193
|
+
success: parsed.success,
|
|
194
|
+
confirmed: parsed.confirmed,
|
|
195
|
+
pending: parsed.pending,
|
|
196
|
+
};
|
|
197
|
+
} catch {
|
|
198
|
+
throw new Error('Unable to parse stream transcribe process response');
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
public async streamTranscribeFinalize(): Promise<CactusSTTStreamTranscribeFinalizeResult> {
|
|
203
|
+
const response = await this.hybridCactus.streamTranscribeFinalize();
|
|
204
|
+
|
|
205
|
+
try {
|
|
206
|
+
const parsed = JSON.parse(response);
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
success: parsed.success,
|
|
210
|
+
confirmed: parsed.confirmed,
|
|
211
|
+
};
|
|
212
|
+
} catch {
|
|
213
|
+
throw new Error('Unable to parse stream transcribe finalize response');
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
public streamTranscribeDestroy(): Promise<void> {
|
|
218
|
+
return this.hybridCactus.streamTranscribeDestroy();
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
public embed(
|
|
222
|
+
text: string,
|
|
223
|
+
embeddingBufferSize: number,
|
|
224
|
+
normalize: boolean
|
|
225
|
+
): Promise<number[]> {
|
|
226
|
+
return this.hybridCactus.embed(text, embeddingBufferSize, normalize);
|
|
145
227
|
}
|
|
146
228
|
|
|
147
229
|
public async imageEmbed(
|
|
@@ -33,6 +33,10 @@ export class CactusFileSystem {
|
|
|
33
33
|
return this.hybridCactusFileSystem.getModelPath(model);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
public static getIndexPath(name: string): Promise<string> {
|
|
37
|
+
return this.hybridCactusFileSystem.getIndexPath(name);
|
|
38
|
+
}
|
|
39
|
+
|
|
36
40
|
public static downloadModel(
|
|
37
41
|
model: string,
|
|
38
42
|
url: string,
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
2
|
+
import type { CactusIndex as CactusIndexSpec } from '../specs/CactusIndex.nitro';
|
|
3
|
+
import type {
|
|
4
|
+
CactusIndexGetResult,
|
|
5
|
+
CactusIndexQueryResult,
|
|
6
|
+
IndexQueryOptions,
|
|
7
|
+
} from '../types/CactusIndex';
|
|
8
|
+
|
|
9
|
+
export class CactusIndex {
|
|
10
|
+
private readonly hybridCactusIndex =
|
|
11
|
+
NitroModules.createHybridObject<CactusIndexSpec>('CactusIndex');
|
|
12
|
+
|
|
13
|
+
public init(indexPath: string, embeddingDim: number): Promise<void> {
|
|
14
|
+
return this.hybridCactusIndex.init(indexPath, embeddingDim);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public add(
|
|
18
|
+
ids: number[],
|
|
19
|
+
documents: string[],
|
|
20
|
+
embeddings: number[][],
|
|
21
|
+
metadatas?: string[]
|
|
22
|
+
): Promise<void> {
|
|
23
|
+
return this.hybridCactusIndex.add(ids, documents, embeddings, metadatas);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public delete(ids: number[]): Promise<void> {
|
|
27
|
+
return this.hybridCactusIndex._delete(ids);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public get(ids: number[]): Promise<CactusIndexGetResult> {
|
|
31
|
+
return this.hybridCactusIndex.get(ids);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public query(
|
|
35
|
+
embeddings: number[][],
|
|
36
|
+
options?: IndexQueryOptions
|
|
37
|
+
): Promise<CactusIndexQueryResult> {
|
|
38
|
+
const optionsJson = options
|
|
39
|
+
? JSON.stringify({
|
|
40
|
+
top_k: options.topK,
|
|
41
|
+
score_threshold: options.scoreThreshold,
|
|
42
|
+
})
|
|
43
|
+
: undefined;
|
|
44
|
+
return this.hybridCactusIndex.query(embeddings, optionsJson);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public compact(): Promise<void> {
|
|
48
|
+
return this.hybridCactusIndex.compact();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public destroy(): Promise<void> {
|
|
52
|
+
return this.hybridCactusIndex.destroy();
|
|
53
|
+
}
|
|
54
|
+
}
|
package/src/native/CactusUtil.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { NitroModules } from 'react-native-nitro-modules';
|
|
|
2
2
|
import type { CactusUtil as CactusUtilSpec } from '../specs/CactusUtil.nitro';
|
|
3
3
|
import { Platform } from 'react-native';
|
|
4
4
|
import { CactusFileSystem } from './CactusFileSystem';
|
|
5
|
+
import { CactusConfig } from '../config/CactusConfig';
|
|
6
|
+
import { Database } from '../api/Database';
|
|
5
7
|
|
|
6
8
|
export class CactusUtil {
|
|
7
9
|
private static readonly hybridCactusUtil =
|
|
@@ -10,7 +12,7 @@ export class CactusUtil {
|
|
|
10
12
|
public static async registerApp(encryptedData: string): Promise<string> {
|
|
11
13
|
if (Platform.OS === 'android') {
|
|
12
14
|
const cactusDirectory = await CactusFileSystem.getCactusDirectory();
|
|
13
|
-
this.hybridCactusUtil.setAndroidDataDirectory(cactusDirectory);
|
|
15
|
+
await this.hybridCactusUtil.setAndroidDataDirectory(cactusDirectory);
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
return this.hybridCactusUtil.registerApp(encryptedData);
|
|
@@ -19,9 +21,23 @@ export class CactusUtil {
|
|
|
19
21
|
public static async getDeviceId(): Promise<string | null> {
|
|
20
22
|
if (Platform.OS === 'android') {
|
|
21
23
|
const cactusDirectory = await CactusFileSystem.getCactusDirectory();
|
|
22
|
-
this.hybridCactusUtil.setAndroidDataDirectory(cactusDirectory);
|
|
24
|
+
await this.hybridCactusUtil.setAndroidDataDirectory(cactusDirectory);
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
const deviceId = await this.hybridCactusUtil.getDeviceId(
|
|
28
|
+
CactusConfig.cactusProKey
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
if (!deviceId) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (deviceId?.indexOf('|') !== -1) {
|
|
36
|
+
const parts = deviceId.split('|');
|
|
37
|
+
CactusConfig.cactusProKey = parts[1];
|
|
38
|
+
return await Database.registerDevice({ deviceId: parts[0] });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return deviceId;
|
|
26
42
|
}
|
|
27
43
|
}
|
package/src/native/index.ts
CHANGED
|
@@ -13,14 +13,30 @@ export interface Cactus extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
|
|
|
13
13
|
toolsJson?: string,
|
|
14
14
|
callback?: (token: string, tokenId: number) => void
|
|
15
15
|
): Promise<string>;
|
|
16
|
+
tokenize(text: string): Promise<number[]>;
|
|
17
|
+
scoreWindow(
|
|
18
|
+
tokens: number[],
|
|
19
|
+
start: number,
|
|
20
|
+
end: number,
|
|
21
|
+
context: number
|
|
22
|
+
): Promise<string>;
|
|
16
23
|
transcribe(
|
|
17
|
-
|
|
24
|
+
audio: string | number[],
|
|
18
25
|
prompt: string,
|
|
19
26
|
responseBufferSize: number,
|
|
20
27
|
optionsJson?: string,
|
|
21
28
|
callback?: (token: string, tokenId: number) => void
|
|
22
29
|
): Promise<string>;
|
|
23
|
-
|
|
30
|
+
streamTranscribeInit(): Promise<void>;
|
|
31
|
+
streamTranscribeInsert(audio: number[]): Promise<void>;
|
|
32
|
+
streamTranscribeProcess(optionsJson?: string): Promise<string>;
|
|
33
|
+
streamTranscribeFinalize(): Promise<string>;
|
|
34
|
+
streamTranscribeDestroy(): Promise<void>;
|
|
35
|
+
embed(
|
|
36
|
+
text: string,
|
|
37
|
+
embeddingBufferSize: number,
|
|
38
|
+
normalize: boolean
|
|
39
|
+
): Promise<number[]>;
|
|
24
40
|
imageEmbed(imagePath: string, embeddingBufferSize: number): Promise<number[]>;
|
|
25
41
|
audioEmbed(audioPath: string, embeddingBufferSize: number): Promise<number[]>;
|
|
26
42
|
reset(): Promise<void>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
|
|
3
|
+
interface CactusIndexGetResult {
|
|
4
|
+
documents: string[];
|
|
5
|
+
metadatas: string[];
|
|
6
|
+
embeddings: number[][];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface CactusIndexQueryResult {
|
|
10
|
+
ids: number[][];
|
|
11
|
+
scores: number[][];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface CactusIndex
|
|
15
|
+
extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
|
|
16
|
+
init(indexPath: string, embeddingDim: number): Promise<void>;
|
|
17
|
+
add(
|
|
18
|
+
ids: number[],
|
|
19
|
+
documents: string[],
|
|
20
|
+
embeddings: number[][],
|
|
21
|
+
metadatas?: string[]
|
|
22
|
+
): Promise<void>;
|
|
23
|
+
_delete(ids: number[]): Promise<void>;
|
|
24
|
+
get(ids: number[]): Promise<CactusIndexGetResult>;
|
|
25
|
+
query(
|
|
26
|
+
embeddings: number[][],
|
|
27
|
+
optionsJson?: string
|
|
28
|
+
): Promise<CactusIndexQueryResult>;
|
|
29
|
+
compact(): Promise<void>;
|
|
30
|
+
destroy(): Promise<void>;
|
|
31
|
+
}
|
|
@@ -3,6 +3,6 @@ import type { HybridObject } from 'react-native-nitro-modules';
|
|
|
3
3
|
export interface CactusUtil
|
|
4
4
|
extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
|
|
5
5
|
registerApp(encryptedData: string): Promise<string>;
|
|
6
|
-
getDeviceId(): Promise<string | null>;
|
|
6
|
+
getDeviceId(token?: string): Promise<string | null>;
|
|
7
7
|
setAndroidDataDirectory(dataDir: string): Promise<void>;
|
|
8
8
|
}
|