cactus-react-native 0.1.3 → 0.2.1

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.
Files changed (79) hide show
  1. package/README.md +551 -720
  2. package/android/src/main/java/com/cactus/Cactus.java +41 -0
  3. package/android/src/main/java/com/cactus/LlamaContext.java +19 -0
  4. package/android/src/newarch/java/com/cactus/CactusModule.java +5 -0
  5. package/android/src/oldarch/java/com/cactus/CactusModule.java +5 -0
  6. package/ios/Cactus.mm +14 -0
  7. package/ios/CactusContext.h +1 -0
  8. package/ios/CactusContext.mm +18 -0
  9. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/cactus +0 -0
  10. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/cactus +0 -0
  11. package/lib/commonjs/NativeCactus.js +10 -0
  12. package/lib/commonjs/NativeCactus.js.map +1 -1
  13. package/lib/commonjs/chat.js +37 -0
  14. package/lib/commonjs/grammar.js +560 -0
  15. package/lib/commonjs/index.js +545 -0
  16. package/lib/commonjs/index.js.map +1 -1
  17. package/lib/commonjs/lm.js +106 -0
  18. package/lib/commonjs/lm.js.map +1 -1
  19. package/lib/commonjs/projectId.js +8 -0
  20. package/lib/commonjs/projectId.js.map +1 -0
  21. package/lib/commonjs/remote.js +153 -0
  22. package/lib/commonjs/remote.js.map +1 -0
  23. package/lib/commonjs/telemetry.js +103 -0
  24. package/lib/commonjs/telemetry.js.map +1 -0
  25. package/lib/commonjs/tools.js +79 -0
  26. package/lib/commonjs/tools.js.map +1 -0
  27. package/lib/commonjs/tts.js +32 -0
  28. package/lib/commonjs/tts.js.map +1 -1
  29. package/lib/commonjs/vlm.js +150 -0
  30. package/lib/commonjs/vlm.js.map +1 -0
  31. package/lib/module/NativeCactus.js +8 -0
  32. package/lib/module/NativeCactus.js.map +1 -1
  33. package/lib/module/chat.js +33 -0
  34. package/lib/module/grammar.js +553 -0
  35. package/lib/module/index.js +435 -0
  36. package/lib/module/index.js.map +1 -1
  37. package/lib/module/lm.js +101 -0
  38. package/lib/module/lm.js.map +1 -0
  39. package/lib/module/projectId.js +4 -0
  40. package/lib/module/projectId.js.map +1 -0
  41. package/lib/module/remote.js +144 -0
  42. package/lib/module/remote.js.map +1 -0
  43. package/lib/module/telemetry.js +98 -0
  44. package/lib/module/telemetry.js.map +1 -0
  45. package/lib/module/tools.js +73 -0
  46. package/lib/module/tools.js.map +1 -0
  47. package/lib/module/tts.js +27 -0
  48. package/lib/module/tts.js.map +1 -1
  49. package/lib/module/vlm.js +145 -0
  50. package/lib/module/vlm.js.map +1 -1
  51. package/lib/typescript/NativeCactus.d.ts +7 -0
  52. package/lib/typescript/NativeCactus.d.ts.map +1 -1
  53. package/lib/typescript/index.d.ts +3 -1
  54. package/lib/typescript/index.d.ts.map +1 -1
  55. package/lib/typescript/lm.d.ts +11 -34
  56. package/lib/typescript/lm.d.ts.map +1 -1
  57. package/lib/typescript/projectId.d.ts +2 -0
  58. package/lib/typescript/projectId.d.ts.map +1 -0
  59. package/lib/typescript/remote.d.ts +7 -0
  60. package/lib/typescript/remote.d.ts.map +1 -0
  61. package/lib/typescript/telemetry.d.ts +25 -0
  62. package/lib/typescript/telemetry.d.ts.map +1 -0
  63. package/lib/typescript/tools.d.ts +0 -3
  64. package/lib/typescript/tools.d.ts.map +1 -1
  65. package/lib/typescript/tts.d.ts.map +1 -1
  66. package/lib/typescript/vlm.d.ts +14 -34
  67. package/lib/typescript/vlm.d.ts.map +1 -1
  68. package/package.json +4 -4
  69. package/scripts/postInstall.js +33 -0
  70. package/src/NativeCactus.ts +7 -0
  71. package/src/index.ts +122 -46
  72. package/src/lm.ts +80 -5
  73. package/src/projectId.ts +1 -0
  74. package/src/remote.ts +175 -0
  75. package/src/telemetry.ts +138 -0
  76. package/src/tools.ts +17 -58
  77. package/src/vlm.ts +129 -8
  78. package/android/src/main/jniLibs/x86_64/libcactus.so +0 -0
  79. package/android/src/main/jniLibs/x86_64/libcactus_x86_64.so +0 -0
@@ -2,6 +2,7 @@ package com.cactus;
2
2
 
3
3
  import androidx.annotation.NonNull;
4
4
  import android.util.Log;
5
+ import android.provider.Settings;
5
6
  import android.os.Build;
6
7
  import android.os.Handler;
7
8
  import android.os.AsyncTask;
@@ -1080,6 +1081,46 @@ public class Cactus implements LifecycleEventListener {
1080
1081
  tasks.put(task, "decodeAudioTokens-" + contextId);
1081
1082
  }
1082
1083
 
1084
+ @ReactMethod
1085
+ public void getDeviceInfo(double id, final Promise promise) {
1086
+ AsyncTask task = new AsyncTask<Void, Void, WritableMap>() {
1087
+ private Exception exception;
1088
+
1089
+ @Override
1090
+ protected WritableMap doInBackground(Void... voids) {
1091
+ try {
1092
+ WritableMap deviceInfo = Arguments.createMap();
1093
+
1094
+ String deviceId = Settings.Secure.getString(reactContext.getContentResolver(), Settings.Secure.ANDROID_ID);
1095
+
1096
+ String make = Build.MANUFACTURER;
1097
+ String model = Build.MODEL;
1098
+ String osVersion = Build.VERSION.RELEASE;
1099
+
1100
+ deviceInfo.putString("deviceId", deviceId);
1101
+ deviceInfo.putString("make", make);
1102
+ deviceInfo.putString("model", model);
1103
+ deviceInfo.putString("os", "Android");
1104
+ deviceInfo.putString("osVersion", osVersion);
1105
+
1106
+ return deviceInfo;
1107
+ } catch (Exception e) {
1108
+ exception = e;
1109
+ }
1110
+ return null;
1111
+ }
1112
+
1113
+ @Override
1114
+ protected void onPostExecute(WritableMap result) {
1115
+ if (exception != null) {
1116
+ promise.reject(exception);
1117
+ return;
1118
+ }
1119
+ promise.resolve(result);
1120
+ }
1121
+ }.executeOnExecutor(singleThreadExecutor);
1122
+ }
1123
+
1083
1124
  public void releaseVocoder(double id, final Promise promise) {
1084
1125
  final int contextId = (int) id;
1085
1126
  AsyncTask task = new AsyncTask<Void, Void, Void>() {
@@ -9,6 +9,7 @@ import com.facebook.react.bridge.ReactApplicationContext;
9
9
  import com.facebook.react.modules.core.DeviceEventManagerModule;
10
10
 
11
11
  import android.util.Log;
12
+ import android.provider.Settings;
12
13
  import android.os.Build;
13
14
  import android.content.res.AssetManager;
14
15
 
@@ -520,6 +521,24 @@ public class LlamaContext {
520
521
  return decodeAudioTokens(this.context, toks);
521
522
  }
522
523
 
524
+ public WritableMap getDeviceInfo() {
525
+ WritableMap deviceInfo = Arguments.createMap();
526
+
527
+ String deviceId = Settings.Secure.getString(this.reactContext.getContentResolver(), Settings.Secure.ANDROID_ID);
528
+
529
+ String make = Build.MANUFACTURER;
530
+ String model = Build.MODEL;
531
+ String osVersion = Build.VERSION.RELEASE;
532
+
533
+ deviceInfo.putString("deviceId", deviceId);
534
+ deviceInfo.putString("make", make);
535
+ deviceInfo.putString("model", model);
536
+ deviceInfo.putString("os", "Android");
537
+ deviceInfo.putString("osVersion", osVersion);
538
+
539
+ return deviceInfo;
540
+ }
541
+
523
542
  public void releaseVocoder() {
524
543
  releaseVocoder(this.context);
525
544
  }
@@ -179,6 +179,11 @@ public class CactusModule extends NativeCactusSpec {
179
179
  cactus.decodeAudioTokens(id, tokens, promise);
180
180
  }
181
181
 
182
+ @ReactMethod
183
+ public void getDeviceInfo(double id, Promise promise) {
184
+ cactus.getDeviceInfo(id, promise);
185
+ }
186
+
182
187
  @ReactMethod
183
188
  public void releaseVocoder(double id, Promise promise) {
184
189
  cactus.releaseVocoder(id, promise);
@@ -178,6 +178,11 @@ public class CactusModule extends ReactContextBaseJavaModule {
178
178
  cactus.decodeAudioTokens(id, tokens, promise);
179
179
  }
180
180
 
181
+ @ReactMethod
182
+ public void getDeviceInfo(double id, final Promise promise) {
183
+ cactus.getDeviceInfo(id, promise);
184
+ }
185
+
181
186
  @ReactMethod
182
187
  public void releaseVocoder(double id, final Promise promise) {
183
188
  cactus.releaseVocoder(id, promise);
package/ios/Cactus.mm CHANGED
@@ -597,6 +597,20 @@ RCT_EXPORT_METHOD(decodeAudioTokens:(double)contextId
597
597
  }
598
598
  }
599
599
 
600
+ RCT_EXPORT_METHOD(getDeviceInfo:(double)contextId
601
+ withResolver:(RCTPromiseResolveBlock)resolve
602
+ withRejecter:(RCTPromiseRejectBlock)reject)
603
+ {
604
+ CactusContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
605
+ if (context == nil) {
606
+ reject(@"llama_error", @"Context not found", nil);
607
+ return;
608
+ }
609
+ NSDictionary *deviceInfo = [context getDeviceInfo];
610
+ resolve(deviceInfo);
611
+ }
612
+
613
+
600
614
  RCT_EXPORT_METHOD(releaseVocoder:(double)contextId
601
615
  withResolver:(RCTPromiseResolveBlock)resolve
602
616
  withRejecter:(RCTPromiseRejectBlock)reject)
@@ -72,6 +72,7 @@
72
72
  - (NSString *)getFormattedAudioCompletion:(NSString *)speakerJsonStr textToSpeak:(NSString *)textToSpeak;
73
73
  - (NSArray *)getAudioCompletionGuideTokens:(NSString *)textToSpeak;
74
74
  - (NSArray *)decodeAudioTokens:(NSArray *)tokens;
75
+ - (NSDictionary *)getDeviceInfo;
75
76
  - (void)releaseVocoder;
76
77
 
77
78
  - (void)invalidate;
@@ -1,5 +1,6 @@
1
1
  #import "CactusContext.h"
2
2
  #import <Metal/Metal.h>
3
+ #import <sys/utsname.h>
3
4
 
4
5
  @implementation CactusContext
5
6
 
@@ -1007,4 +1008,21 @@
1007
1008
  return result;
1008
1009
  }
1009
1010
 
1011
+ - (NSDictionary *)getDeviceInfo {
1012
+ UIDevice *device = [UIDevice currentDevice];
1013
+ NSString *deviceId = [[device identifierForVendor] UUIDString];
1014
+ struct utsname systemInfo;
1015
+ uname(&systemInfo);
1016
+ NSString *model = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
1017
+ NSString *os = [device systemName];
1018
+ NSDictionary *deviceInfo = @{
1019
+ @"deviceId": deviceId,
1020
+ @"model": model,
1021
+ @"make": @"Apple",
1022
+ @"os": os
1023
+ };
1024
+
1025
+ return deviceInfo;
1026
+ }
1027
+
1010
1028
  @end
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _reactNative = require("react-native");
8
+ // New TTS/Audio types
9
+ var _default = exports.default = _reactNative.TurboModuleRegistry.get('Cactus');
10
+ //# sourceMappingURL=NativeCactus.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","get"],"sourceRoot":"../../src","sources":["NativeCactus.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAkSA;AAAA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GA2LeC,gCAAmB,CAACC,GAAG,CAAO,QAAQ,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","get"],"sourceRoot":"../../src","sources":["NativeCactus.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAkSA;AAAA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAkMeC,gCAAmB,CAACC,GAAG,CAAO,QAAQ,CAAC","ignoreList":[]}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.formatChat = formatChat;
7
+ function formatChat(messages) {
8
+ const chat = [];
9
+ messages.forEach(currMsg => {
10
+ const role = currMsg.role || '';
11
+ let content = '';
12
+ if ('content' in currMsg) {
13
+ if (typeof currMsg.content === 'string') {
14
+ ;
15
+ ({
16
+ content
17
+ } = currMsg);
18
+ } else if (Array.isArray(currMsg.content)) {
19
+ currMsg.content.forEach(part => {
20
+ if ('text' in part) {
21
+ content += `${content ? '\n' : ''}${part.text}`;
22
+ }
23
+ });
24
+ } else {
25
+ throw new TypeError("Invalid 'content' type (ref: https://github.com/ggerganov/llama.cpp/issues/8367)");
26
+ }
27
+ } else {
28
+ throw new Error("Missing 'content' (ref: https://github.com/ggerganov/llama.cpp/issues/8367)");
29
+ }
30
+ chat.push({
31
+ role,
32
+ content
33
+ });
34
+ });
35
+ return chat;
36
+ }
37
+ //# sourceMappingURL=chat.js.map