cactus-react-native 1.0.2 → 1.2.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 +378 -21
- package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusCrypto.kt +23 -15
- package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusDeviceInfo.kt +12 -9
- package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusFileSystem.kt +42 -41
- package/android/src/main/java/com/margelo/nitro/cactus/HybridCactusImage.kt +81 -0
- package/android/src/main/jniLibs/arm64-v8a/libcactus.a +0 -0
- package/cpp/HybridCactus.cpp +105 -0
- package/cpp/HybridCactus.hpp +13 -0
- package/cpp/cactus_ffi.h +27 -0
- package/ios/HybridCactusImage.swift +53 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus_ffi.h +27 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/engine.h +37 -5
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ffi_utils.h +10 -9
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/graph.h +49 -7
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/kernel.h +31 -0
- package/ios/cactus.xcframework/ios-arm64/cactus.framework/cactus +0 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/cactus_ffi.h +27 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/engine.h +37 -5
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/ffi_utils.h +10 -9
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/graph.h +49 -7
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/Headers/kernel.h +31 -0
- package/ios/cactus.xcframework/ios-arm64-simulator/cactus.framework/cactus +0 -0
- package/lib/module/api/Database.js +23 -0
- package/lib/module/api/Database.js.map +1 -1
- package/lib/module/api/RemoteLM.js +201 -0
- package/lib/module/api/RemoteLM.js.map +1 -0
- package/lib/module/classes/CactusLM.js +52 -26
- package/lib/module/classes/CactusLM.js.map +1 -1
- package/lib/module/classes/CactusSTT.js +139 -0
- package/lib/module/classes/CactusSTT.js.map +1 -0
- package/lib/module/config/CactusConfig.js +4 -0
- package/lib/module/config/CactusConfig.js.map +1 -1
- package/lib/module/constants/packageVersion.js +1 -1
- package/lib/module/hooks/useCactusLM.js +33 -10
- package/lib/module/hooks/useCactusLM.js.map +1 -1
- package/lib/module/hooks/useCactusSTT.js +234 -0
- package/lib/module/hooks/useCactusSTT.js.map +1 -0
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/native/Cactus.js +50 -1
- package/lib/module/native/Cactus.js.map +1 -1
- package/lib/module/native/CactusFileSystem.js +2 -3
- package/lib/module/native/CactusFileSystem.js.map +1 -1
- package/lib/module/native/CactusImage.js +13 -0
- package/lib/module/native/CactusImage.js.map +1 -0
- package/lib/module/native/index.js +1 -0
- package/lib/module/native/index.js.map +1 -1
- package/lib/module/specs/CactusImage.nitro.js +4 -0
- package/lib/module/specs/CactusImage.nitro.js.map +1 -0
- package/lib/module/telemetry/Telemetry.js +53 -1
- package/lib/module/telemetry/Telemetry.js.map +1 -1
- package/lib/module/types/CactusSTT.js +2 -0
- package/lib/module/types/CactusSTT.js.map +1 -0
- package/lib/typescript/src/api/Database.d.ts +1 -0
- package/lib/typescript/src/api/Database.d.ts.map +1 -1
- package/lib/typescript/src/api/RemoteLM.d.ts +14 -0
- package/lib/typescript/src/api/RemoteLM.d.ts.map +1 -0
- package/lib/typescript/src/classes/CactusLM.d.ts +6 -4
- package/lib/typescript/src/classes/CactusLM.d.ts.map +1 -1
- package/lib/typescript/src/classes/CactusSTT.d.ts +26 -0
- package/lib/typescript/src/classes/CactusSTT.d.ts.map +1 -0
- 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/useCactusLM.d.ts +4 -3
- package/lib/typescript/src/hooks/useCactusLM.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useCactusSTT.d.ts +20 -0
- package/lib/typescript/src/hooks/useCactusSTT.d.ts.map +1 -0
- 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 +9 -2
- package/lib/typescript/src/native/Cactus.d.ts.map +1 -1
- package/lib/typescript/src/native/CactusFileSystem.d.ts +1 -1
- package/lib/typescript/src/native/CactusFileSystem.d.ts.map +1 -1
- package/lib/typescript/src/native/CactusImage.d.ts +6 -0
- package/lib/typescript/src/native/CactusImage.d.ts.map +1 -0
- 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 +3 -0
- package/lib/typescript/src/specs/Cactus.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/CactusImage.nitro.d.ts +9 -0
- package/lib/typescript/src/specs/CactusImage.nitro.d.ts.map +1 -0
- package/lib/typescript/src/telemetry/Telemetry.d.ts +5 -1
- package/lib/typescript/src/telemetry/Telemetry.d.ts.map +1 -1
- package/lib/typescript/src/types/CactusLM.d.ts +8 -5
- package/lib/typescript/src/types/CactusLM.d.ts.map +1 -1
- package/lib/typescript/src/types/CactusSTT.d.ts +37 -0
- package/lib/typescript/src/types/CactusSTT.d.ts.map +1 -0
- package/nitro.json +4 -0
- package/nitrogen/generated/android/c++/JHybridCactusImageSpec.cpp +81 -0
- package/nitrogen/generated/android/c++/JHybridCactusImageSpec.hpp +66 -0
- package/nitrogen/generated/android/cactus+autolinking.cmake +2 -0
- package/nitrogen/generated/android/cactusOnLoad.cpp +10 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/cactus/HybridCactusImageSpec.kt +62 -0
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.cpp +17 -0
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Bridge.hpp +17 -0
- package/nitrogen/generated/ios/Cactus-Swift-Cxx-Umbrella.hpp +5 -0
- package/nitrogen/generated/ios/CactusAutolinking.mm +8 -0
- package/nitrogen/generated/ios/CactusAutolinking.swift +15 -0
- package/nitrogen/generated/ios/c++/HybridCactusImageSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridCactusImageSpecSwift.hpp +85 -0
- package/nitrogen/generated/ios/swift/HybridCactusImageSpec.swift +58 -0
- package/nitrogen/generated/ios/swift/HybridCactusImageSpec_cxx.swift +158 -0
- package/nitrogen/generated/shared/c++/HybridCactusImageSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridCactusImageSpec.hpp +64 -0
- package/nitrogen/generated/shared/c++/HybridCactusSpec.cpp +3 -0
- package/nitrogen/generated/shared/c++/HybridCactusSpec.hpp +3 -0
- package/package.json +1 -1
- package/src/api/Database.ts +27 -0
- package/src/api/RemoteLM.ts +273 -0
- package/src/classes/CactusLM.ts +72 -38
- package/src/classes/CactusSTT.ts +188 -0
- package/src/config/CactusConfig.ts +4 -0
- package/src/constants/packageVersion.ts +1 -1
- package/src/hooks/useCactusLM.ts +45 -17
- package/src/hooks/useCactusSTT.ts +285 -0
- package/src/index.tsx +14 -2
- package/src/native/Cactus.ts +94 -4
- package/src/native/CactusFileSystem.ts +2 -2
- package/src/native/CactusImage.ts +20 -0
- package/src/native/index.ts +1 -0
- package/src/specs/Cactus.nitro.ts +9 -0
- package/src/specs/CactusImage.nitro.ts +12 -0
- package/src/telemetry/Telemetry.ts +78 -1
- package/src/types/CactusLM.ts +9 -5
- package/src/types/CactusSTT.ts +42 -0
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
import { CactusConfig } from '../config/CactusConfig';
|
|
9
9
|
import { packageVersion } from '../constants/packageVersion';
|
|
10
10
|
import type { CactusLMCompleteResult } from '../types/CactusLM';
|
|
11
|
+
import type { CactusSTTTranscribeResult } from '../types/CactusSTT';
|
|
11
12
|
|
|
12
13
|
export interface LogRecord {
|
|
13
14
|
// Framework
|
|
@@ -15,7 +16,13 @@ export interface LogRecord {
|
|
|
15
16
|
framework_version: string;
|
|
16
17
|
|
|
17
18
|
// Event
|
|
18
|
-
event_type:
|
|
19
|
+
event_type:
|
|
20
|
+
| 'init'
|
|
21
|
+
| 'completion'
|
|
22
|
+
| 'transcription'
|
|
23
|
+
| 'embedding'
|
|
24
|
+
| 'image_embedding'
|
|
25
|
+
| 'audio_embedding';
|
|
19
26
|
model: string;
|
|
20
27
|
success: boolean;
|
|
21
28
|
message?: string;
|
|
@@ -41,10 +48,17 @@ export class Telemetry {
|
|
|
41
48
|
private static readonly logBufferPaths = {
|
|
42
49
|
init: 'logs/init.json',
|
|
43
50
|
completion: 'logs/completion.json',
|
|
51
|
+
transcription: 'logs/transcription.json',
|
|
44
52
|
embedding: 'logs/embedding.json',
|
|
53
|
+
image_embedding: 'logs/image_embedding.json',
|
|
54
|
+
audio_embedding: 'logs/audio_embedding.json',
|
|
45
55
|
};
|
|
46
56
|
|
|
47
57
|
private static async handleLog(logRecord: LogRecord) {
|
|
58
|
+
if (!this.isInitialized()) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
48
62
|
if (!CactusConfig.isTelemetryEnabled) {
|
|
49
63
|
return;
|
|
50
64
|
}
|
|
@@ -78,6 +92,10 @@ export class Telemetry {
|
|
|
78
92
|
}
|
|
79
93
|
|
|
80
94
|
public static async init(cactusTelemetryToken?: string): Promise<void> {
|
|
95
|
+
if (this.isInitialized()) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
81
99
|
if (!CactusConfig.isTelemetryEnabled) {
|
|
82
100
|
return;
|
|
83
101
|
}
|
|
@@ -139,6 +157,29 @@ export class Telemetry {
|
|
|
139
157
|
});
|
|
140
158
|
}
|
|
141
159
|
|
|
160
|
+
public static logTranscribe(
|
|
161
|
+
model: string,
|
|
162
|
+
success: boolean,
|
|
163
|
+
message?: string,
|
|
164
|
+
result?: CactusSTTTranscribeResult
|
|
165
|
+
): Promise<void> {
|
|
166
|
+
return this.handleLog({
|
|
167
|
+
framework: 'react-native',
|
|
168
|
+
framework_version: packageVersion,
|
|
169
|
+
event_type: 'transcription',
|
|
170
|
+
model,
|
|
171
|
+
success,
|
|
172
|
+
message,
|
|
173
|
+
telemetry_token: this.cactusTelemetryToken,
|
|
174
|
+
project_id: this.projectId,
|
|
175
|
+
device_id: this.deviceId,
|
|
176
|
+
tokens: result?.totalTokens,
|
|
177
|
+
response_time: result?.totalTimeMs,
|
|
178
|
+
ttft: result?.timeToFirstTokenMs,
|
|
179
|
+
tps: result?.tokensPerSecond,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
142
183
|
public static logEmbedding(
|
|
143
184
|
model: string,
|
|
144
185
|
success: boolean,
|
|
@@ -156,4 +197,40 @@ export class Telemetry {
|
|
|
156
197
|
device_id: this.deviceId,
|
|
157
198
|
});
|
|
158
199
|
}
|
|
200
|
+
|
|
201
|
+
public static logImageEmbedding(
|
|
202
|
+
model: string,
|
|
203
|
+
success: boolean,
|
|
204
|
+
message?: string
|
|
205
|
+
): Promise<void> {
|
|
206
|
+
return this.handleLog({
|
|
207
|
+
framework: 'react-native',
|
|
208
|
+
framework_version: packageVersion,
|
|
209
|
+
event_type: 'image_embedding',
|
|
210
|
+
model,
|
|
211
|
+
success,
|
|
212
|
+
message,
|
|
213
|
+
telemetry_token: this.cactusTelemetryToken,
|
|
214
|
+
project_id: this.projectId,
|
|
215
|
+
device_id: this.deviceId,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
public static logAudioEmbedding(
|
|
220
|
+
model: string,
|
|
221
|
+
success: boolean,
|
|
222
|
+
message?: string
|
|
223
|
+
): Promise<void> {
|
|
224
|
+
return this.handleLog({
|
|
225
|
+
framework: 'react-native',
|
|
226
|
+
framework_version: packageVersion,
|
|
227
|
+
event_type: 'audio_embedding',
|
|
228
|
+
model,
|
|
229
|
+
success,
|
|
230
|
+
message,
|
|
231
|
+
telemetry_token: this.cactusTelemetryToken,
|
|
232
|
+
project_id: this.projectId,
|
|
233
|
+
device_id: this.deviceId,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
159
236
|
}
|
package/src/types/CactusLM.ts
CHANGED
|
@@ -14,7 +14,7 @@ export interface Message {
|
|
|
14
14
|
images?: string[];
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export interface
|
|
17
|
+
export interface CompleteOptions {
|
|
18
18
|
temperature?: number;
|
|
19
19
|
topP?: number;
|
|
20
20
|
topK?: number;
|
|
@@ -23,7 +23,6 @@ export interface Options {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export interface Tool {
|
|
26
|
-
type: 'function';
|
|
27
26
|
name: string;
|
|
28
27
|
description: string;
|
|
29
28
|
parameters: {
|
|
@@ -40,9 +39,10 @@ export interface Tool {
|
|
|
40
39
|
|
|
41
40
|
export interface CactusLMCompleteParams {
|
|
42
41
|
messages: Message[];
|
|
43
|
-
options?:
|
|
42
|
+
options?: CompleteOptions;
|
|
44
43
|
tools?: Tool[];
|
|
45
44
|
onToken?: (token: string) => void;
|
|
45
|
+
mode?: 'local' | 'hybrid';
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export interface CactusLMCompleteResult {
|
|
@@ -68,6 +68,10 @@ export interface CactusLMEmbedResult {
|
|
|
68
68
|
embedding: number[];
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
export interface
|
|
72
|
-
|
|
71
|
+
export interface CactusLMImageEmbedParams {
|
|
72
|
+
imagePath: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface CactusLMImageEmbedResult {
|
|
76
|
+
embedding: number[];
|
|
73
77
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export interface CactusSTTParams {
|
|
2
|
+
model?: string;
|
|
3
|
+
contextSize?: number;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface CactusSTTDownloadParams {
|
|
7
|
+
onProgress?: (progress: number) => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface TranscribeOptions {
|
|
11
|
+
temperature?: number;
|
|
12
|
+
topP?: number;
|
|
13
|
+
topK?: number;
|
|
14
|
+
maxTokens?: number;
|
|
15
|
+
stopSequences?: string[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface CactusSTTTranscribeParams {
|
|
19
|
+
audioFilePath: string;
|
|
20
|
+
prompt?: string;
|
|
21
|
+
options?: TranscribeOptions;
|
|
22
|
+
onToken?: (token: string) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface CactusSTTTranscribeResult {
|
|
26
|
+
success: boolean;
|
|
27
|
+
response: string;
|
|
28
|
+
timeToFirstTokenMs: number;
|
|
29
|
+
totalTimeMs: number;
|
|
30
|
+
tokensPerSecond: number;
|
|
31
|
+
prefillTokens: number;
|
|
32
|
+
decodeTokens: number;
|
|
33
|
+
totalTokens: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface CactusSTTAudioEmbedParams {
|
|
37
|
+
audioPath: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface CactusSTTAudioEmbedResult {
|
|
41
|
+
embedding: number[];
|
|
42
|
+
}
|