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/src/hooks/useCactusLM.ts
CHANGED
|
@@ -4,12 +4,16 @@ import { CactusFileSystem } from '../native';
|
|
|
4
4
|
import { getErrorMessage } from '../utils/error';
|
|
5
5
|
import type {
|
|
6
6
|
CactusLMParams,
|
|
7
|
+
CactusLMCompleteParams,
|
|
7
8
|
CactusLMCompleteResult,
|
|
9
|
+
CactusLMTokenizeParams,
|
|
10
|
+
CactusLMTokenizeResult,
|
|
11
|
+
CactusLMScoreWindowParams,
|
|
12
|
+
CactusLMScoreWindowResult,
|
|
8
13
|
CactusLMEmbedParams,
|
|
9
14
|
CactusLMEmbedResult,
|
|
10
15
|
CactusLMImageEmbedParams,
|
|
11
16
|
CactusLMImageEmbedResult,
|
|
12
|
-
CactusLMCompleteParams,
|
|
13
17
|
CactusLMDownloadParams,
|
|
14
18
|
} from '../types/CactusLM';
|
|
15
19
|
import type { CactusModel } from '../types/CactusModel';
|
|
@@ -201,8 +205,62 @@ export const useCactusLM = ({
|
|
|
201
205
|
[cactusLM, isGenerating]
|
|
202
206
|
);
|
|
203
207
|
|
|
208
|
+
const tokenize = useCallback(
|
|
209
|
+
async ({
|
|
210
|
+
text,
|
|
211
|
+
}: CactusLMTokenizeParams): Promise<CactusLMTokenizeResult> => {
|
|
212
|
+
if (isGenerating) {
|
|
213
|
+
const message = 'CactusLM is already generating';
|
|
214
|
+
setError(message);
|
|
215
|
+
throw new Error(message);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
setError(null);
|
|
219
|
+
setIsGenerating(true);
|
|
220
|
+
try {
|
|
221
|
+
return await cactusLM.tokenize({ text });
|
|
222
|
+
} catch (e) {
|
|
223
|
+
setError(getErrorMessage(e));
|
|
224
|
+
throw e;
|
|
225
|
+
} finally {
|
|
226
|
+
setIsGenerating(false);
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
[cactusLM, isGenerating]
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
const scoreWindow = useCallback(
|
|
233
|
+
async ({
|
|
234
|
+
tokens,
|
|
235
|
+
start,
|
|
236
|
+
end,
|
|
237
|
+
context,
|
|
238
|
+
}: CactusLMScoreWindowParams): Promise<CactusLMScoreWindowResult> => {
|
|
239
|
+
if (isGenerating) {
|
|
240
|
+
const message = 'CactusLM is already generating';
|
|
241
|
+
setError(message);
|
|
242
|
+
throw new Error(message);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
setError(null);
|
|
246
|
+
setIsGenerating(true);
|
|
247
|
+
try {
|
|
248
|
+
return await cactusLM.scoreWindow({ tokens, start, end, context });
|
|
249
|
+
} catch (e) {
|
|
250
|
+
setError(getErrorMessage(e));
|
|
251
|
+
throw e;
|
|
252
|
+
} finally {
|
|
253
|
+
setIsGenerating(false);
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
[cactusLM, isGenerating]
|
|
257
|
+
);
|
|
258
|
+
|
|
204
259
|
const embed = useCallback(
|
|
205
|
-
async ({
|
|
260
|
+
async ({
|
|
261
|
+
text,
|
|
262
|
+
normalize = false,
|
|
263
|
+
}: CactusLMEmbedParams): Promise<CactusLMEmbedResult> => {
|
|
206
264
|
if (isGenerating) {
|
|
207
265
|
const message = 'CactusLM is already generating';
|
|
208
266
|
setError(message);
|
|
@@ -212,7 +270,7 @@ export const useCactusLM = ({
|
|
|
212
270
|
setError(null);
|
|
213
271
|
setIsGenerating(true);
|
|
214
272
|
try {
|
|
215
|
-
return await cactusLM.embed({ text });
|
|
273
|
+
return await cactusLM.embed({ text, normalize });
|
|
216
274
|
} catch (e) {
|
|
217
275
|
setError(getErrorMessage(e));
|
|
218
276
|
throw e;
|
|
@@ -303,6 +361,8 @@ export const useCactusLM = ({
|
|
|
303
361
|
download,
|
|
304
362
|
init,
|
|
305
363
|
complete,
|
|
364
|
+
tokenize,
|
|
365
|
+
scoreWindow,
|
|
306
366
|
embed,
|
|
307
367
|
imageEmbed,
|
|
308
368
|
reset,
|
|
@@ -162,7 +162,7 @@ export const useCactusSTT = ({
|
|
|
162
162
|
|
|
163
163
|
const transcribe = useCallback(
|
|
164
164
|
async ({
|
|
165
|
-
|
|
165
|
+
audio,
|
|
166
166
|
prompt,
|
|
167
167
|
options,
|
|
168
168
|
onToken,
|
|
@@ -178,7 +178,7 @@ export const useCactusSTT = ({
|
|
|
178
178
|
setIsGenerating(true);
|
|
179
179
|
try {
|
|
180
180
|
return await cactusSTT.transcribe({
|
|
181
|
-
|
|
181
|
+
audio,
|
|
182
182
|
prompt,
|
|
183
183
|
options,
|
|
184
184
|
onToken: (token) => {
|
package/src/index.tsx
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// Classes
|
|
2
2
|
export { CactusLM } from './classes/CactusLM';
|
|
3
3
|
export { CactusSTT } from './classes/CactusSTT';
|
|
4
|
+
export { CactusIndex } from './classes/CactusIndex';
|
|
4
5
|
|
|
5
6
|
// Hooks
|
|
6
7
|
export { useCactusLM } from './hooks/useCactusLM';
|
|
7
8
|
export { useCactusSTT } from './hooks/useCactusSTT';
|
|
9
|
+
export { useCactusIndex } from './hooks/useCactusIndex';
|
|
8
10
|
|
|
9
11
|
// Types
|
|
10
12
|
export type { CactusModel } from './types/CactusModel';
|
|
@@ -17,6 +19,10 @@ export type {
|
|
|
17
19
|
Tool,
|
|
18
20
|
CactusLMCompleteParams,
|
|
19
21
|
CactusLMCompleteResult,
|
|
22
|
+
CactusLMTokenizeParams,
|
|
23
|
+
CactusLMTokenizeResult,
|
|
24
|
+
CactusLMScoreWindowParams,
|
|
25
|
+
CactusLMScoreWindowResult,
|
|
20
26
|
CactusLMEmbedParams,
|
|
21
27
|
CactusLMEmbedResult,
|
|
22
28
|
CactusLMImageEmbedParams,
|
|
@@ -31,6 +37,16 @@ export type {
|
|
|
31
37
|
CactusSTTAudioEmbedParams,
|
|
32
38
|
CactusSTTAudioEmbedResult,
|
|
33
39
|
} from './types/CactusSTT';
|
|
40
|
+
export type {
|
|
41
|
+
CactusIndexParams,
|
|
42
|
+
CactusIndexAddParams,
|
|
43
|
+
CactusIndexGetParams,
|
|
44
|
+
CactusIndexGetResult,
|
|
45
|
+
IndexQueryOptions,
|
|
46
|
+
CactusIndexQueryParams,
|
|
47
|
+
CactusIndexQueryResult,
|
|
48
|
+
CactusIndexDeleteParams,
|
|
49
|
+
} from './types/CactusIndex';
|
|
34
50
|
|
|
35
51
|
// Config
|
|
36
52
|
export { CactusConfig } from './config/CactusConfig';
|
package/src/native/Cactus.ts
CHANGED
|
@@ -32,15 +32,9 @@ export class Cactus {
|
|
|
32
32
|
callback?: (token: string, tokenId: number) => void
|
|
33
33
|
): Promise<CactusLMCompleteResult> {
|
|
34
34
|
const messagesInternal: Message[] = [];
|
|
35
|
-
for (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (!message.images || !isLastMessage) {
|
|
40
|
-
messagesInternal.push({
|
|
41
|
-
...message,
|
|
42
|
-
images: undefined,
|
|
43
|
-
});
|
|
35
|
+
for (const message of messages) {
|
|
36
|
+
if (!message.images) {
|
|
37
|
+
messagesInternal.push(message);
|
|
44
38
|
continue;
|
|
45
39
|
}
|
|
46
40
|
|
|
@@ -66,6 +60,7 @@ export class Cactus {
|
|
|
66
60
|
top_k: options.topK,
|
|
67
61
|
max_tokens: options.maxTokens,
|
|
68
62
|
stop_sequences: options.stopSequences,
|
|
63
|
+
force_tools: options.forceTools,
|
|
69
64
|
})
|
|
70
65
|
: undefined;
|
|
71
66
|
const toolsJson = JSON.stringify(tools);
|
|
@@ -97,13 +92,41 @@ export class Cactus {
|
|
|
97
92
|
}
|
|
98
93
|
}
|
|
99
94
|
|
|
95
|
+
public tokenize(text: string): Promise<number[]> {
|
|
96
|
+
return this.hybridCactus.tokenize(text);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public async scoreWindow(
|
|
100
|
+
tokens: number[],
|
|
101
|
+
start: number,
|
|
102
|
+
end: number,
|
|
103
|
+
context: number
|
|
104
|
+
): Promise<number> {
|
|
105
|
+
const response = await this.hybridCactus.scoreWindow(
|
|
106
|
+
tokens,
|
|
107
|
+
start,
|
|
108
|
+
end,
|
|
109
|
+
context
|
|
110
|
+
);
|
|
111
|
+
try {
|
|
112
|
+
const parsed = JSON.parse(response);
|
|
113
|
+
return parsed.logprob;
|
|
114
|
+
} catch {
|
|
115
|
+
throw new Error('Unable to parse score window response');
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
100
119
|
public async transcribe(
|
|
101
|
-
|
|
120
|
+
audio: string | number[],
|
|
102
121
|
prompt: string,
|
|
103
122
|
responseBufferSize: number,
|
|
104
123
|
options?: TranscribeOptions,
|
|
105
124
|
callback?: (token: string, tokenId: number) => void
|
|
106
125
|
): Promise<CactusSTTTranscribeResult> {
|
|
126
|
+
if (typeof audio === 'string') {
|
|
127
|
+
audio = audio.replace('file://', '');
|
|
128
|
+
}
|
|
129
|
+
|
|
107
130
|
const optionsJson = options
|
|
108
131
|
? JSON.stringify({
|
|
109
132
|
temperature: options.temperature,
|
|
@@ -115,7 +138,7 @@ export class Cactus {
|
|
|
115
138
|
: undefined;
|
|
116
139
|
|
|
117
140
|
const response = await this.hybridCactus.transcribe(
|
|
118
|
-
|
|
141
|
+
audio,
|
|
119
142
|
prompt,
|
|
120
143
|
responseBufferSize,
|
|
121
144
|
optionsJson,
|
|
@@ -140,8 +163,12 @@ export class Cactus {
|
|
|
140
163
|
}
|
|
141
164
|
}
|
|
142
165
|
|
|
143
|
-
public embed(
|
|
144
|
-
|
|
166
|
+
public embed(
|
|
167
|
+
text: string,
|
|
168
|
+
embeddingBufferSize: number,
|
|
169
|
+
normalize: boolean
|
|
170
|
+
): Promise<number[]> {
|
|
171
|
+
return this.hybridCactus.embed(text, embeddingBufferSize, normalize);
|
|
145
172
|
}
|
|
146
173
|
|
|
147
174
|
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,25 @@ 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
|
-
embed(
|
|
30
|
+
embed(
|
|
31
|
+
text: string,
|
|
32
|
+
embeddingBufferSize: number,
|
|
33
|
+
normalize: boolean
|
|
34
|
+
): Promise<number[]>;
|
|
24
35
|
imageEmbed(imagePath: string, embeddingBufferSize: number): Promise<number[]>;
|
|
25
36
|
audioEmbed(audioPath: string, embeddingBufferSize: number): Promise<number[]>;
|
|
26
37
|
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
|
}
|
|
@@ -110,7 +110,7 @@ export class Telemetry {
|
|
|
110
110
|
try {
|
|
111
111
|
this.deviceId =
|
|
112
112
|
(await CactusUtil.getDeviceId()) ??
|
|
113
|
-
(await Database.registerDevice(deviceInfo));
|
|
113
|
+
(await Database.registerDevice({ deviceData: deviceInfo }));
|
|
114
114
|
} catch (error) {
|
|
115
115
|
console.log(error);
|
|
116
116
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface CactusIndexParams {
|
|
2
|
+
name: string;
|
|
3
|
+
embeddingDim: number;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface CactusIndexAddParams {
|
|
7
|
+
ids: number[];
|
|
8
|
+
documents: string[];
|
|
9
|
+
embeddings: number[][];
|
|
10
|
+
metadatas?: string[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface CactusIndexGetParams {
|
|
14
|
+
ids: number[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CactusIndexGetResult {
|
|
18
|
+
documents: string[];
|
|
19
|
+
metadatas: string[];
|
|
20
|
+
embeddings: number[][];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface IndexQueryOptions {
|
|
24
|
+
topK?: number;
|
|
25
|
+
scoreThreshold?: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface CactusIndexQueryParams {
|
|
29
|
+
embeddings: number[][];
|
|
30
|
+
options?: IndexQueryOptions;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface CactusIndexQueryResult {
|
|
34
|
+
ids: number[][];
|
|
35
|
+
scores: number[][];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface CactusIndexDeleteParams {
|
|
39
|
+
ids: number[];
|
|
40
|
+
}
|
package/src/types/CactusLM.ts
CHANGED
|
@@ -20,6 +20,7 @@ export interface CompleteOptions {
|
|
|
20
20
|
topK?: number;
|
|
21
21
|
maxTokens?: number;
|
|
22
22
|
stopSequences?: string[];
|
|
23
|
+
forceTools?: boolean;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export interface Tool {
|
|
@@ -60,8 +61,28 @@ export interface CactusLMCompleteResult {
|
|
|
60
61
|
totalTokens: number;
|
|
61
62
|
}
|
|
62
63
|
|
|
64
|
+
export interface CactusLMTokenizeParams {
|
|
65
|
+
text: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface CactusLMTokenizeResult {
|
|
69
|
+
tokens: number[];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface CactusLMScoreWindowParams {
|
|
73
|
+
tokens: number[];
|
|
74
|
+
start: number;
|
|
75
|
+
end: number;
|
|
76
|
+
context: number;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface CactusLMScoreWindowResult {
|
|
80
|
+
score: number;
|
|
81
|
+
}
|
|
82
|
+
|
|
63
83
|
export interface CactusLMEmbedParams {
|
|
64
84
|
text: string;
|
|
85
|
+
normalize?: boolean;
|
|
65
86
|
}
|
|
66
87
|
|
|
67
88
|
export interface CactusLMEmbedResult {
|
package/src/types/CactusSTT.ts
CHANGED
|
Binary file
|