cactus-react-native 1.2.1 → 1.4.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 +555 -8
- 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 +112 -19
- package/cpp/HybridCactus.hpp +12 -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 +83 -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 +83 -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} +104 -17
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/engine.h +117 -7
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/graph.h +91 -5
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel.h +15 -6
- 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 +83 -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} +104 -17
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/engine.h +117 -7
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/graph.h +91 -5
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel.h +15 -6
- 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 -3
- 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 +35 -5
- package/lib/module/classes/CactusLM.js.map +1 -1
- package/lib/module/classes/CactusSTT.js +17 -5
- 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 +54 -2
- package/lib/module/hooks/useCactusLM.js.map +1 -1
- package/lib/module/hooks/useCactusSTT.js +2 -2
- 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/native/Cactus.js +24 -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/CactusIndex.js.map +1 -0
- package/lib/typescript/src/api/Database.d.ts +4 -1
- 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 +5 -2
- package/lib/typescript/src/classes/CactusLM.d.ts.map +1 -1
- package/lib/typescript/src/classes/CactusSTT.d.ts +2 -1
- 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 +4 -2
- package/lib/typescript/src/hooks/useCactusLM.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useCactusSTT.d.ts +1 -1
- package/lib/typescript/src/hooks/useCactusSTT.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +4 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/native/Cactus.d.ts +4 -2
- 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 +4 -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 +17 -0
- package/lib/typescript/src/types/CactusLM.d.ts.map +1 -1
- package/lib/typescript/src/types/CactusSTT.d.ts +1 -1
- package/lib/typescript/src/types/CactusSTT.d.ts.map +1 -1
- 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 +3 -1
- package/nitrogen/generated/shared/c++/HybridCactusSpec.hpp +6 -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 -2
- package/src/classes/CactusIndex.ts +58 -0
- package/src/classes/CactusLM.ts +41 -5
- package/src/classes/CactusSTT.ts +19 -6
- 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 +63 -3
- package/src/hooks/useCactusSTT.ts +2 -2
- package/src/index.tsx +16 -0
- package/src/native/Cactus.ts +40 -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 +13 -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 +21 -0
- package/src/types/CactusSTT.ts +1 -1
- package/android/src/main/jniLibs/arm64-v8a/libcactus_util.so +0 -0
package/cpp/cactus_ffi.h
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
#include <stddef.h>
|
|
5
5
|
#include <stdint.h>
|
|
6
|
+
#include <stdbool.h>
|
|
6
7
|
|
|
7
8
|
#if __GNUC__ >= 4
|
|
8
9
|
#define CACTUS_FFI_EXPORT __attribute__ ((visibility ("default")))
|
|
@@ -33,6 +34,26 @@ CACTUS_FFI_EXPORT int cactus_complete(
|
|
|
33
34
|
void* user_data
|
|
34
35
|
);
|
|
35
36
|
|
|
37
|
+
CACTUS_FFI_EXPORT int cactus_tokenize(
|
|
38
|
+
cactus_model_t model,
|
|
39
|
+
const char* text,
|
|
40
|
+
uint32_t* token_buffer,
|
|
41
|
+
size_t token_buffer_len,
|
|
42
|
+
size_t* out_token_len
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
CACTUS_FFI_EXPORT int cactus_score_window(
|
|
46
|
+
cactus_model_t model,
|
|
47
|
+
const uint32_t* tokens,
|
|
48
|
+
size_t token_len,
|
|
49
|
+
size_t start,
|
|
50
|
+
size_t end,
|
|
51
|
+
size_t context,
|
|
52
|
+
char* response_buffer,
|
|
53
|
+
size_t buffer_size
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
|
|
36
57
|
CACTUS_FFI_EXPORT int cactus_transcribe(
|
|
37
58
|
cactus_model_t model,
|
|
38
59
|
const char* audio_file_path,
|
|
@@ -41,7 +62,9 @@ CACTUS_FFI_EXPORT int cactus_transcribe(
|
|
|
41
62
|
size_t buffer_size,
|
|
42
63
|
const char* options_json,
|
|
43
64
|
cactus_token_callback callback,
|
|
44
|
-
void* user_data
|
|
65
|
+
void* user_data,
|
|
66
|
+
const uint8_t* pcm_buffer,
|
|
67
|
+
size_t pcm_buffer_size
|
|
45
68
|
);
|
|
46
69
|
|
|
47
70
|
|
|
@@ -50,7 +73,8 @@ CACTUS_FFI_EXPORT int cactus_embed(
|
|
|
50
73
|
const char* text,
|
|
51
74
|
float* embeddings_buffer,
|
|
52
75
|
size_t buffer_size,
|
|
53
|
-
size_t* embedding_dim
|
|
76
|
+
size_t* embedding_dim,
|
|
77
|
+
bool normalize
|
|
54
78
|
);
|
|
55
79
|
|
|
56
80
|
CACTUS_FFI_EXPORT int cactus_image_embed(
|
|
@@ -75,6 +99,63 @@ CACTUS_FFI_EXPORT void cactus_stop(cactus_model_t model);
|
|
|
75
99
|
|
|
76
100
|
CACTUS_FFI_EXPORT void cactus_destroy(cactus_model_t model);
|
|
77
101
|
|
|
102
|
+
CACTUS_FFI_EXPORT const char* cactus_get_last_error(void);
|
|
103
|
+
|
|
104
|
+
CACTUS_FFI_EXPORT void cactus_set_telemetry_token(const char* token);
|
|
105
|
+
|
|
106
|
+
CACTUS_FFI_EXPORT void cactus_set_pro_key(const char* pro_key);
|
|
107
|
+
|
|
108
|
+
typedef void* cactus_index_t;
|
|
109
|
+
|
|
110
|
+
CACTUS_FFI_EXPORT cactus_index_t cactus_index_init(
|
|
111
|
+
const char* index_dir,
|
|
112
|
+
size_t embedding_dim
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
CACTUS_FFI_EXPORT int cactus_index_add(
|
|
116
|
+
cactus_index_t index,
|
|
117
|
+
const int* ids,
|
|
118
|
+
const char** documents,
|
|
119
|
+
const char** metadatas,
|
|
120
|
+
const float** embeddings,
|
|
121
|
+
size_t count,
|
|
122
|
+
size_t embedding_dim
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
CACTUS_FFI_EXPORT int cactus_index_delete(
|
|
126
|
+
cactus_index_t index,
|
|
127
|
+
const int* ids,
|
|
128
|
+
size_t ids_count
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
CACTUS_FFI_EXPORT int cactus_index_get(
|
|
132
|
+
cactus_index_t index,
|
|
133
|
+
const int* ids,
|
|
134
|
+
size_t ids_count,
|
|
135
|
+
char** document_buffers,
|
|
136
|
+
size_t* document_buffer_sizes,
|
|
137
|
+
char** metadata_buffers,
|
|
138
|
+
size_t* metadata_buffer_sizes,
|
|
139
|
+
float** embedding_buffers,
|
|
140
|
+
size_t* embedding_buffer_sizes
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
CACTUS_FFI_EXPORT int cactus_index_query(
|
|
144
|
+
cactus_index_t index,
|
|
145
|
+
const float** embeddings,
|
|
146
|
+
size_t embeddings_count,
|
|
147
|
+
size_t embedding_dim,
|
|
148
|
+
const char* options_json,
|
|
149
|
+
int** id_buffers,
|
|
150
|
+
size_t* id_buffer_sizes,
|
|
151
|
+
float** score_buffers,
|
|
152
|
+
size_t* score_buffer_sizes
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
CACTUS_FFI_EXPORT int cactus_index_compact(cactus_index_t index);
|
|
156
|
+
|
|
157
|
+
CACTUS_FFI_EXPORT void cactus_index_destroy(cactus_index_t index);
|
|
158
|
+
|
|
78
159
|
#ifdef __cplusplus
|
|
79
160
|
}
|
|
80
161
|
#endif
|
package/cpp/cactus_util.h
CHANGED
|
@@ -7,7 +7,7 @@ extern "C" {
|
|
|
7
7
|
|
|
8
8
|
const char* register_app(const char* encrypted_data);
|
|
9
9
|
|
|
10
|
-
const char* get_device_id();
|
|
10
|
+
const char* get_device_id(const char* current_token);
|
|
11
11
|
|
|
12
12
|
// Helper function to free memory allocated by register_app
|
|
13
13
|
void free_string(const char* str);
|
|
@@ -133,7 +133,11 @@ class HybridCactusFileSystem: HybridCactusFileSystemSpec {
|
|
|
133
133
|
try FileManager.default.removeItem(at: modelURL)
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
|
-
|
|
136
|
+
|
|
137
|
+
func getIndexPath(name: String) throws -> Promise<String> {
|
|
138
|
+
return Promise.async { try self.indexURL(name: name).path }
|
|
139
|
+
}
|
|
140
|
+
|
|
137
141
|
private func cactusURL() throws -> URL {
|
|
138
142
|
let documentsURL = try FileManager.default.url(
|
|
139
143
|
for: .documentDirectory,
|
|
@@ -156,7 +160,24 @@ class HybridCactusFileSystem: HybridCactusFileSystemSpec {
|
|
|
156
160
|
|
|
157
161
|
private func modelURL(model: String) throws -> URL {
|
|
158
162
|
let cactusURL = try self.cactusURL()
|
|
159
|
-
|
|
163
|
+
let modelsURL = cactusURL.appendingPathComponent("models", isDirectory: true)
|
|
164
|
+
|
|
165
|
+
if !FileManager.default.fileExists(atPath: modelsURL.path) {
|
|
166
|
+
try FileManager.default.createDirectory(at: modelsURL, withIntermediateDirectories: true)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return modelsURL.appendingPathComponent(model)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
private func indexURL(name: String) throws -> URL {
|
|
173
|
+
let cactusURL = try self.cactusURL()
|
|
174
|
+
let finalURL = cactusURL.appendingPathComponent("indexes/\(name)", isDirectory: true)
|
|
175
|
+
|
|
176
|
+
if !FileManager.default.fileExists(atPath: finalURL.path) {
|
|
177
|
+
try FileManager.default.createDirectory(at: finalURL, withIntermediateDirectories: true)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return finalURL
|
|
160
181
|
}
|
|
161
182
|
}
|
|
162
183
|
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
#include <stddef.h>
|
|
5
5
|
#include <stdint.h>
|
|
6
|
+
#include <stdbool.h>
|
|
6
7
|
|
|
7
8
|
#if __GNUC__ >= 4
|
|
8
9
|
#define CACTUS_FFI_EXPORT __attribute__ ((visibility ("default")))
|
|
@@ -33,6 +34,26 @@ CACTUS_FFI_EXPORT int cactus_complete(
|
|
|
33
34
|
void* user_data
|
|
34
35
|
);
|
|
35
36
|
|
|
37
|
+
CACTUS_FFI_EXPORT int cactus_tokenize(
|
|
38
|
+
cactus_model_t model,
|
|
39
|
+
const char* text,
|
|
40
|
+
uint32_t* token_buffer,
|
|
41
|
+
size_t token_buffer_len,
|
|
42
|
+
size_t* out_token_len
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
CACTUS_FFI_EXPORT int cactus_score_window(
|
|
46
|
+
cactus_model_t model,
|
|
47
|
+
const uint32_t* tokens,
|
|
48
|
+
size_t token_len,
|
|
49
|
+
size_t start,
|
|
50
|
+
size_t end,
|
|
51
|
+
size_t context,
|
|
52
|
+
char* response_buffer,
|
|
53
|
+
size_t buffer_size
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
|
|
36
57
|
CACTUS_FFI_EXPORT int cactus_transcribe(
|
|
37
58
|
cactus_model_t model,
|
|
38
59
|
const char* audio_file_path,
|
|
@@ -41,7 +62,9 @@ CACTUS_FFI_EXPORT int cactus_transcribe(
|
|
|
41
62
|
size_t buffer_size,
|
|
42
63
|
const char* options_json,
|
|
43
64
|
cactus_token_callback callback,
|
|
44
|
-
void* user_data
|
|
65
|
+
void* user_data,
|
|
66
|
+
const uint8_t* pcm_buffer,
|
|
67
|
+
size_t pcm_buffer_size
|
|
45
68
|
);
|
|
46
69
|
|
|
47
70
|
|
|
@@ -50,7 +73,8 @@ CACTUS_FFI_EXPORT int cactus_embed(
|
|
|
50
73
|
const char* text,
|
|
51
74
|
float* embeddings_buffer,
|
|
52
75
|
size_t buffer_size,
|
|
53
|
-
size_t* embedding_dim
|
|
76
|
+
size_t* embedding_dim,
|
|
77
|
+
bool normalize
|
|
54
78
|
);
|
|
55
79
|
|
|
56
80
|
CACTUS_FFI_EXPORT int cactus_image_embed(
|
|
@@ -75,6 +99,63 @@ CACTUS_FFI_EXPORT void cactus_stop(cactus_model_t model);
|
|
|
75
99
|
|
|
76
100
|
CACTUS_FFI_EXPORT void cactus_destroy(cactus_model_t model);
|
|
77
101
|
|
|
102
|
+
CACTUS_FFI_EXPORT const char* cactus_get_last_error(void);
|
|
103
|
+
|
|
104
|
+
CACTUS_FFI_EXPORT void cactus_set_telemetry_token(const char* token);
|
|
105
|
+
|
|
106
|
+
CACTUS_FFI_EXPORT void cactus_set_pro_key(const char* pro_key);
|
|
107
|
+
|
|
108
|
+
typedef void* cactus_index_t;
|
|
109
|
+
|
|
110
|
+
CACTUS_FFI_EXPORT cactus_index_t cactus_index_init(
|
|
111
|
+
const char* index_dir,
|
|
112
|
+
size_t embedding_dim
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
CACTUS_FFI_EXPORT int cactus_index_add(
|
|
116
|
+
cactus_index_t index,
|
|
117
|
+
const int* ids,
|
|
118
|
+
const char** documents,
|
|
119
|
+
const char** metadatas,
|
|
120
|
+
const float** embeddings,
|
|
121
|
+
size_t count,
|
|
122
|
+
size_t embedding_dim
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
CACTUS_FFI_EXPORT int cactus_index_delete(
|
|
126
|
+
cactus_index_t index,
|
|
127
|
+
const int* ids,
|
|
128
|
+
size_t ids_count
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
CACTUS_FFI_EXPORT int cactus_index_get(
|
|
132
|
+
cactus_index_t index,
|
|
133
|
+
const int* ids,
|
|
134
|
+
size_t ids_count,
|
|
135
|
+
char** document_buffers,
|
|
136
|
+
size_t* document_buffer_sizes,
|
|
137
|
+
char** metadata_buffers,
|
|
138
|
+
size_t* metadata_buffer_sizes,
|
|
139
|
+
float** embedding_buffers,
|
|
140
|
+
size_t* embedding_buffer_sizes
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
CACTUS_FFI_EXPORT int cactus_index_query(
|
|
144
|
+
cactus_index_t index,
|
|
145
|
+
const float** embeddings,
|
|
146
|
+
size_t embeddings_count,
|
|
147
|
+
size_t embedding_dim,
|
|
148
|
+
const char* options_json,
|
|
149
|
+
int** id_buffers,
|
|
150
|
+
size_t* id_buffer_sizes,
|
|
151
|
+
float** score_buffers,
|
|
152
|
+
size_t* score_buffer_sizes
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
CACTUS_FFI_EXPORT int cactus_index_compact(cactus_index_t index);
|
|
156
|
+
|
|
157
|
+
CACTUS_FFI_EXPORT void cactus_index_destroy(cactus_index_t index);
|
|
158
|
+
|
|
78
159
|
#ifdef __cplusplus
|
|
79
160
|
}
|
|
80
161
|
#endif
|