react-native-executorch 0.5.1-rc.0 → 0.5.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 (88) hide show
  1. package/README.md +132 -0
  2. package/common/rnexecutorch/models/speech_to_text/SpeechToText.cpp +4 -10
  3. package/common/rnexecutorch/models/speech_to_text/SpeechToText.h +1 -1
  4. package/common/rnexecutorch/models/speech_to_text/SpeechToTextStrategy.h +3 -2
  5. package/common/rnexecutorch/models/speech_to_text/WhisperStrategy.cpp +16 -4
  6. package/common/rnexecutorch/models/speech_to_text/WhisperStrategy.h +2 -2
  7. package/ios/RnExecutorch.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  8. package/ios/RnExecutorch.xcodeproj/project.xcworkspace/xcuserdata/jakubchmura.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  9. package/ios/RnExecutorch.xcodeproj/xcuserdata/jakubchmura.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  10. package/lib/module/constants/modelUrls.js +61 -36
  11. package/lib/module/constants/modelUrls.js.map +1 -1
  12. package/lib/module/constants/ocr/models.js +1 -1
  13. package/lib/module/hooks/natural_language_processing/useSpeechToText.js +71 -34
  14. package/lib/module/hooks/natural_language_processing/useSpeechToText.js.map +1 -1
  15. package/lib/module/index.js +2 -3
  16. package/lib/module/index.js.map +1 -1
  17. package/lib/module/modules/natural_language_processing/SpeechToTextModule.js +72 -31
  18. package/lib/module/modules/natural_language_processing/SpeechToTextModule.js.map +1 -1
  19. package/lib/module/types/stt.js +1 -85
  20. package/lib/module/types/stt.js.map +1 -1
  21. package/lib/module/utils/SpeechToTextModule/ASR.js +191 -0
  22. package/lib/module/utils/SpeechToTextModule/ASR.js.map +1 -0
  23. package/lib/module/utils/SpeechToTextModule/OnlineProcessor.js +73 -0
  24. package/lib/module/utils/SpeechToTextModule/OnlineProcessor.js.map +1 -0
  25. package/lib/module/utils/SpeechToTextModule/hypothesisBuffer.js +56 -0
  26. package/lib/module/utils/SpeechToTextModule/hypothesisBuffer.js.map +1 -0
  27. package/lib/tsconfig.tsbuildinfo +1 -0
  28. package/lib/typescript/constants/modelUrls.d.ts +24 -7
  29. package/lib/typescript/constants/modelUrls.d.ts.map +1 -1
  30. package/lib/typescript/constants/ocr/models.d.ts +126 -126
  31. package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts +15 -24
  32. package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts.map +1 -1
  33. package/lib/typescript/index.d.ts +2 -3
  34. package/lib/typescript/index.d.ts.map +1 -1
  35. package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts +19 -22
  36. package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts.map +1 -1
  37. package/lib/typescript/types/stt.d.ts +17 -91
  38. package/lib/typescript/types/stt.d.ts.map +1 -1
  39. package/lib/typescript/utils/SpeechToTextModule/ASR.d.ts +27 -0
  40. package/lib/typescript/utils/SpeechToTextModule/ASR.d.ts.map +1 -0
  41. package/lib/typescript/utils/SpeechToTextModule/OnlineProcessor.d.ts +23 -0
  42. package/lib/typescript/utils/SpeechToTextModule/OnlineProcessor.d.ts.map +1 -0
  43. package/lib/typescript/utils/SpeechToTextModule/hypothesisBuffer.d.ts +13 -0
  44. package/lib/typescript/utils/SpeechToTextModule/hypothesisBuffer.d.ts.map +1 -0
  45. package/package.json +5 -3
  46. package/src/constants/modelUrls.ts +70 -37
  47. package/src/constants/ocr/models.ts +1 -1
  48. package/src/hooks/natural_language_processing/useSpeechToText.ts +87 -92
  49. package/src/index.ts +6 -8
  50. package/src/modules/natural_language_processing/SpeechToTextModule.ts +81 -69
  51. package/src/types/stt.ts +97 -92
  52. package/src/utils/SpeechToTextModule/ASR.ts +303 -0
  53. package/src/utils/SpeechToTextModule/OnlineProcessor.ts +87 -0
  54. package/src/utils/SpeechToTextModule/hypothesisBuffer.ts +79 -0
  55. package/third-party/ios/ExecutorchLib/ExecutorchLib.xcodeproj/project.xcworkspace/xcuserdata/jakubchmura.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  56. package/common/rnexecutorch/models/speech_to_text/MoonshineStrategy.cpp +0 -31
  57. package/common/rnexecutorch/models/speech_to_text/MoonshineStrategy.h +0 -21
  58. package/lib/common/Logger.d.ts +0 -8
  59. package/lib/common/Logger.js +0 -19
  60. package/lib/constants/modelUrls.d.ts +0 -89
  61. package/lib/constants/modelUrls.js +0 -116
  62. package/lib/constants/sttDefaults.js +0 -66
  63. package/lib/controllers/LLMController.js +0 -210
  64. package/lib/controllers/OCRController.js +0 -65
  65. package/lib/controllers/SpeechToTextController.d.ts +0 -52
  66. package/lib/controllers/SpeechToTextController.js +0 -343
  67. package/lib/hooks/natural_language_processing/useSpeechToText.js +0 -44
  68. package/lib/index.d.ts +0 -50
  69. package/lib/index.js +0 -59
  70. package/lib/module/constants/sttDefaults.js +0 -74
  71. package/lib/module/constants/sttDefaults.js.map +0 -1
  72. package/lib/module/controllers/SpeechToTextController.js +0 -320
  73. package/lib/module/controllers/SpeechToTextController.js.map +0 -1
  74. package/lib/modules/natural_language_processing/SpeechToTextModule.d.ts +0 -14
  75. package/lib/modules/natural_language_processing/SpeechToTextModule.js +0 -30
  76. package/lib/modules/natural_language_processing/TokenizerModule.js +0 -29
  77. package/lib/native/RnExecutorchModules.d.ts +0 -3
  78. package/lib/native/RnExecutorchModules.js +0 -16
  79. package/lib/typescript/constants/sttDefaults.d.ts +0 -29
  80. package/lib/typescript/constants/sttDefaults.d.ts.map +0 -1
  81. package/lib/typescript/controllers/SpeechToTextController.d.ts +0 -57
  82. package/lib/typescript/controllers/SpeechToTextController.d.ts.map +0 -1
  83. package/lib/utils/ResourceFetcherUtils.js +0 -119
  84. package/lib/utils/llm.js +0 -72
  85. package/src/constants/sttDefaults.ts +0 -82
  86. package/src/controllers/SpeechToTextController.ts +0 -471
  87. package/third-party/ios/ExecutorchLib/ExecutorchLib.xcodeproj/project.xcworkspace/xcuserdata/norbertklockiewicz.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  88. /package/third-party/ios/ExecutorchLib/ExecutorchLib.xcodeproj/xcuserdata/{norbertklockiewicz.xcuserdatad → jakubchmura.xcuserdatad}/xcschemes/xcschememanagement.plist +0 -0
@@ -1,116 +0,0 @@
1
- import { Platform } from 'react-native';
2
- // LLM's
3
- // LLAMA 3.2
4
- export const LLAMA3_2_3B = 'https://huggingface.co/software-mansion/react-native-executorch-llama-3.2/resolve/v0.4.0/llama-3.2-3B/original/llama3_2_3B_bf16.pte';
5
- export const LLAMA3_2_3B_QLORA = 'https://huggingface.co/software-mansion/react-native-executorch-llama-3.2/resolve/v0.4.0/llama-3.2-3B/QLoRA/llama3_2-3B_qat_lora.pte';
6
- export const LLAMA3_2_3B_SPINQUANT = 'https://huggingface.co/software-mansion/react-native-executorch-llama-3.2/resolve/v0.4.0/llama-3.2-3B/spinquant/llama3_2_3B_spinquant.pte';
7
- export const LLAMA3_2_1B = 'https://huggingface.co/software-mansion/react-native-executorch-llama-3.2/resolve/v0.4.0/llama-3.2-1B/original/llama3_2_bf16.pte';
8
- export const LLAMA3_2_1B_QLORA = 'https://huggingface.co/software-mansion/react-native-executorch-llama-3.2/resolve/v0.4.0/llama-3.2-1B/QLoRA/llama3_2_qat_lora.pte';
9
- export const LLAMA3_2_1B_SPINQUANT = 'https://huggingface.co/software-mansion/react-native-executorch-llama-3.2/resolve/v0.4.0/llama-3.2-1B/spinquant/llama3_2_spinquant.pte';
10
- export const LLAMA3_2_TOKENIZER = 'https://huggingface.co/software-mansion/react-native-executorch-llama-3.2/resolve/v0.4.0/tokenizer.json';
11
- export const LLAMA3_2_TOKENIZER_CONFIG = 'https://huggingface.co/software-mansion/react-native-executorch-llama-3.2/resolve/v0.4.0/tokenizer_config.json';
12
- // QWEN 3
13
- export const QWEN3_0_6B = 'https://huggingface.co/software-mansion/react-native-executorch-qwen-3/resolve/v0.4.0/qwen-3-0.6B/original/qwen3_0_6b_bf16.pte';
14
- export const QWEN3_0_6B_QUANTIZED = 'https://huggingface.co/software-mansion/react-native-executorch-qwen-3/resolve/v0.4.0/qwen-3-0.6B/quantized/qwen3_0_6b_8da4w.pte';
15
- export const QWEN3_1_7B = 'https://huggingface.co/software-mansion/react-native-executorch-qwen-3/resolve/v0.4.0/qwen-3-1.7B/original/qwen3_1_7b_bf16.pte';
16
- export const QWEN3_1_7B_QUANTIZED = 'https://huggingface.co/software-mansion/react-native-executorch-qwen-3/resolve/v0.4.0/qwen-3-1.7B/quantized/qwen3_1_7b_8da4w.pte';
17
- export const QWEN3_4B = 'https://huggingface.co/software-mansion/react-native-executorch-qwen-3/resolve/v0.4.0/qwen-3-4B/original/qwen3_4b_bf16.pte';
18
- export const QWEN3_4B_QUANTIZED = 'https://huggingface.co/software-mansion/react-native-executorch-qwen-3/resolve/v0.4.0/qwen-3-4B/quantized/qwen3_4b_8da4w.pte';
19
- export const QWEN3_TOKENIZER = 'https://huggingface.co/software-mansion/react-native-executorch-qwen-3/resolve/v0.4.0/tokenizer.json';
20
- export const QWEN3_TOKENIZER_CONFIG = 'https://huggingface.co/software-mansion/react-native-executorch-qwen-3/resolve/v0.4.0/tokenizer_config.json';
21
- // HAMMER 2.1
22
- export const HAMMER2_1_0_5B = 'https://huggingface.co/software-mansion/react-native-executorch-hammer-2.1/resolve/v0.4.0/hammer-2.1-0.5B/original/hammer2_1_0_5B_bf16.pte';
23
- export const HAMMER2_1_0_5B_QUANTIZED = 'https://huggingface.co/software-mansion/react-native-executorch-hammer-2.1/resolve/v0.4.0/hammer-2.1-0.5B/quantized/hammer2_1_0_5B_8da4w.pte';
24
- export const HAMMER2_1_1_5B = 'https://huggingface.co/software-mansion/react-native-executorch-hammer-2.1/resolve/v0.4.0/hammer-2.1-1.5B/original/hammer2_1_1_5B_bf16.pte';
25
- export const HAMMER2_1_1_5B_QUANTIZED = 'https://huggingface.co/software-mansion/react-native-executorch-hammer-2.1/resolve/v0.4.0/hammer-2.1-1.5B/quantized/hammer2_1_1_5B_8da4w.pte';
26
- export const HAMMER2_1_3B = 'https://huggingface.co/software-mansion/react-native-executorch-hammer-2.1/resolve/v0.4.0/hammer-2.1-3B/original/hammer2_1_3B_bf16.pte';
27
- export const HAMMER2_1_3B_QUANTIZED = 'https://huggingface.co/software-mansion/react-native-executorch-hammer-2.1/resolve/v0.4.0/hammer-2.1-3B/quantized/hammer2_1_3B_8da4w.pte';
28
- export const HAMMER2_1_TOKENIZER = 'https://huggingface.co/software-mansion/react-native-executorch-hammer-2.1/resolve/v0.4.0/tokenizer.json';
29
- export const HAMMER2_1_TOKENIZER_CONFIG = 'https://huggingface.co/software-mansion/react-native-executorch-hammer-2.1/resolve/v0.4.0/tokenizer_config.json';
30
- // SMOLLM2
31
- export const SMOLLM2_1_135M = 'https://huggingface.co/software-mansion/react-native-executorch-smolLm-2/resolve/v0.4.0/smolLm-2-135M/original/smolLm2_135M_bf16.pte';
32
- export const SMOLLM2_1_135M_QUANTIZED = 'https://huggingface.co/software-mansion/react-native-executorch-smolLm-2/resolve/v0.4.0/smolLm-2-135M/quantized/smolLm2_135M_8da4w.pte';
33
- export const SMOLLM2_1_360M = 'https://huggingface.co/software-mansion/react-native-executorch-smolLm-2/resolve/v0.4.0/smolLm-2-360M/original/smolLm2_360M_bf16.pte';
34
- export const SMOLLM2_1_360M_QUANTIZED = 'https://huggingface.co/software-mansion/react-native-executorch-smolLm-2/resolve/v0.4.0/smolLm-2-360M/quantized/smolLm2_360M_8da4w.pte';
35
- export const SMOLLM2_1_1_7B = 'https://huggingface.co/software-mansion/react-native-executorch-smolLm-2/resolve/v0.4.0/smolLm-2-1.7B/original/smolLm2_1_7B_bf16.pte';
36
- export const SMOLLM2_1_1_7B_QUANTIZED = 'https://huggingface.co/software-mansion/react-native-executorch-smolLm-2/resolve/v0.4.0/smolLm-2-1.7B/quantized/smolLm2_1_7B_8da4w.pte';
37
- export const SMOLLM2_1_TOKENIZER = 'https://huggingface.co/software-mansion/react-native-executorch-smolLm-2/resolve/v0.4.0/tokenizer.json';
38
- export const SMOLLM2_1_TOKENIZER_CONFIG = 'https://huggingface.co/software-mansion/react-native-executorch-smolLm-2/resolve/v0.4.0/tokenizer_config.json';
39
- // QWEN 2.5
40
- export const QWEN2_5_0_5B = 'https://huggingface.co/software-mansion/react-native-executorch-qwen-2.5/resolve/v0.4.0/qwen-2.5-0.5B/original/qwen2_5_0_5b_bf16.pte';
41
- export const QWEN2_5_0_5B_QUANTIZED = 'https://huggingface.co/software-mansion/react-native-executorch-qwen-2.5/resolve/v0.4.0/qwen-2.5-0.5B/quantized/qwen2_5_0_5b_8da4w.pte';
42
- export const QWEN2_5_1_5B = 'https://huggingface.co/software-mansion/react-native-executorch-qwen-2.5/resolve/v0.4.0/qwen-2.5-1.5B/original/qwen2_5_1_5b_bf16.pte';
43
- export const QWEN2_5_1_5B_QUANTIZED = 'https://huggingface.co/software-mansion/react-native-executorch-qwen-2.5/resolve/v0.4.0/qwen-2.5-1.5B/quantized/qwen2_5_1_5b_8da4w.pte';
44
- export const QWEN2_5_3B = 'https://huggingface.co/software-mansion/react-native-executorch-qwen-2.5/resolve/v0.4.0/qwen-2.5-3B/original/qwen2_5_3b_bf16.pte';
45
- export const QWEN2_5_3B_QUANTIZED = 'https://huggingface.co/software-mansion/react-native-executorch-qwen-2.5/resolve/v0.4.0/qwen-2.5-3B/quantized/qwen2_5_3b_8da4w.pte';
46
- export const QWEN2_5_TOKENIZER = 'https://huggingface.co/software-mansion/react-native-executorch-qwen-2.5/resolve/v0.4.0/tokenizer.json';
47
- export const QWEN2_5_TOKENIZER_CONFIG = 'https://huggingface.co/software-mansion/react-native-executorch-qwen-2.5/resolve/v0.4.0/tokenizer_config.json';
48
- // PHI 4
49
- export const PHI_4_MINI_4B = 'https://huggingface.co/software-mansion/react-native-executorch-phi-4-mini/resolve/v0.4.0/original/phi-4-mini_bf16.pte';
50
- export const PHI_4_MINI_4B_QUANTIZED = 'https://huggingface.co/software-mansion/react-native-executorch-phi-4-mini/resolve/v0.4.0/quantized/phi-4-mini_8da4w.pte';
51
- export const PHI_4_MINI_TOKENIZER = 'https://huggingface.co/software-mansion/react-native-executorch-phi-4-mini/resolve/v0.4.0/tokenizer.json';
52
- export const PHI_4_MINI_TOKENIZER_CONFIG = 'https://huggingface.co/software-mansion/react-native-executorch-phi-4-mini/resolve/v0.4.0/tokenizer_config.json';
53
- // Classification
54
- export const EFFICIENTNET_V2_S = Platform.OS === 'ios'
55
- ? 'https://huggingface.co/software-mansion/react-native-executorch-efficientnet-v2-s/resolve/v0.4.0/coreml/efficientnet_v2_s_coreml_all.pte'
56
- : 'https://huggingface.co/software-mansion/react-native-executorch-efficientnet-v2-s/resolve/v0.4.0/xnnpack/efficientnet_v2_s_xnnpack.pte';
57
- // Object detection
58
- export const SSDLITE_320_MOBILENET_V3_LARGE = 'https://huggingface.co/software-mansion/react-native-executorch-ssdlite320-mobilenet-v3-large/resolve/v0.4.0/ssdlite320-mobilenetv3-large.pte';
59
- // Style transfer
60
- export const STYLE_TRANSFER_CANDY = Platform.OS === 'ios'
61
- ? 'https://huggingface.co/software-mansion/react-native-executorch-style-transfer-candy/resolve/v0.4.0/coreml/style_transfer_candy_coreml.pte'
62
- : 'https://huggingface.co/software-mansion/react-native-executorch-style-transfer-candy/resolve/v0.4.0/xnnpack/style_transfer_candy_xnnpack.pte';
63
- export const STYLE_TRANSFER_MOSAIC = Platform.OS === 'ios'
64
- ? 'https://huggingface.co/software-mansion/react-native-executorch-style-transfer-mosaic/resolve/v0.4.0/coreml/style_transfer_mosaic_coreml.pte'
65
- : 'https://huggingface.co/software-mansion/react-native-executorch-style-transfer-mosaic/resolve/v0.4.0/xnnpack/style_transfer_mosaic_xnnpack.pte';
66
- export const STYLE_TRANSFER_RAIN_PRINCESS = Platform.OS === 'ios'
67
- ? 'https://huggingface.co/software-mansion/react-native-executorch-style-transfer-rain-princess/resolve/v0.4.0/coreml/style_transfer_rain_princess_coreml.pte'
68
- : 'https://huggingface.co/software-mansion/react-native-executorch-style-transfer-rain-princess/resolve/v0.4.0/xnnpack/style_transfer_rain_princess_xnnpack.pte';
69
- export const STYLE_TRANSFER_UDNIE = Platform.OS === 'ios'
70
- ? 'https://huggingface.co/software-mansion/react-native-executorch-style-transfer-udnie/resolve/v0.4.0/coreml/style_transfer_udnie_coreml.pte'
71
- : 'https://huggingface.co/software-mansion/react-native-executorch-style-transfer-udnie/resolve/v0.4.0/xnnpack/style_transfer_udnie_xnnpack.pte';
72
- // S2T
73
- export const MOONSHINE_TINY_DECODER = 'https://huggingface.co/software-mansion/react-native-executorch-moonshine-tiny/resolve/v0.4.0/xnnpack/moonshine_tiny_xnnpack_decoder.pte';
74
- export const MOONSHINE_TINY_ENCODER = 'https://huggingface.co/software-mansion/react-native-executorch-moonshine-tiny/resolve/v0.4.0/xnnpack/moonshine_tiny_xnnpack_encoder.pte';
75
- export const MOONSHINE_TOKENIZER = 'https://huggingface.co/software-mansion/react-native-executorch-moonshine-tiny/resolve/v0.4.0/moonshine_tiny_tokenizer.json';
76
- export const WHISPER_TOKENIZER = 'https://huggingface.co/software-mansion/react-native-executorch-whisper-tiny.en/resolve/v0.4.0/whisper_tokenizer.json';
77
- export const WHISPER_TINY_DECODER = 'https://huggingface.co/software-mansion/react-native-executorch-whisper-tiny.en/resolve/v0.4.0/xnnpack/whisper_tiny_en_xnnpack_decoder.pte';
78
- export const WHISPER_TINY_ENCODER = 'https://huggingface.co/software-mansion/react-native-executorch-whisper-tiny.en/resolve/v0.4.0/xnnpack/whisper_tiny_en_xnnpack_encoder.pte';
79
- export const WHISPER_TINY_MULTILINGUAL_ENCODER = 'https://huggingface.co/software-mansion/react-native-executorch-whisper-tiny/resolve/v0.4.0/xnnpack/xnnpack_whisper_encoder.pte';
80
- export const WHISPER_TINY_MULTILINGUAL_DECODER = 'https://huggingface.co/software-mansion/react-native-executorch-whisper-tiny/resolve/v0.4.0/xnnpack/xnnpack_whisper_decoder.pte';
81
- export const WHISPER_TINY_MULTILINGUAL_TOKENIZER = 'https://huggingface.co/software-mansion/react-native-executorch-whisper-tiny/resolve/v0.4.0/tokenizer.json';
82
- // OCR
83
- export const DETECTOR_CRAFT_1280 = 'https://huggingface.co/software-mansion/react-native-executorch-detector-craft/resolve/v0.4.0/xnnpack/xnnpack_craft_1280.pte';
84
- export const DETECTOR_CRAFT_800 = 'https://huggingface.co/software-mansion/react-native-executorch-detector-craft/resolve/v0.4.0/xnnpack/xnnpack_craft_800.pte';
85
- export const DETECTOR_CRAFT_320 = 'https://huggingface.co/software-mansion/react-native-executorch-detector-craft/resolve/v0.4.0/xnnpack/xnnpack_craft_320.pte';
86
- // Image segmentation
87
- export const DEEPLAB_V3_RESNET50 = 'https://huggingface.co/software-mansion/react-native-executorch-deeplab-v3/resolve/v0.4.0/xnnpack/deeplabV3_xnnpack_fp32.pte';
88
- // Image Embeddings
89
- export const CLIP_VIT_BASE_PATCH32_IMAGE_MODEL = 'https://huggingface.co/software-mansion/react-native-executorch-clip-vit-base-patch32/resolve/v0.5.0/clip-vit-base-patch32-vision_xnnpack.pte';
90
- // Text Embeddings
91
- export const ALL_MINILM_L6_V2 = 'https://huggingface.co/software-mansion/react-native-executorch-all-MiniLM-L6-v2/resolve/v0.5.0/all-MiniLM-L6-v2_xnnpack.pte';
92
- export const ALL_MINILM_L6_V2_TOKENIZER = 'https://huggingface.co/software-mansion/react-native-executorch-all-MiniLM-L6-v2/resolve/v0.5.0/tokenizer.json';
93
- export const ALL_MPNET_BASE_V2 = 'https://huggingface.co/software-mansion/react-native-executorch-all-mpnet-base-v2/resolve/v0.5.0/all-mpnet-base-v2_xnnpack.pte';
94
- export const ALL_MPNET_BASE_V2_TOKENIZER = 'https://huggingface.co/software-mansion/react-native-executorch-all-mpnet-base-v2/resolve/v0.5.0/tokenizer.json';
95
- export const MULTI_QA_MINILM_L6_COS_V1 = 'https://huggingface.co/software-mansion/react-native-executorch-multi-qa-MiniLM-L6-cos-v1/resolve/v0.5.0/multi-qa-MiniLM-L6-cos-v1_xnnpack.pte';
96
- export const MULTI_QA_MINILM_L6_COS_V1_TOKENIZER = 'https://huggingface.co/software-mansion/react-native-executorch-multi-qa-MiniLM-L6-cos-v1/resolve/v0.5.0/tokenizer.json';
97
- export const MULTI_QA_MPNET_BASE_DOT_V1 = 'https://huggingface.co/software-mansion/react-native-executorch-multi-qa-mpnet-base-dot-v1/resolve/v0.5.0/multi-qa-mpnet-base-dot-v1_xnnpack.pte';
98
- export const MULTI_QA_MPNET_BASE_DOT_V1_TOKENIZER = 'https://huggingface.co/software-mansion/react-native-executorch-multi-qa-mpnet-base-dot-v1/resolve/v0.5.0/tokenizer.json';
99
- export const CLIP_VIT_BASE_PATCH32_TEXT_MODEL = 'https://huggingface.co/software-mansion/react-native-executorch-clip-vit-base-patch32/resolve/v0.5.0/clip-vit-base-patch32-text_xnnpack.pte';
100
- export const CLIP_VIT_BASE_PATCH32_TEXT_TOKENIZER = 'https://huggingface.co/software-mansion/react-native-executorch-clip-vit-base-patch32/resolve/v0.5.0/tokenizer.json';
101
- export const CLIP_VIT_BASE_PATCH32_TEXT = {
102
- modelSource: CLIP_VIT_BASE_PATCH32_TEXT_MODEL,
103
- tokenizerSource: CLIP_VIT_BASE_PATCH32_TEXT_TOKENIZER,
104
- };
105
- export const CLIP_VIT_BASE_PATCH32_IMAGE = {
106
- modelSource: CLIP_VIT_BASE_PATCH32_IMAGE_MODEL,
107
- };
108
- // Backward compatibility
109
- export const LLAMA3_2_3B_URL = LLAMA3_2_3B;
110
- export const LLAMA3_2_3B_QLORA_URL = LLAMA3_2_3B_QLORA;
111
- export const LLAMA3_2_3B_SPINQUANT_URL = LLAMA3_2_3B_SPINQUANT;
112
- export const LLAMA3_2_1B_URL = LLAMA3_2_1B;
113
- export const LLAMA3_2_1B_QLORA_URL = LLAMA3_2_1B_QLORA;
114
- export const LLAMA3_2_1B_SPINQUANT_URL = LLAMA3_2_1B_SPINQUANT;
115
- export const LLAMA3_2_1B_TOKENIZER = LLAMA3_2_TOKENIZER;
116
- export const LLAMA3_2_3B_TOKENIZER = LLAMA3_2_TOKENIZER;
@@ -1,66 +0,0 @@
1
- import { MOONSHINE_TINY_ENCODER, MOONSHINE_TINY_DECODER, MOONSHINE_TOKENIZER, WHISPER_TINY_ENCODER, WHISPER_TINY_DECODER, WHISPER_TOKENIZER, WHISPER_TINY_MULTILINGUAL_ENCODER, WHISPER_TINY_MULTILINGUAL_DECODER, WHISPER_TINY_MULTILINGUAL_TOKENIZER, } from './modelUrls';
2
- export const SAMPLE_RATE = 16_000;
3
- export const SECOND = SAMPLE_RATE;
4
- export const HAMMING_DIST_THRESHOLD = 1;
5
- const whisperTinyModelConfig = {
6
- sources: {
7
- encoder: WHISPER_TINY_ENCODER,
8
- decoder: WHISPER_TINY_DECODER,
9
- },
10
- tokenizer: {
11
- source: WHISPER_TOKENIZER,
12
- bos: 50257, // FIXME: this is a placeholder and needs to be changed
13
- eos: 50256, // FIXME: this is a placeholder and needs to be changed
14
- },
15
- isMultilingual: false,
16
- };
17
- const moonshineTinyModelConfig = {
18
- sources: {
19
- encoder: MOONSHINE_TINY_ENCODER,
20
- decoder: MOONSHINE_TINY_DECODER,
21
- },
22
- tokenizer: {
23
- source: MOONSHINE_TOKENIZER,
24
- bos: 1, // FIXME: this is a placeholder and needs to be changed
25
- eos: 2, // FIXME: this is a placeholder and needs to be changed
26
- },
27
- isMultilingual: false,
28
- };
29
- const whisperTinyMultilingualModelConfig = {
30
- sources: {
31
- encoder: WHISPER_TINY_MULTILINGUAL_ENCODER,
32
- decoder: WHISPER_TINY_MULTILINGUAL_DECODER,
33
- },
34
- tokenizer: {
35
- source: WHISPER_TINY_MULTILINGUAL_TOKENIZER,
36
- bos: 50258, // FIXME: this is a placeholder and needs to be changed
37
- eos: 50257, // FIXME: this is a placeholder and needs to be changed
38
- },
39
- isMultilingual: true,
40
- };
41
- export const MODEL_CONFIGS = {
42
- moonshine: moonshineTinyModelConfig,
43
- whisper: whisperTinyModelConfig,
44
- whisperMultilingual: whisperTinyMultilingualModelConfig,
45
- };
46
- export const MODES = {
47
- fast: {
48
- windowSize: 5,
49
- overlapSeconds: 1.2,
50
- },
51
- balanced: {
52
- windowSize: 12,
53
- overlapSeconds: 2,
54
- },
55
- quality: {
56
- windowSize: 24,
57
- overlapSeconds: 3,
58
- },
59
- };
60
- export const NUM_TOKENS_TO_TRIM = 3;
61
- export var STREAMING_ACTION;
62
- (function (STREAMING_ACTION) {
63
- STREAMING_ACTION[STREAMING_ACTION["START"] = 0] = "START";
64
- STREAMING_ACTION[STREAMING_ACTION["DATA"] = 1] = "DATA";
65
- STREAMING_ACTION[STREAMING_ACTION["STOP"] = 2] = "STOP";
66
- })(STREAMING_ACTION || (STREAMING_ACTION = {}));
@@ -1,210 +0,0 @@
1
- import { ResourceFetcher } from '../utils/ResourceFetcher';
2
- import { ETError, getError } from '../Error';
3
- import { Template } from '@huggingface/jinja';
4
- import { DEFAULT_CHAT_CONFIG } from '../constants/llmDefaults';
5
- import { readAsStringAsync } from 'expo-file-system';
6
- import { SPECIAL_TOKENS, } from '../types/llm';
7
- import { parseToolCall } from '../utils/llm';
8
- import { Logger } from '../common/Logger';
9
- export class LLMController {
10
- nativeModule;
11
- chatConfig = DEFAULT_CHAT_CONFIG;
12
- toolsConfig;
13
- tokenizerConfig;
14
- onToken;
15
- _response = '';
16
- _isReady = false;
17
- _isGenerating = false;
18
- _messageHistory = [];
19
- // User callbacks
20
- tokenCallback;
21
- responseCallback;
22
- messageHistoryCallback;
23
- isReadyCallback;
24
- isGeneratingCallback;
25
- onDownloadProgressCallback;
26
- constructor({ tokenCallback, responseCallback, messageHistoryCallback, isReadyCallback, isGeneratingCallback, onDownloadProgressCallback, }) {
27
- if (responseCallback !== undefined) {
28
- Logger.warn('Passing response callback is deprecated and will be removed in 0.6.0');
29
- }
30
- this.tokenCallback = (token) => {
31
- tokenCallback?.(token);
32
- };
33
- this.responseCallback = (response) => {
34
- this._response = response;
35
- responseCallback?.(response);
36
- };
37
- this.messageHistoryCallback = (messageHistory) => {
38
- this._messageHistory = messageHistory;
39
- messageHistoryCallback?.(messageHistory);
40
- };
41
- this.isReadyCallback = (isReady) => {
42
- this._isReady = isReady;
43
- isReadyCallback?.(isReady);
44
- };
45
- this.isGeneratingCallback = (isGenerating) => {
46
- this._isGenerating = isGenerating;
47
- isGeneratingCallback?.(isGenerating);
48
- };
49
- this.onDownloadProgressCallback = onDownloadProgressCallback;
50
- }
51
- get response() {
52
- return this._response;
53
- }
54
- get isReady() {
55
- return this._isReady;
56
- }
57
- get isGenerating() {
58
- return this._isGenerating;
59
- }
60
- get messageHistory() {
61
- return this._messageHistory;
62
- }
63
- async load({ modelSource, tokenizerSource, tokenizerConfigSource, }) {
64
- // reset inner state when loading new model
65
- this.responseCallback('');
66
- this.messageHistoryCallback(this.chatConfig.initialMessageHistory);
67
- this.isGeneratingCallback(false);
68
- this.isReadyCallback(false);
69
- try {
70
- const paths = await ResourceFetcher.fetch(this.onDownloadProgressCallback, tokenizerSource, tokenizerConfigSource, modelSource);
71
- if (paths === null || paths?.length < 3) {
72
- throw new Error('Download interrupted!');
73
- }
74
- const tokenizerFileUri = paths[0];
75
- const tokenizerConfigFileUri = paths[1];
76
- const modelFileUri = paths[2];
77
- this.tokenizerConfig = JSON.parse(await readAsStringAsync('file://' + tokenizerConfigFileUri));
78
- this.nativeModule = global.loadLLM(modelFileUri, tokenizerFileUri);
79
- this.isReadyCallback(true);
80
- this.onToken = (data) => {
81
- if (!data ||
82
- (SPECIAL_TOKENS.EOS_TOKEN in this.tokenizerConfig &&
83
- data === this.tokenizerConfig.eos_token) ||
84
- (SPECIAL_TOKENS.PAD_TOKEN in this.tokenizerConfig &&
85
- data === this.tokenizerConfig.pad_token)) {
86
- return;
87
- }
88
- this.tokenCallback(data);
89
- this.responseCallback(this._response + data);
90
- };
91
- }
92
- catch (e) {
93
- this.isReadyCallback(false);
94
- throw new Error(getError(e));
95
- }
96
- }
97
- setTokenCallback(tokenCallback) {
98
- this.tokenCallback = tokenCallback;
99
- }
100
- configure({ chatConfig, toolsConfig, }) {
101
- this.chatConfig = { ...DEFAULT_CHAT_CONFIG, ...chatConfig };
102
- this.toolsConfig = toolsConfig;
103
- // reset inner state when loading new configuration
104
- this.responseCallback('');
105
- this.messageHistoryCallback(this.chatConfig.initialMessageHistory);
106
- this.isGeneratingCallback(false);
107
- }
108
- delete() {
109
- if (this._isGenerating) {
110
- throw new Error(getError(ETError.ModelGenerating) +
111
- 'You cannot delete the model now. You need to interrupt first.');
112
- }
113
- this.onToken = () => { };
114
- this.nativeModule.unload();
115
- this.isReadyCallback(false);
116
- this.isGeneratingCallback(false);
117
- }
118
- async forward(input) {
119
- if (!this._isReady) {
120
- throw new Error(getError(ETError.ModuleNotLoaded));
121
- }
122
- if (this._isGenerating) {
123
- throw new Error(getError(ETError.ModelGenerating));
124
- }
125
- try {
126
- this.responseCallback('');
127
- this.isGeneratingCallback(true);
128
- await this.nativeModule.generate(input, this.onToken);
129
- }
130
- catch (e) {
131
- throw new Error(getError(e));
132
- }
133
- finally {
134
- this.isGeneratingCallback(false);
135
- }
136
- }
137
- interrupt() {
138
- this.nativeModule.interrupt();
139
- }
140
- async generate(messages, tools) {
141
- if (!this._isReady) {
142
- throw new Error(getError(ETError.ModuleNotLoaded));
143
- }
144
- if (messages.length === 0) {
145
- throw new Error(`Empty 'messages' array!`);
146
- }
147
- if (messages[0] && messages[0].role !== 'system') {
148
- Logger.warn(`You are not providing system prompt. You can pass it in the first message using { role: 'system', content: YOUR_PROMPT }. Otherwise prompt from your model's chat template will be used.`);
149
- }
150
- const renderedChat = this.applyChatTemplate(messages, this.tokenizerConfig, tools,
151
- // eslint-disable-next-line camelcase
152
- { tools_in_user_message: false, add_generation_prompt: true });
153
- await this.forward(renderedChat);
154
- }
155
- async sendMessage(message) {
156
- this.messageHistoryCallback([
157
- ...this._messageHistory,
158
- { content: message, role: 'user' },
159
- ]);
160
- const messageHistoryWithPrompt = [
161
- { content: this.chatConfig.systemPrompt, role: 'system' },
162
- ...this._messageHistory.slice(-this.chatConfig.contextWindowLength),
163
- ];
164
- await this.generate(messageHistoryWithPrompt, this.toolsConfig?.tools);
165
- if (!this.toolsConfig || this.toolsConfig.displayToolCalls) {
166
- this.messageHistoryCallback([
167
- ...this._messageHistory,
168
- { content: this._response, role: 'assistant' },
169
- ]);
170
- }
171
- if (!this.toolsConfig) {
172
- return;
173
- }
174
- const toolCalls = parseToolCall(this._response);
175
- for (const toolCall of toolCalls) {
176
- this.toolsConfig
177
- .executeToolCallback(toolCall)
178
- .then((toolResponse) => {
179
- if (toolResponse) {
180
- this.messageHistoryCallback([
181
- ...this._messageHistory,
182
- { content: toolResponse, role: 'assistant' },
183
- ]);
184
- }
185
- });
186
- }
187
- }
188
- deleteMessage(index) {
189
- // we delete referenced message and all messages after it
190
- // so the model responses that used them are deleted as well
191
- const newMessageHistory = this._messageHistory.slice(0, index);
192
- this.messageHistoryCallback(newMessageHistory);
193
- }
194
- applyChatTemplate(messages, tokenizerConfig, tools, templateFlags) {
195
- if (!tokenizerConfig.chat_template) {
196
- throw Error("Tokenizer config doesn't include chat_template");
197
- }
198
- const template = new Template(tokenizerConfig.chat_template);
199
- const specialTokens = Object.fromEntries(Object.keys(SPECIAL_TOKENS)
200
- .filter((key) => key in tokenizerConfig)
201
- .map((key) => [key, tokenizerConfig[key]]));
202
- const result = template.render({
203
- messages,
204
- tools,
205
- ...templateFlags,
206
- ...specialTokens,
207
- });
208
- return result;
209
- }
210
- }
@@ -1,65 +0,0 @@
1
- import { symbols } from '../constants/ocr/symbols';
2
- import { ETError, getError } from '../Error';
3
- import { ResourceFetcher } from '../utils/ResourceFetcher';
4
- export class OCRController {
5
- nativeModule;
6
- isReady = false;
7
- isGenerating = false;
8
- error = null;
9
- modelDownloadProgressCallback;
10
- isReadyCallback;
11
- isGeneratingCallback;
12
- errorCallback;
13
- constructor({ modelDownloadProgressCallback = (_downloadProgress) => { }, isReadyCallback = (_isReady) => { }, isGeneratingCallback = (_isGenerating) => { }, errorCallback = (_error) => { }, }) {
14
- this.modelDownloadProgressCallback = modelDownloadProgressCallback;
15
- this.isReadyCallback = isReadyCallback;
16
- this.isGeneratingCallback = isGeneratingCallback;
17
- this.errorCallback = errorCallback;
18
- }
19
- load = async (detectorSource, recognizerSources, language) => {
20
- try {
21
- if (!detectorSource || Object.keys(recognizerSources).length !== 3)
22
- return;
23
- if (!symbols[language]) {
24
- throw new Error(getError(ETError.LanguageNotSupported));
25
- }
26
- this.isReady = false;
27
- this.isReadyCallback(false);
28
- const paths = await ResourceFetcher.fetch(this.modelDownloadProgressCallback, detectorSource, recognizerSources.recognizerLarge, recognizerSources.recognizerMedium, recognizerSources.recognizerSmall);
29
- if (paths === null || paths?.length < 4) {
30
- throw new Error('Download interrupted!');
31
- }
32
- this.nativeModule = global.loadOCR(paths[0], paths[1], paths[2], paths[3], symbols[language]);
33
- this.isReady = true;
34
- this.isReadyCallback(this.isReady);
35
- }
36
- catch (e) {
37
- if (this.errorCallback) {
38
- this.errorCallback(getError(e));
39
- }
40
- else {
41
- throw new Error(getError(e));
42
- }
43
- }
44
- };
45
- forward = async (input) => {
46
- if (!this.isReady) {
47
- throw new Error(getError(ETError.ModuleNotLoaded));
48
- }
49
- if (this.isGenerating) {
50
- throw new Error(getError(ETError.ModelGenerating));
51
- }
52
- try {
53
- this.isGenerating = true;
54
- this.isGeneratingCallback(this.isGenerating);
55
- return await this.nativeModule.generate(input);
56
- }
57
- catch (e) {
58
- throw new Error(getError(e));
59
- }
60
- finally {
61
- this.isGenerating = false;
62
- this.isGeneratingCallback(this.isGenerating);
63
- }
64
- };
65
- }
@@ -1,52 +0,0 @@
1
- import { MODES, STREAMING_ACTION } from '../constants/sttDefaults';
2
- import { AvailableModels } from '../types/stt';
3
- import { ResourceSource } from '../types/common';
4
- import { SpeechToTextLanguage } from '../types/stt';
5
- export declare class SpeechToTextController {
6
- private speechToTextNativeModule;
7
- sequence: number[];
8
- isReady: boolean;
9
- isGenerating: boolean;
10
- private tokenizerModule;
11
- private overlapSeconds;
12
- private windowSize;
13
- private chunks;
14
- private seqs;
15
- private prevSeq;
16
- private waveform;
17
- private numOfChunks;
18
- private streaming;
19
- private decodedTranscribeCallback;
20
- private modelDownloadProgressCallback;
21
- private isReadyCallback;
22
- private isGeneratingCallback;
23
- private onErrorCallback;
24
- private config;
25
- constructor({ transcribeCallback, modelDownloadProgressCallback, isReadyCallback, isGeneratingCallback, onErrorCallback, overlapSeconds, windowSize, streamingConfig, }: {
26
- transcribeCallback: (sequence: string) => void;
27
- modelDownloadProgressCallback?: (downloadProgress: number) => void;
28
- isReadyCallback?: (isReady: boolean) => void;
29
- isGeneratingCallback?: (isGenerating: boolean) => void;
30
- onErrorCallback?: (error: Error | undefined) => void;
31
- overlapSeconds?: number;
32
- windowSize?: number;
33
- streamingConfig?: keyof typeof MODES;
34
- });
35
- loadModel(modelName: AvailableModels, encoderSource?: ResourceSource, decoderSource?: ResourceSource, tokenizerSource?: ResourceSource): Promise<void>;
36
- configureStreaming(overlapSeconds?: number, windowSize?: number, streamingConfig?: keyof typeof MODES): void;
37
- private chunkWaveform;
38
- private resetState;
39
- private expectedChunkLength;
40
- private getStartingTokenIds;
41
- private decodeChunk;
42
- private handleOverlaps;
43
- private trimLeft;
44
- private trimRight;
45
- private trimSequences;
46
- private validateAndFixLastChunk;
47
- private tokenIdsToText;
48
- transcribe(waveform: number[], audioLanguage?: SpeechToTextLanguage): Promise<string>;
49
- streamingTranscribe(streamAction: STREAMING_ACTION, waveform?: number[], audioLanguage?: SpeechToTextLanguage): Promise<string>;
50
- encode(waveform: Float32Array): Promise<null>;
51
- decode(seq: number[]): Promise<number>;
52
- }