cactus-react-native 1.4.0 → 1.7.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/Cactus.podspec +1 -1
- package/README.md +465 -174
- package/android/CMakeLists.txt +24 -5
- package/android/src/main/jniLibs/arm64-v8a/libcactus.a +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libcurl.a +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libmbedcrypto.a +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libmbedtls.a +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libmbedx509.a +0 -0
- package/cpp/HybridCactus.cpp +157 -6
- package/cpp/HybridCactus.hpp +20 -3
- package/cpp/cactus_ffi.h +65 -30
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus.h +0 -1
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_ffi.h +65 -30
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_utils.h +357 -122
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/engine.h +184 -63
- 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 +153 -27
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel.h +90 -178
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel_utils.h +276 -151
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/cactus +0 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus.h +0 -1
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_ffi.h +65 -30
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_utils.h +357 -122
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/engine.h +184 -63
- 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 +153 -27
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel.h +90 -178
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel_utils.h +276 -151
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/cactus +0 -0
- package/lib/module/classes/CactusLM.js +43 -58
- package/lib/module/classes/CactusLM.js.map +1 -1
- package/lib/module/classes/CactusSTT.js +64 -38
- package/lib/module/classes/CactusSTT.js.map +1 -1
- package/lib/module/classes/CactusVAD.js +95 -0
- package/lib/module/classes/CactusVAD.js.map +1 -0
- package/lib/module/hooks/useCactusLM.js +23 -15
- package/lib/module/hooks/useCactusLM.js.map +1 -1
- package/lib/module/hooks/useCactusSTT.js +85 -28
- package/lib/module/hooks/useCactusSTT.js.map +1 -1
- package/lib/module/hooks/useCactusVAD.js +171 -0
- package/lib/module/hooks/useCactusVAD.js.map +1 -0
- package/lib/module/index.js +2 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/modelRegistry.js +52 -0
- package/lib/module/modelRegistry.js.map +1 -0
- package/lib/module/native/Cactus.js +107 -8
- package/lib/module/native/Cactus.js.map +1 -1
- package/lib/module/native/CactusIndex.js.map +1 -1
- package/lib/module/native/index.js +0 -3
- package/lib/module/native/index.js.map +1 -1
- package/lib/module/types/CactusLM.js +2 -0
- package/lib/module/types/CactusSTT.js +2 -0
- package/lib/module/types/CactusVAD.js +4 -0
- package/lib/module/types/{CactusModel.js.map → CactusVAD.js.map} +1 -1
- package/lib/module/types/common.js +2 -0
- package/lib/module/types/{CactusSTTModel.js.map → common.js.map} +1 -1
- package/lib/typescript/src/classes/CactusLM.d.ts +8 -6
- package/lib/typescript/src/classes/CactusLM.d.ts.map +1 -1
- package/lib/typescript/src/classes/CactusSTT.d.ts +11 -6
- package/lib/typescript/src/classes/CactusSTT.d.ts.map +1 -1
- package/lib/typescript/src/classes/CactusVAD.d.ts +20 -0
- package/lib/typescript/src/classes/CactusVAD.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useCactusLM.d.ts +3 -3
- package/lib/typescript/src/hooks/useCactusLM.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useCactusSTT.d.ts +11 -5
- package/lib/typescript/src/hooks/useCactusSTT.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useCactusVAD.d.ts +15 -0
- package/lib/typescript/src/hooks/useCactusVAD.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +7 -6
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/modelRegistry.d.ts +5 -0
- package/lib/typescript/src/modelRegistry.d.ts.map +1 -0
- package/lib/typescript/src/native/Cactus.d.ts +12 -6
- package/lib/typescript/src/native/Cactus.d.ts.map +1 -1
- package/lib/typescript/src/native/CactusIndex.d.ts +2 -2
- package/lib/typescript/src/native/CactusIndex.d.ts.map +1 -1
- package/lib/typescript/src/native/index.d.ts +0 -3
- package/lib/typescript/src/native/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/Cactus.nitro.d.ts +6 -1
- package/lib/typescript/src/specs/Cactus.nitro.d.ts.map +1 -1
- package/lib/typescript/src/types/CactusIndex.d.ts +2 -2
- package/lib/typescript/src/types/CactusIndex.d.ts.map +1 -1
- package/lib/typescript/src/types/CactusLM.d.ts +19 -9
- package/lib/typescript/src/types/CactusLM.d.ts.map +1 -1
- package/lib/typescript/src/types/CactusSTT.d.ts +45 -4
- package/lib/typescript/src/types/CactusSTT.d.ts.map +1 -1
- package/lib/typescript/src/types/CactusVAD.d.ts +34 -0
- package/lib/typescript/src/types/CactusVAD.d.ts.map +1 -0
- package/lib/typescript/src/types/common.d.ts +23 -0
- package/lib/typescript/src/types/common.d.ts.map +1 -0
- package/nitro.json +0 -11
- package/nitrogen/generated/android/cactus+autolinking.cmake +0 -5
- package/nitrogen/generated/android/cactusOnLoad.cpp +0 -30
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.cpp +0 -50
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.hpp +9 -147
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Umbrella.hpp +0 -13
- package/nitrogen/generated/ios/CactusAutolinking.mm +0 -26
- package/nitrogen/generated/ios/CactusAutolinking.swift +0 -30
- package/nitrogen/generated/shared/c++/HybridCactusSpec.cpp +5 -0
- package/nitrogen/generated/shared/c++/HybridCactusSpec.hpp +6 -1
- package/package.json +3 -3
- package/src/classes/CactusLM.ts +59 -74
- package/src/classes/CactusSTT.ts +92 -49
- package/src/classes/CactusVAD.ts +129 -0
- package/src/hooks/useCactusLM.ts +26 -9
- package/src/hooks/useCactusSTT.ts +105 -44
- package/src/hooks/useCactusVAD.ts +215 -0
- package/src/index.tsx +20 -10
- package/src/modelRegistry.ts +65 -0
- package/src/native/Cactus.ts +130 -14
- package/src/native/CactusIndex.ts +2 -2
- package/src/native/index.ts +0 -3
- package/src/specs/Cactus.nitro.ts +11 -2
- package/src/types/CactusIndex.ts +2 -2
- package/src/types/CactusLM.ts +20 -9
- package/src/types/CactusSTT.ts +50 -4
- package/src/types/CactusVAD.ts +39 -0
- package/src/types/common.ts +23 -0
- package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusCrypto.kt +0 -46
- package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusDeviceInfo.kt +0 -27
- package/android/src/main/jniLibs/arm64-v8a/libcactus_util.a +0 -0
- package/cpp/HybridCactusUtil.cpp +0 -47
- package/cpp/HybridCactusUtil.hpp +0 -27
- package/cpp/cactus_util.h +0 -25
- package/ios/HybridCactusCrypto.swift +0 -37
- package/ios/HybridCactusDeviceInfo.swift +0 -32
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_telemetry.h +0 -656
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_telemetry.h +0 -656
- package/ios/cactus_util.xcframework/Info.plist +0 -39
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/cactus_util.h +0 -25
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/database.h +0 -27
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/ios_utils.h +0 -10
- package/ios/cactus_util.xcframework/ios-arm64/cactus_util.framework/Headers/logging.h +0 -25
- 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 +0 -25
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/database.h +0 -27
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/ios_utils.h +0 -10
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/Headers/logging.h +0 -25
- 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 +0 -135
- package/ios/cactus_util.xcframework/ios-arm64-simulator/cactus_util.framework/cactus_util +0 -0
- package/lib/module/api/Database.js +0 -137
- package/lib/module/api/Database.js.map +0 -1
- package/lib/module/api/RemoteLM.js +0 -201
- package/lib/module/api/RemoteLM.js.map +0 -1
- package/lib/module/config/CactusConfig.js +0 -12
- package/lib/module/config/CactusConfig.js.map +0 -1
- package/lib/module/native/CactusCrypto.js +0 -10
- package/lib/module/native/CactusCrypto.js.map +0 -1
- package/lib/module/native/CactusDeviceInfo.js +0 -13
- package/lib/module/native/CactusDeviceInfo.js.map +0 -1
- package/lib/module/native/CactusUtil.js +0 -36
- package/lib/module/native/CactusUtil.js.map +0 -1
- package/lib/module/specs/CactusCrypto.nitro.js +0 -4
- package/lib/module/specs/CactusCrypto.nitro.js.map +0 -1
- package/lib/module/specs/CactusDeviceInfo.nitro.js +0 -4
- package/lib/module/specs/CactusDeviceInfo.nitro.js.map +0 -1
- package/lib/module/specs/CactusUtil.nitro.js +0 -4
- package/lib/module/specs/CactusUtil.nitro.js.map +0 -1
- package/lib/module/telemetry/Telemetry.js +0 -154
- package/lib/module/telemetry/Telemetry.js.map +0 -1
- package/lib/module/types/CactusModel.js +0 -2
- package/lib/module/types/CactusSTTModel.js +0 -2
- package/lib/typescript/src/api/Database.d.ts +0 -18
- package/lib/typescript/src/api/Database.d.ts.map +0 -1
- package/lib/typescript/src/api/RemoteLM.d.ts +0 -14
- package/lib/typescript/src/api/RemoteLM.d.ts.map +0 -1
- package/lib/typescript/src/config/CactusConfig.d.ts +0 -7
- package/lib/typescript/src/config/CactusConfig.d.ts.map +0 -1
- package/lib/typescript/src/native/CactusCrypto.d.ts +0 -5
- package/lib/typescript/src/native/CactusCrypto.d.ts.map +0 -1
- package/lib/typescript/src/native/CactusDeviceInfo.d.ts +0 -7
- package/lib/typescript/src/native/CactusDeviceInfo.d.ts.map +0 -1
- package/lib/typescript/src/native/CactusUtil.d.ts +0 -6
- package/lib/typescript/src/native/CactusUtil.d.ts.map +0 -1
- package/lib/typescript/src/specs/CactusCrypto.nitro.d.ts +0 -8
- package/lib/typescript/src/specs/CactusCrypto.nitro.d.ts.map +0 -1
- package/lib/typescript/src/specs/CactusDeviceInfo.nitro.d.ts +0 -16
- package/lib/typescript/src/specs/CactusDeviceInfo.nitro.d.ts.map +0 -1
- package/lib/typescript/src/specs/CactusUtil.nitro.d.ts +0 -10
- package/lib/typescript/src/specs/CactusUtil.nitro.d.ts.map +0 -1
- package/lib/typescript/src/telemetry/Telemetry.d.ts +0 -34
- package/lib/typescript/src/telemetry/Telemetry.d.ts.map +0 -1
- 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/nitrogen/generated/android/c++/JDeviceInfo.hpp +0 -74
- package/nitrogen/generated/android/c++/JHybridCactusCryptoSpec.cpp +0 -65
- package/nitrogen/generated/android/c++/JHybridCactusCryptoSpec.hpp +0 -65
- package/nitrogen/generated/android/c++/JHybridCactusDeviceInfoSpec.cpp +0 -85
- package/nitrogen/generated/android/c++/JHybridCactusDeviceInfoSpec.hpp +0 -66
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/DeviceInfo.kt +0 -50
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusCryptoSpec.kt +0 -58
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusDeviceInfoSpec.kt +0 -62
- package/nitrogen/generated/ios/c++/HybridCactusCryptoSpecSwift.cpp +0 -11
- package/nitrogen/generated/ios/c++/HybridCactusCryptoSpecSwift.hpp +0 -77
- package/nitrogen/generated/ios/c++/HybridCactusDeviceInfoSpecSwift.cpp +0 -11
- package/nitrogen/generated/ios/c++/HybridCactusDeviceInfoSpecSwift.hpp +0 -88
- package/nitrogen/generated/ios/swift/DeviceInfo.swift +0 -98
- package/nitrogen/generated/ios/swift/Func_void_DeviceInfo.swift +0 -47
- package/nitrogen/generated/ios/swift/Func_void_std__optional_std__string_.swift +0 -54
- package/nitrogen/generated/ios/swift/HybridCactusCryptoSpec.swift +0 -57
- package/nitrogen/generated/ios/swift/HybridCactusCryptoSpec_cxx.swift +0 -139
- package/nitrogen/generated/ios/swift/HybridCactusDeviceInfoSpec.swift +0 -58
- package/nitrogen/generated/ios/swift/HybridCactusDeviceInfoSpec_cxx.swift +0 -164
- package/nitrogen/generated/shared/c++/DeviceInfo.hpp +0 -92
- package/nitrogen/generated/shared/c++/HybridCactusCryptoSpec.cpp +0 -21
- package/nitrogen/generated/shared/c++/HybridCactusCryptoSpec.hpp +0 -63
- package/nitrogen/generated/shared/c++/HybridCactusDeviceInfoSpec.cpp +0 -22
- package/nitrogen/generated/shared/c++/HybridCactusDeviceInfoSpec.hpp +0 -67
- package/nitrogen/generated/shared/c++/HybridCactusUtilSpec.cpp +0 -23
- package/nitrogen/generated/shared/c++/HybridCactusUtilSpec.hpp +0 -66
- package/src/api/Database.ts +0 -188
- package/src/api/RemoteLM.ts +0 -273
- package/src/config/CactusConfig.ts +0 -11
- package/src/native/CactusCrypto.ts +0 -11
- package/src/native/CactusDeviceInfo.ts +0 -18
- package/src/native/CactusUtil.ts +0 -43
- package/src/specs/CactusCrypto.nitro.ts +0 -6
- package/src/specs/CactusDeviceInfo.nitro.ts +0 -15
- package/src/specs/CactusUtil.nitro.ts +0 -8
- package/src/telemetry/Telemetry.ts +0 -236
- package/src/types/CactusModel.ts +0 -15
- package/src/types/CactusSTTModel.ts +0 -10
package/android/CMakeLists.txt
CHANGED
|
@@ -9,7 +9,6 @@ set(CMAKE_CXX_STANDARD 20)
|
|
|
9
9
|
add_library(${PACKAGE_NAME} SHARED
|
|
10
10
|
src/main/cpp/cpp-adapter.cpp
|
|
11
11
|
../cpp/HybridCactus.cpp
|
|
12
|
-
../cpp/HybridCactusUtil.cpp
|
|
13
12
|
../cpp/HybridCactusIndex.cpp
|
|
14
13
|
)
|
|
15
14
|
|
|
@@ -18,9 +17,26 @@ set_target_properties(libcactus PROPERTIES
|
|
|
18
17
|
IMPORTED_LOCATION "${CMAKE_CURRENT_LIST_DIR}/src/main/jniLibs/${ANDROID_ABI}/libcactus.a"
|
|
19
18
|
)
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
set(JNILIBS_DIR "${CMAKE_CURRENT_LIST_DIR}/src/main/jniLibs/${ANDROID_ABI}")
|
|
21
|
+
|
|
22
|
+
add_library(libcurl STATIC IMPORTED)
|
|
23
|
+
set_target_properties(libcurl PROPERTIES
|
|
24
|
+
IMPORTED_LOCATION "${JNILIBS_DIR}/libcurl.a"
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
add_library(libmbedtls STATIC IMPORTED)
|
|
28
|
+
set_target_properties(libmbedtls PROPERTIES
|
|
29
|
+
IMPORTED_LOCATION "${JNILIBS_DIR}/libmbedtls.a"
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
add_library(libmbedx509 STATIC IMPORTED)
|
|
33
|
+
set_target_properties(libmbedx509 PROPERTIES
|
|
34
|
+
IMPORTED_LOCATION "${JNILIBS_DIR}/libmbedx509.a"
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
add_library(libmbedcrypto STATIC IMPORTED)
|
|
38
|
+
set_target_properties(libmbedcrypto PROPERTIES
|
|
39
|
+
IMPORTED_LOCATION "${JNILIBS_DIR}/libmbedcrypto.a"
|
|
24
40
|
)
|
|
25
41
|
|
|
26
42
|
# Add Nitrogen specs :)
|
|
@@ -37,5 +53,8 @@ target_link_libraries(
|
|
|
37
53
|
${LOG_LIB}
|
|
38
54
|
android # <-- Android core
|
|
39
55
|
libcactus
|
|
40
|
-
|
|
56
|
+
libcurl
|
|
57
|
+
libmbedtls
|
|
58
|
+
libmbedx509
|
|
59
|
+
libmbedcrypto
|
|
41
60
|
)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/cpp/HybridCactus.cpp
CHANGED
|
@@ -5,10 +5,11 @@ namespace margelo::nitro::cactus {
|
|
|
5
5
|
HybridCactus::HybridCactus() : HybridObject(TAG) {}
|
|
6
6
|
|
|
7
7
|
std::shared_ptr<Promise<void>>
|
|
8
|
-
HybridCactus::init(const std::string &modelPath,
|
|
9
|
-
const std::optional<std::string> &corpusDir
|
|
8
|
+
HybridCactus::init(const std::string &modelPath,
|
|
9
|
+
const std::optional<std::string> &corpusDir,
|
|
10
|
+
std::optional<bool> cacheIndex) {
|
|
10
11
|
return Promise<void>::async(
|
|
11
|
-
[this, modelPath,
|
|
12
|
+
[this, modelPath, corpusDir, cacheIndex]() -> void {
|
|
12
13
|
std::lock_guard<std::mutex> lock(this->_modelMutex);
|
|
13
14
|
|
|
14
15
|
if (this->_model) {
|
|
@@ -16,8 +17,9 @@ HybridCactus::init(const std::string &modelPath, double contextSize,
|
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
const cactus_model_t model =
|
|
19
|
-
cactus_init(modelPath.c_str(),
|
|
20
|
-
corpusDir ? corpusDir->c_str() : nullptr
|
|
20
|
+
cactus_init(modelPath.c_str(),
|
|
21
|
+
corpusDir ? corpusDir->c_str() : nullptr,
|
|
22
|
+
cacheIndex.value_or(false));
|
|
21
23
|
|
|
22
24
|
if (!model) {
|
|
23
25
|
throw std::runtime_error("Cactus init failed: " +
|
|
@@ -25,7 +27,6 @@ HybridCactus::init(const std::string &modelPath, double contextSize,
|
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
this->_model = model;
|
|
28
|
-
this->_contextSize = contextSize;
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -211,6 +212,144 @@ std::shared_ptr<Promise<std::string>> HybridCactus::transcribe(
|
|
|
211
212
|
});
|
|
212
213
|
}
|
|
213
214
|
|
|
215
|
+
std::shared_ptr<Promise<void>> HybridCactus::streamTranscribeStart(
|
|
216
|
+
const std::optional<std::string> &optionsJson) {
|
|
217
|
+
return Promise<void>::async([this, optionsJson]() -> void {
|
|
218
|
+
std::lock_guard<std::mutex> lock(this->_modelMutex);
|
|
219
|
+
|
|
220
|
+
if (!this->_model) {
|
|
221
|
+
throw std::runtime_error("Cactus model is not initialized");
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (this->_streamTranscribe) {
|
|
225
|
+
throw std::runtime_error(
|
|
226
|
+
"Cactus stream transcribe is already initialized");
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
this->_streamTranscribe = cactus_stream_transcribe_start(
|
|
230
|
+
this->_model, optionsJson ? optionsJson->c_str() : nullptr);
|
|
231
|
+
if (!this->_streamTranscribe) {
|
|
232
|
+
throw std::runtime_error("Cactus stream transcribe start failed: " +
|
|
233
|
+
std::string(cactus_get_last_error()));
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
std::shared_ptr<Promise<std::string>>
|
|
239
|
+
HybridCactus::streamTranscribeProcess(const std::vector<double> &audio) {
|
|
240
|
+
return Promise<std::string>::async([this, audio]() -> std::string {
|
|
241
|
+
std::lock_guard<std::mutex> lock(this->_modelMutex);
|
|
242
|
+
|
|
243
|
+
if (!this->_streamTranscribe) {
|
|
244
|
+
throw std::runtime_error("Cactus stream transcribe is not initialized");
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
std::vector<uint8_t> audioBytes;
|
|
248
|
+
audioBytes.reserve(audio.size());
|
|
249
|
+
for (double d : audio) {
|
|
250
|
+
d = std::clamp(d, 0.0, 255.0);
|
|
251
|
+
audioBytes.emplace_back(static_cast<uint8_t>(d));
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
std::string responseBuffer;
|
|
255
|
+
responseBuffer.resize(32768);
|
|
256
|
+
|
|
257
|
+
int result = cactus_stream_transcribe_process(
|
|
258
|
+
this->_streamTranscribe, audioBytes.data(), audioBytes.size(),
|
|
259
|
+
responseBuffer.data(), responseBuffer.size());
|
|
260
|
+
|
|
261
|
+
if (result < 0) {
|
|
262
|
+
throw std::runtime_error("Cactus stream transcribe process failed: " +
|
|
263
|
+
std::string(cactus_get_last_error()));
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Remove null terminator
|
|
267
|
+
responseBuffer.resize(strlen(responseBuffer.c_str()));
|
|
268
|
+
|
|
269
|
+
return responseBuffer;
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
std::shared_ptr<Promise<std::string>> HybridCactus::streamTranscribeStop() {
|
|
274
|
+
return Promise<std::string>::async([this]() -> std::string {
|
|
275
|
+
std::lock_guard<std::mutex> lock(this->_modelMutex);
|
|
276
|
+
|
|
277
|
+
if (!this->_streamTranscribe) {
|
|
278
|
+
throw std::runtime_error("Cactus stream transcribe is not initialized");
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
std::string responseBuffer;
|
|
282
|
+
responseBuffer.resize(32768);
|
|
283
|
+
|
|
284
|
+
int result = cactus_stream_transcribe_stop(
|
|
285
|
+
this->_streamTranscribe, responseBuffer.data(), responseBuffer.size());
|
|
286
|
+
|
|
287
|
+
this->_streamTranscribe = nullptr;
|
|
288
|
+
|
|
289
|
+
if (result < 0) {
|
|
290
|
+
throw std::runtime_error("Cactus stream transcribe stop failed: " +
|
|
291
|
+
std::string(cactus_get_last_error()));
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Remove null terminator
|
|
295
|
+
responseBuffer.resize(strlen(responseBuffer.c_str()));
|
|
296
|
+
|
|
297
|
+
return responseBuffer;
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
std::shared_ptr<Promise<std::string>>
|
|
302
|
+
HybridCactus::vad(const std::variant<std::vector<double>, std::string> &audio,
|
|
303
|
+
double responseBufferSize,
|
|
304
|
+
const std::optional<std::string> &optionsJson) {
|
|
305
|
+
return Promise<std::string>::async(
|
|
306
|
+
[this, audio, responseBufferSize, optionsJson]() -> std::string {
|
|
307
|
+
std::lock_guard<std::mutex> lock(this->_modelMutex);
|
|
308
|
+
|
|
309
|
+
if (!this->_model) {
|
|
310
|
+
throw std::runtime_error("Cactus model is not initialized");
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
std::string responseBuffer;
|
|
314
|
+
responseBuffer.resize(responseBufferSize);
|
|
315
|
+
|
|
316
|
+
int result;
|
|
317
|
+
if (std::holds_alternative<std::string>(audio)) {
|
|
318
|
+
result =
|
|
319
|
+
cactus_vad(this->_model,
|
|
320
|
+
std::get<std::string>(audio).c_str(),
|
|
321
|
+
responseBuffer.data(), responseBufferSize,
|
|
322
|
+
optionsJson ? optionsJson->c_str() : nullptr,
|
|
323
|
+
nullptr, 0);
|
|
324
|
+
} else {
|
|
325
|
+
const auto &audioDoubles = std::get<std::vector<double>>(audio);
|
|
326
|
+
|
|
327
|
+
std::vector<uint8_t> audioBytes;
|
|
328
|
+
audioBytes.reserve(audioDoubles.size());
|
|
329
|
+
for (double d : audioDoubles) {
|
|
330
|
+
d = std::clamp(d, 0.0, 255.0);
|
|
331
|
+
audioBytes.emplace_back(static_cast<uint8_t>(d));
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
result =
|
|
335
|
+
cactus_vad(this->_model, nullptr,
|
|
336
|
+
responseBuffer.data(), responseBufferSize,
|
|
337
|
+
optionsJson ? optionsJson->c_str() : nullptr,
|
|
338
|
+
audioBytes.data(), audioBytes.size());
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (result < 0) {
|
|
342
|
+
throw std::runtime_error("Cactus VAD failed: " +
|
|
343
|
+
std::string(cactus_get_last_error()));
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// Remove null terminator
|
|
347
|
+
responseBuffer.resize(strlen(responseBuffer.c_str()));
|
|
348
|
+
|
|
349
|
+
return responseBuffer;
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
|
|
214
353
|
std::shared_ptr<Promise<std::vector<double>>>
|
|
215
354
|
HybridCactus::embed(const std::string &text, double embeddingBufferSize,
|
|
216
355
|
bool normalize) {
|
|
@@ -325,9 +464,21 @@ std::shared_ptr<Promise<void>> HybridCactus::destroy() {
|
|
|
325
464
|
throw std::runtime_error("Cactus model is not initialized");
|
|
326
465
|
}
|
|
327
466
|
|
|
467
|
+
if (this->_streamTranscribe) {
|
|
468
|
+
cactus_stream_transcribe_stop(this->_streamTranscribe, nullptr, 0);
|
|
469
|
+
this->_streamTranscribe = nullptr;
|
|
470
|
+
}
|
|
471
|
+
|
|
328
472
|
cactus_destroy(this->_model);
|
|
329
473
|
this->_model = nullptr;
|
|
330
474
|
});
|
|
331
475
|
}
|
|
332
476
|
|
|
477
|
+
std::shared_ptr<Promise<void>>
|
|
478
|
+
HybridCactus::setTelemetryEnvironment(const std::string &cacheDir) {
|
|
479
|
+
return Promise<void>::async([cacheDir]() -> void {
|
|
480
|
+
cactus_set_telemetry_environment("react-native-v1.7", cacheDir.c_str());
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
|
|
333
484
|
} // namespace margelo::nitro::cactus
|
package/cpp/HybridCactus.hpp
CHANGED
|
@@ -12,8 +12,9 @@ public:
|
|
|
12
12
|
HybridCactus();
|
|
13
13
|
|
|
14
14
|
std::shared_ptr<Promise<void>>
|
|
15
|
-
init(const std::string &modelPath,
|
|
16
|
-
const std::optional<std::string> &corpusDir
|
|
15
|
+
init(const std::string &modelPath,
|
|
16
|
+
const std::optional<std::string> &corpusDir,
|
|
17
|
+
std::optional<bool> cacheIndex) override;
|
|
17
18
|
|
|
18
19
|
std::shared_ptr<Promise<std::string>> complete(
|
|
19
20
|
const std::string &messagesJson, double responseBufferSize,
|
|
@@ -38,6 +39,19 @@ public:
|
|
|
38
39
|
double /* tokenId */)>> &callback)
|
|
39
40
|
override;
|
|
40
41
|
|
|
42
|
+
std::shared_ptr<Promise<void>>
|
|
43
|
+
streamTranscribeStart(const std::optional<std::string> &optionsJson) override;
|
|
44
|
+
|
|
45
|
+
std::shared_ptr<Promise<std::string>>
|
|
46
|
+
streamTranscribeProcess(const std::vector<double> &audio) override;
|
|
47
|
+
|
|
48
|
+
std::shared_ptr<Promise<std::string>> streamTranscribeStop() override;
|
|
49
|
+
|
|
50
|
+
std::shared_ptr<Promise<std::string>>
|
|
51
|
+
vad(const std::variant<std::vector<double>, std::string> &audio,
|
|
52
|
+
double responseBufferSize,
|
|
53
|
+
const std::optional<std::string> &optionsJson) override;
|
|
54
|
+
|
|
41
55
|
std::shared_ptr<Promise<std::vector<double>>>
|
|
42
56
|
embed(const std::string &text, double embeddingBufferSize,
|
|
43
57
|
bool normalize) override;
|
|
@@ -54,9 +68,12 @@ public:
|
|
|
54
68
|
|
|
55
69
|
std::shared_ptr<Promise<void>> destroy() override;
|
|
56
70
|
|
|
71
|
+
std::shared_ptr<Promise<void>>
|
|
72
|
+
setTelemetryEnvironment(const std::string &cacheDir) override;
|
|
73
|
+
|
|
57
74
|
private:
|
|
58
75
|
cactus_model_t _model = nullptr;
|
|
59
|
-
|
|
76
|
+
cactus_stream_transcribe_t _streamTranscribe = nullptr;
|
|
60
77
|
|
|
61
78
|
std::mutex _modelMutex;
|
|
62
79
|
};
|
package/cpp/cactus_ffi.h
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
#include <stdbool.h>
|
|
7
7
|
|
|
8
8
|
#if __GNUC__ >= 4
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
#define CACTUS_FFI_EXPORT __attribute__((visibility("default")))
|
|
10
|
+
#define CACTUS_FFI_LOCAL __attribute__((visibility("hidden")))
|
|
11
11
|
#else
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
#define CACTUS_FFI_EXPORT
|
|
13
|
+
#define CACTUS_FFI_LOCAL
|
|
14
14
|
#endif
|
|
15
15
|
|
|
16
16
|
#ifdef __cplusplus
|
|
@@ -18,20 +18,30 @@ extern "C" {
|
|
|
18
18
|
#endif
|
|
19
19
|
|
|
20
20
|
typedef void* cactus_model_t;
|
|
21
|
+
typedef void* cactus_index_t;
|
|
22
|
+
typedef void* cactus_stream_transcribe_t;
|
|
21
23
|
|
|
22
24
|
typedef void (*cactus_token_callback)(const char* token, uint32_t token_id, void* user_data);
|
|
23
25
|
|
|
24
|
-
CACTUS_FFI_EXPORT cactus_model_t cactus_init(
|
|
26
|
+
CACTUS_FFI_EXPORT cactus_model_t cactus_init(
|
|
27
|
+
const char* model_path,
|
|
28
|
+
const char* corpus_dir, // optional: NULL if no RAG corpus
|
|
29
|
+
bool cache_index // false = always rebuild index, true = load cached if available
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
CACTUS_FFI_EXPORT void cactus_destroy(cactus_model_t model);
|
|
33
|
+
CACTUS_FFI_EXPORT void cactus_reset(cactus_model_t model);
|
|
34
|
+
CACTUS_FFI_EXPORT void cactus_stop(cactus_model_t model);
|
|
25
35
|
|
|
26
36
|
CACTUS_FFI_EXPORT int cactus_complete(
|
|
27
37
|
cactus_model_t model,
|
|
28
38
|
const char* messages_json,
|
|
29
39
|
char* response_buffer,
|
|
30
40
|
size_t buffer_size,
|
|
31
|
-
const char* options_json,
|
|
32
|
-
const char* tools_json,
|
|
33
|
-
cactus_token_callback callback,
|
|
34
|
-
void* user_data
|
|
41
|
+
const char* options_json, // optional
|
|
42
|
+
const char* tools_json, // optional
|
|
43
|
+
cactus_token_callback callback, // optional
|
|
44
|
+
void* user_data // optional
|
|
35
45
|
);
|
|
36
46
|
|
|
37
47
|
CACTUS_FFI_EXPORT int cactus_tokenize(
|
|
@@ -53,20 +63,37 @@ CACTUS_FFI_EXPORT int cactus_score_window(
|
|
|
53
63
|
size_t buffer_size
|
|
54
64
|
);
|
|
55
65
|
|
|
56
|
-
|
|
57
66
|
CACTUS_FFI_EXPORT int cactus_transcribe(
|
|
58
67
|
cactus_model_t model,
|
|
59
|
-
const char* audio_file_path,
|
|
68
|
+
const char* audio_file_path, // NULL if using pcm_buffer
|
|
60
69
|
const char* prompt,
|
|
61
70
|
char* response_buffer,
|
|
62
71
|
size_t buffer_size,
|
|
63
|
-
const char* options_json,
|
|
64
|
-
cactus_token_callback callback,
|
|
65
|
-
void* user_data,
|
|
66
|
-
const uint8_t* pcm_buffer,
|
|
72
|
+
const char* options_json, // optional
|
|
73
|
+
cactus_token_callback callback, // optional
|
|
74
|
+
void* user_data, // optional
|
|
75
|
+
const uint8_t* pcm_buffer, // NULL if using audio_file_path
|
|
67
76
|
size_t pcm_buffer_size
|
|
68
77
|
);
|
|
69
78
|
|
|
79
|
+
CACTUS_FFI_EXPORT cactus_stream_transcribe_t cactus_stream_transcribe_start(
|
|
80
|
+
cactus_model_t model,
|
|
81
|
+
const char* options_json // optional
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
CACTUS_FFI_EXPORT int cactus_stream_transcribe_process(
|
|
85
|
+
cactus_stream_transcribe_t stream,
|
|
86
|
+
const uint8_t* pcm_buffer,
|
|
87
|
+
size_t pcm_buffer_size,
|
|
88
|
+
char* response_buffer,
|
|
89
|
+
size_t buffer_size
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
CACTUS_FFI_EXPORT int cactus_stream_transcribe_stop(
|
|
93
|
+
cactus_stream_transcribe_t stream,
|
|
94
|
+
char* response_buffer,
|
|
95
|
+
size_t buffer_size
|
|
96
|
+
);
|
|
70
97
|
|
|
71
98
|
CACTUS_FFI_EXPORT int cactus_embed(
|
|
72
99
|
cactus_model_t model,
|
|
@@ -93,19 +120,24 @@ CACTUS_FFI_EXPORT int cactus_audio_embed(
|
|
|
93
120
|
size_t* embedding_dim
|
|
94
121
|
);
|
|
95
122
|
|
|
96
|
-
CACTUS_FFI_EXPORT
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
123
|
+
CACTUS_FFI_EXPORT int cactus_vad(
|
|
124
|
+
cactus_model_t model,
|
|
125
|
+
const char* audio_file_path,
|
|
126
|
+
char* response_buffer,
|
|
127
|
+
size_t buffer_size,
|
|
128
|
+
const char* options_json,
|
|
129
|
+
const uint8_t* pcm_buffer,
|
|
130
|
+
size_t pcm_buffer_size
|
|
131
|
+
);
|
|
105
132
|
|
|
106
|
-
CACTUS_FFI_EXPORT
|
|
133
|
+
CACTUS_FFI_EXPORT int cactus_rag_query(
|
|
134
|
+
cactus_model_t model,
|
|
135
|
+
const char* query,
|
|
136
|
+
char* response_buffer,
|
|
137
|
+
size_t buffer_size,
|
|
138
|
+
size_t top_k
|
|
139
|
+
);
|
|
107
140
|
|
|
108
|
-
typedef void* cactus_index_t;
|
|
109
141
|
|
|
110
142
|
CACTUS_FFI_EXPORT cactus_index_t cactus_index_init(
|
|
111
143
|
const char* index_dir,
|
|
@@ -116,7 +148,7 @@ CACTUS_FFI_EXPORT int cactus_index_add(
|
|
|
116
148
|
cactus_index_t index,
|
|
117
149
|
const int* ids,
|
|
118
150
|
const char** documents,
|
|
119
|
-
const char** metadatas,
|
|
151
|
+
const char** metadatas, // optional: can be NULL
|
|
120
152
|
const float** embeddings,
|
|
121
153
|
size_t count,
|
|
122
154
|
size_t embedding_dim
|
|
@@ -145,7 +177,7 @@ CACTUS_FFI_EXPORT int cactus_index_query(
|
|
|
145
177
|
const float** embeddings,
|
|
146
178
|
size_t embeddings_count,
|
|
147
179
|
size_t embedding_dim,
|
|
148
|
-
const char* options_json,
|
|
180
|
+
const char* options_json, // optional
|
|
149
181
|
int** id_buffers,
|
|
150
182
|
size_t* id_buffer_sizes,
|
|
151
183
|
float** score_buffers,
|
|
@@ -153,11 +185,14 @@ CACTUS_FFI_EXPORT int cactus_index_query(
|
|
|
153
185
|
);
|
|
154
186
|
|
|
155
187
|
CACTUS_FFI_EXPORT int cactus_index_compact(cactus_index_t index);
|
|
156
|
-
|
|
157
188
|
CACTUS_FFI_EXPORT void cactus_index_destroy(cactus_index_t index);
|
|
158
189
|
|
|
190
|
+
CACTUS_FFI_EXPORT const char* cactus_get_last_error(void);
|
|
191
|
+
|
|
192
|
+
CACTUS_FFI_EXPORT void cactus_set_telemetry_environment(const char* framework, const char* cache_location);
|
|
193
|
+
|
|
159
194
|
#ifdef __cplusplus
|
|
160
195
|
}
|
|
161
196
|
#endif
|
|
162
197
|
|
|
163
|
-
#endif
|
|
198
|
+
#endif // CACTUS_FFI_H
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
#include <stdbool.h>
|
|
7
7
|
|
|
8
8
|
#if __GNUC__ >= 4
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
#define CACTUS_FFI_EXPORT __attribute__((visibility("default")))
|
|
10
|
+
#define CACTUS_FFI_LOCAL __attribute__((visibility("hidden")))
|
|
11
11
|
#else
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
#define CACTUS_FFI_EXPORT
|
|
13
|
+
#define CACTUS_FFI_LOCAL
|
|
14
14
|
#endif
|
|
15
15
|
|
|
16
16
|
#ifdef __cplusplus
|
|
@@ -18,20 +18,30 @@ extern "C" {
|
|
|
18
18
|
#endif
|
|
19
19
|
|
|
20
20
|
typedef void* cactus_model_t;
|
|
21
|
+
typedef void* cactus_index_t;
|
|
22
|
+
typedef void* cactus_stream_transcribe_t;
|
|
21
23
|
|
|
22
24
|
typedef void (*cactus_token_callback)(const char* token, uint32_t token_id, void* user_data);
|
|
23
25
|
|
|
24
|
-
CACTUS_FFI_EXPORT cactus_model_t cactus_init(
|
|
26
|
+
CACTUS_FFI_EXPORT cactus_model_t cactus_init(
|
|
27
|
+
const char* model_path,
|
|
28
|
+
const char* corpus_dir, // optional: NULL if no RAG corpus
|
|
29
|
+
bool cache_index // false = always rebuild index, true = load cached if available
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
CACTUS_FFI_EXPORT void cactus_destroy(cactus_model_t model);
|
|
33
|
+
CACTUS_FFI_EXPORT void cactus_reset(cactus_model_t model);
|
|
34
|
+
CACTUS_FFI_EXPORT void cactus_stop(cactus_model_t model);
|
|
25
35
|
|
|
26
36
|
CACTUS_FFI_EXPORT int cactus_complete(
|
|
27
37
|
cactus_model_t model,
|
|
28
38
|
const char* messages_json,
|
|
29
39
|
char* response_buffer,
|
|
30
40
|
size_t buffer_size,
|
|
31
|
-
const char* options_json,
|
|
32
|
-
const char* tools_json,
|
|
33
|
-
cactus_token_callback callback,
|
|
34
|
-
void* user_data
|
|
41
|
+
const char* options_json, // optional
|
|
42
|
+
const char* tools_json, // optional
|
|
43
|
+
cactus_token_callback callback, // optional
|
|
44
|
+
void* user_data // optional
|
|
35
45
|
);
|
|
36
46
|
|
|
37
47
|
CACTUS_FFI_EXPORT int cactus_tokenize(
|
|
@@ -53,20 +63,37 @@ CACTUS_FFI_EXPORT int cactus_score_window(
|
|
|
53
63
|
size_t buffer_size
|
|
54
64
|
);
|
|
55
65
|
|
|
56
|
-
|
|
57
66
|
CACTUS_FFI_EXPORT int cactus_transcribe(
|
|
58
67
|
cactus_model_t model,
|
|
59
|
-
const char* audio_file_path,
|
|
68
|
+
const char* audio_file_path, // NULL if using pcm_buffer
|
|
60
69
|
const char* prompt,
|
|
61
70
|
char* response_buffer,
|
|
62
71
|
size_t buffer_size,
|
|
63
|
-
const char* options_json,
|
|
64
|
-
cactus_token_callback callback,
|
|
65
|
-
void* user_data,
|
|
66
|
-
const uint8_t* pcm_buffer,
|
|
72
|
+
const char* options_json, // optional
|
|
73
|
+
cactus_token_callback callback, // optional
|
|
74
|
+
void* user_data, // optional
|
|
75
|
+
const uint8_t* pcm_buffer, // NULL if using audio_file_path
|
|
67
76
|
size_t pcm_buffer_size
|
|
68
77
|
);
|
|
69
78
|
|
|
79
|
+
CACTUS_FFI_EXPORT cactus_stream_transcribe_t cactus_stream_transcribe_start(
|
|
80
|
+
cactus_model_t model,
|
|
81
|
+
const char* options_json // optional
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
CACTUS_FFI_EXPORT int cactus_stream_transcribe_process(
|
|
85
|
+
cactus_stream_transcribe_t stream,
|
|
86
|
+
const uint8_t* pcm_buffer,
|
|
87
|
+
size_t pcm_buffer_size,
|
|
88
|
+
char* response_buffer,
|
|
89
|
+
size_t buffer_size
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
CACTUS_FFI_EXPORT int cactus_stream_transcribe_stop(
|
|
93
|
+
cactus_stream_transcribe_t stream,
|
|
94
|
+
char* response_buffer,
|
|
95
|
+
size_t buffer_size
|
|
96
|
+
);
|
|
70
97
|
|
|
71
98
|
CACTUS_FFI_EXPORT int cactus_embed(
|
|
72
99
|
cactus_model_t model,
|
|
@@ -93,19 +120,24 @@ CACTUS_FFI_EXPORT int cactus_audio_embed(
|
|
|
93
120
|
size_t* embedding_dim
|
|
94
121
|
);
|
|
95
122
|
|
|
96
|
-
CACTUS_FFI_EXPORT
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
123
|
+
CACTUS_FFI_EXPORT int cactus_vad(
|
|
124
|
+
cactus_model_t model,
|
|
125
|
+
const char* audio_file_path,
|
|
126
|
+
char* response_buffer,
|
|
127
|
+
size_t buffer_size,
|
|
128
|
+
const char* options_json,
|
|
129
|
+
const uint8_t* pcm_buffer,
|
|
130
|
+
size_t pcm_buffer_size
|
|
131
|
+
);
|
|
105
132
|
|
|
106
|
-
CACTUS_FFI_EXPORT
|
|
133
|
+
CACTUS_FFI_EXPORT int cactus_rag_query(
|
|
134
|
+
cactus_model_t model,
|
|
135
|
+
const char* query,
|
|
136
|
+
char* response_buffer,
|
|
137
|
+
size_t buffer_size,
|
|
138
|
+
size_t top_k
|
|
139
|
+
);
|
|
107
140
|
|
|
108
|
-
typedef void* cactus_index_t;
|
|
109
141
|
|
|
110
142
|
CACTUS_FFI_EXPORT cactus_index_t cactus_index_init(
|
|
111
143
|
const char* index_dir,
|
|
@@ -116,7 +148,7 @@ CACTUS_FFI_EXPORT int cactus_index_add(
|
|
|
116
148
|
cactus_index_t index,
|
|
117
149
|
const int* ids,
|
|
118
150
|
const char** documents,
|
|
119
|
-
const char** metadatas,
|
|
151
|
+
const char** metadatas, // optional: can be NULL
|
|
120
152
|
const float** embeddings,
|
|
121
153
|
size_t count,
|
|
122
154
|
size_t embedding_dim
|
|
@@ -145,7 +177,7 @@ CACTUS_FFI_EXPORT int cactus_index_query(
|
|
|
145
177
|
const float** embeddings,
|
|
146
178
|
size_t embeddings_count,
|
|
147
179
|
size_t embedding_dim,
|
|
148
|
-
const char* options_json,
|
|
180
|
+
const char* options_json, // optional
|
|
149
181
|
int** id_buffers,
|
|
150
182
|
size_t* id_buffer_sizes,
|
|
151
183
|
float** score_buffers,
|
|
@@ -153,11 +185,14 @@ CACTUS_FFI_EXPORT int cactus_index_query(
|
|
|
153
185
|
);
|
|
154
186
|
|
|
155
187
|
CACTUS_FFI_EXPORT int cactus_index_compact(cactus_index_t index);
|
|
156
|
-
|
|
157
188
|
CACTUS_FFI_EXPORT void cactus_index_destroy(cactus_index_t index);
|
|
158
189
|
|
|
190
|
+
CACTUS_FFI_EXPORT const char* cactus_get_last_error(void);
|
|
191
|
+
|
|
192
|
+
CACTUS_FFI_EXPORT void cactus_set_telemetry_environment(const char* framework, const char* cache_location);
|
|
193
|
+
|
|
159
194
|
#ifdef __cplusplus
|
|
160
195
|
}
|
|
161
196
|
#endif
|
|
162
197
|
|
|
163
|
-
#endif
|
|
198
|
+
#endif // CACTUS_FFI_H
|