react-native-executorch 0.3.3 → 0.4.2

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 (343) hide show
  1. package/README.md +30 -13
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/com/swmansion/rnexecutorch/ETModule.kt +1 -2
  4. package/android/src/main/java/com/swmansion/rnexecutorch/ImageSegmentation.kt +58 -0
  5. package/android/src/main/java/com/swmansion/rnexecutorch/LLM.kt +13 -49
  6. package/android/src/main/java/com/swmansion/rnexecutorch/RnExecutorchPackage.kt +37 -0
  7. package/android/src/main/java/com/swmansion/rnexecutorch/StyleTransfer.kt +1 -1
  8. package/android/src/main/java/com/swmansion/rnexecutorch/TextEmbeddings.kt +51 -0
  9. package/android/src/main/java/com/swmansion/rnexecutorch/Tokenizer.kt +86 -0
  10. package/android/src/main/java/com/swmansion/rnexecutorch/models/BaseModel.kt +3 -4
  11. package/android/src/main/java/com/swmansion/rnexecutorch/models/TextEmbeddings/TextEmbeddingsModel.kt +48 -0
  12. package/android/src/main/java/com/swmansion/rnexecutorch/models/TextEmbeddings/TextEmbeddingsUtils.kt +37 -0
  13. package/android/src/main/java/com/swmansion/rnexecutorch/models/classification/ClassificationModel.kt +1 -0
  14. package/android/src/main/java/com/swmansion/rnexecutorch/models/imageSegmentation/Constants.kt +26 -0
  15. package/android/src/main/java/com/swmansion/rnexecutorch/models/imageSegmentation/ImageSegmentationModel.kt +142 -0
  16. package/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/RecognizerUtils.kt +3 -0
  17. package/android/src/main/java/com/swmansion/rnexecutorch/models/{StyleTransferModel.kt → styleTransfer/StyleTransferModel.kt} +2 -1
  18. package/android/src/main/java/com/swmansion/rnexecutorch/utils/ArrayUtils.kt +0 -8
  19. package/android/src/main/java/com/swmansion/rnexecutorch/{models/classification/Utils.kt → utils/Numerical.kt} +1 -1
  20. package/ios/ExecutorchLib.xcframework/Info.plist +4 -4
  21. package/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/ExecutorchLib +0 -0
  22. package/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Headers/HuggingFaceTokenizer.h +14 -0
  23. package/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Headers/LLaMARunner.h +1 -23
  24. package/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Info.plist +0 -0
  25. package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/ExecutorchLib +0 -0
  26. package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Headers/HuggingFaceTokenizer.h +14 -0
  27. package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Headers/LLaMARunner.h +1 -23
  28. package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Info.plist +0 -0
  29. package/ios/RnExecutorch/Classification.mm +15 -18
  30. package/ios/RnExecutorch/ETModule.mm +6 -5
  31. package/ios/RnExecutorch/ImageSegmentation.h +5 -0
  32. package/ios/RnExecutorch/ImageSegmentation.mm +60 -0
  33. package/ios/RnExecutorch/LLM.mm +12 -53
  34. package/ios/RnExecutorch/OCR.mm +39 -43
  35. package/ios/RnExecutorch/ObjectDetection.mm +20 -20
  36. package/ios/RnExecutorch/SpeechToText.mm +6 -7
  37. package/ios/RnExecutorch/StyleTransfer.mm +16 -19
  38. package/ios/RnExecutorch/TextEmbeddings.h +5 -0
  39. package/ios/RnExecutorch/TextEmbeddings.mm +62 -0
  40. package/ios/RnExecutorch/Tokenizer.h +5 -0
  41. package/ios/RnExecutorch/Tokenizer.mm +83 -0
  42. package/ios/RnExecutorch/VerticalOCR.mm +36 -36
  43. package/ios/RnExecutorch/models/BaseModel.h +2 -5
  44. package/ios/RnExecutorch/models/BaseModel.mm +5 -15
  45. package/ios/RnExecutorch/models/classification/ClassificationModel.mm +2 -3
  46. package/ios/RnExecutorch/models/classification/Constants.mm +0 -1
  47. package/ios/RnExecutorch/models/image_segmentation/Constants.h +4 -0
  48. package/ios/RnExecutorch/models/image_segmentation/Constants.mm +8 -0
  49. package/ios/RnExecutorch/models/image_segmentation/ImageSegmentationModel.h +10 -0
  50. package/ios/RnExecutorch/models/image_segmentation/ImageSegmentationModel.mm +146 -0
  51. package/ios/RnExecutorch/models/object_detection/SSDLiteLargeModel.mm +1 -2
  52. package/ios/RnExecutorch/models/ocr/Detector.h +0 -2
  53. package/ios/RnExecutorch/models/ocr/Detector.mm +2 -1
  54. package/ios/RnExecutorch/models/ocr/RecognitionHandler.h +5 -4
  55. package/ios/RnExecutorch/models/ocr/RecognitionHandler.mm +9 -26
  56. package/ios/RnExecutorch/models/ocr/Recognizer.mm +1 -2
  57. package/ios/RnExecutorch/models/ocr/VerticalDetector.h +0 -2
  58. package/ios/RnExecutorch/models/ocr/VerticalDetector.mm +2 -1
  59. package/ios/RnExecutorch/models/ocr/utils/OCRUtils.mm +0 -1
  60. package/ios/RnExecutorch/models/stt/Moonshine.mm +1 -6
  61. package/ios/RnExecutorch/models/stt/SpeechToTextBaseModel.mm +7 -11
  62. package/ios/RnExecutorch/models/stt/Whisper.mm +0 -5
  63. package/ios/RnExecutorch/models/{StyleTransferModel.h → style_transfer/StyleTransferModel.h} +1 -1
  64. package/ios/RnExecutorch/models/{StyleTransferModel.mm → style_transfer/StyleTransferModel.mm} +2 -3
  65. package/ios/RnExecutorch/models/text_embeddings/TextEmbeddingsModel.h +15 -0
  66. package/ios/RnExecutorch/models/text_embeddings/TextEmbeddingsModel.mm +45 -0
  67. package/ios/RnExecutorch/models/text_embeddings/TextEmbeddingsUtils.h +8 -0
  68. package/ios/RnExecutorch/models/text_embeddings/TextEmbeddingsUtils.mm +49 -0
  69. package/ios/RnExecutorch/utils/Conversions.h +15 -0
  70. package/ios/RnExecutorch/utils/ImageProcessor.h +0 -1
  71. package/ios/RnExecutorch/{models/classification/Utils.h → utils/Numerical.h} +0 -2
  72. package/ios/RnExecutorch/{models/classification/Utils.mm → utils/Numerical.mm} +0 -2
  73. package/ios/RnExecutorch/utils/ObjectDetectionUtils.mm +0 -2
  74. package/ios/RnExecutorch/utils/SFFT.mm +1 -1
  75. package/ios/RnExecutorch/utils/ScalarType.h +0 -2
  76. package/lib/module/Error.js +16 -2
  77. package/lib/module/Error.js.map +1 -1
  78. package/lib/module/constants/{llamaDefaults.js → llmDefaults.js} +7 -3
  79. package/lib/module/constants/llmDefaults.js.map +1 -0
  80. package/lib/module/constants/modelUrls.js +88 -27
  81. package/lib/module/constants/modelUrls.js.map +1 -1
  82. package/lib/module/constants/ocr/models.js +290 -0
  83. package/lib/module/constants/ocr/models.js.map +1 -0
  84. package/lib/module/constants/ocr/symbols.js +137 -2
  85. package/lib/module/constants/ocr/symbols.js.map +1 -1
  86. package/lib/module/constants/sttDefaults.js +50 -25
  87. package/lib/module/constants/sttDefaults.js.map +1 -1
  88. package/lib/module/controllers/LLMController.js +205 -0
  89. package/lib/module/controllers/LLMController.js.map +1 -0
  90. package/lib/module/controllers/OCRController.js +5 -10
  91. package/lib/module/controllers/OCRController.js.map +1 -1
  92. package/lib/module/controllers/SpeechToTextController.js +225 -122
  93. package/lib/module/controllers/SpeechToTextController.js.map +1 -1
  94. package/lib/module/controllers/VerticalOCRController.js +6 -10
  95. package/lib/module/controllers/VerticalOCRController.js.map +1 -1
  96. package/lib/module/hooks/computer_vision/useClassification.js +8 -23
  97. package/lib/module/hooks/computer_vision/useClassification.js.map +1 -1
  98. package/lib/module/hooks/computer_vision/useImageSegmentation.js +13 -0
  99. package/lib/module/hooks/computer_vision/useImageSegmentation.js.map +1 -0
  100. package/lib/module/hooks/computer_vision/useOCR.js +11 -6
  101. package/lib/module/hooks/computer_vision/useOCR.js.map +1 -1
  102. package/lib/module/hooks/computer_vision/useObjectDetection.js +8 -23
  103. package/lib/module/hooks/computer_vision/useObjectDetection.js.map +1 -1
  104. package/lib/module/hooks/computer_vision/useStyleTransfer.js +8 -23
  105. package/lib/module/hooks/computer_vision/useStyleTransfer.js.map +1 -1
  106. package/lib/module/hooks/computer_vision/useVerticalOCR.js +10 -7
  107. package/lib/module/hooks/computer_vision/useVerticalOCR.js.map +1 -1
  108. package/lib/module/hooks/general/useExecutorchModule.js +8 -36
  109. package/lib/module/hooks/general/useExecutorchModule.js.map +1 -1
  110. package/lib/module/hooks/natural_language_processing/useLLM.js +54 -63
  111. package/lib/module/hooks/natural_language_processing/useLLM.js.map +1 -1
  112. package/lib/module/hooks/natural_language_processing/useSpeechToText.js +15 -11
  113. package/lib/module/hooks/natural_language_processing/useSpeechToText.js.map +1 -1
  114. package/lib/module/hooks/natural_language_processing/useTextEmbeddings.js +14 -0
  115. package/lib/module/hooks/natural_language_processing/useTextEmbeddings.js.map +1 -0
  116. package/lib/module/hooks/natural_language_processing/useTokenizer.js +54 -0
  117. package/lib/module/hooks/natural_language_processing/useTokenizer.js.map +1 -0
  118. package/lib/module/hooks/useModule.js +18 -62
  119. package/lib/module/hooks/useModule.js.map +1 -1
  120. package/lib/module/index.js +16 -2
  121. package/lib/module/index.js.map +1 -1
  122. package/lib/module/modules/BaseModule.js +9 -10
  123. package/lib/module/modules/BaseModule.js.map +1 -1
  124. package/lib/module/modules/computer_vision/ClassificationModule.js +8 -5
  125. package/lib/module/modules/computer_vision/ClassificationModule.js.map +1 -1
  126. package/lib/module/modules/computer_vision/ImageSegmentationModule.js +28 -0
  127. package/lib/module/modules/computer_vision/ImageSegmentationModule.js.map +1 -0
  128. package/lib/module/modules/computer_vision/ObjectDetectionModule.js +8 -5
  129. package/lib/module/modules/computer_vision/ObjectDetectionModule.js.map +1 -1
  130. package/lib/module/modules/computer_vision/StyleTransferModule.js +8 -5
  131. package/lib/module/modules/computer_vision/StyleTransferModule.js.map +1 -1
  132. package/lib/module/modules/general/ExecutorchModule.js +8 -5
  133. package/lib/module/modules/general/ExecutorchModule.js.map +1 -1
  134. package/lib/module/modules/natural_language_processing/LLMModule.js +46 -27
  135. package/lib/module/modules/natural_language_processing/LLMModule.js.map +1 -1
  136. package/lib/module/modules/natural_language_processing/SpeechToTextModule.js +8 -5
  137. package/lib/module/modules/natural_language_processing/SpeechToTextModule.js.map +1 -1
  138. package/lib/module/modules/natural_language_processing/TextEmbeddingsModule.js +14 -0
  139. package/lib/module/modules/natural_language_processing/TextEmbeddingsModule.js.map +1 -0
  140. package/lib/module/modules/natural_language_processing/TokenizerModule.js +26 -0
  141. package/lib/module/modules/natural_language_processing/TokenizerModule.js.map +1 -0
  142. package/lib/module/native/NativeClassification.js.map +1 -1
  143. package/lib/module/native/NativeImageSegmentation.js +5 -0
  144. package/lib/module/native/NativeImageSegmentation.js.map +1 -0
  145. package/lib/module/native/NativeLLM.js.map +1 -1
  146. package/lib/module/native/NativeTextEmbeddings.js +5 -0
  147. package/lib/module/native/NativeTextEmbeddings.js.map +1 -0
  148. package/lib/module/native/NativeTokenizer.js +5 -0
  149. package/lib/module/native/NativeTokenizer.js.map +1 -0
  150. package/lib/module/native/RnExecutorchModules.js +18 -113
  151. package/lib/module/native/RnExecutorchModules.js.map +1 -1
  152. package/lib/module/types/common.js.map +1 -1
  153. package/lib/module/types/imageSegmentation.js +29 -0
  154. package/lib/module/types/imageSegmentation.js.map +1 -0
  155. package/lib/module/types/llm.js +7 -0
  156. package/lib/module/types/llm.js.map +1 -0
  157. package/lib/module/types/{object_detection.js → objectDetection.js} +1 -1
  158. package/lib/module/types/objectDetection.js.map +1 -0
  159. package/lib/module/types/ocr.js +2 -0
  160. package/lib/module/types/stt.js +82 -0
  161. package/lib/module/types/stt.js.map +1 -0
  162. package/lib/module/utils/ResourceFetcher.js +156 -0
  163. package/lib/module/utils/ResourceFetcher.js.map +1 -0
  164. package/lib/module/utils/llm.js +25 -0
  165. package/lib/module/utils/llm.js.map +1 -0
  166. package/lib/module/utils/stt.js +22 -0
  167. package/lib/module/utils/stt.js.map +1 -0
  168. package/lib/typescript/Error.d.ts +4 -1
  169. package/lib/typescript/Error.d.ts.map +1 -1
  170. package/lib/typescript/constants/{llamaDefaults.d.ts → llmDefaults.d.ts} +5 -5
  171. package/lib/typescript/constants/llmDefaults.d.ts.map +1 -0
  172. package/lib/typescript/constants/modelUrls.d.ts +74 -28
  173. package/lib/typescript/constants/modelUrls.d.ts.map +1 -1
  174. package/lib/typescript/constants/ocr/models.d.ts +285 -0
  175. package/lib/typescript/constants/ocr/models.d.ts.map +1 -0
  176. package/lib/typescript/constants/ocr/symbols.d.ts +73 -1
  177. package/lib/typescript/constants/ocr/symbols.d.ts.map +1 -1
  178. package/lib/typescript/constants/sttDefaults.d.ts +8 -13
  179. package/lib/typescript/constants/sttDefaults.d.ts.map +1 -1
  180. package/lib/typescript/controllers/LLMController.d.ts +46 -0
  181. package/lib/typescript/controllers/LLMController.d.ts.map +1 -0
  182. package/lib/typescript/controllers/OCRController.d.ts.map +1 -1
  183. package/lib/typescript/controllers/SpeechToTextController.d.ts +30 -16
  184. package/lib/typescript/controllers/SpeechToTextController.d.ts.map +1 -1
  185. package/lib/typescript/controllers/VerticalOCRController.d.ts +1 -1
  186. package/lib/typescript/controllers/VerticalOCRController.d.ts.map +1 -1
  187. package/lib/typescript/hooks/computer_vision/useClassification.d.ts +5 -5
  188. package/lib/typescript/hooks/computer_vision/useClassification.d.ts.map +1 -1
  189. package/lib/typescript/hooks/computer_vision/useImageSegmentation.d.ts +37 -0
  190. package/lib/typescript/hooks/computer_vision/useImageSegmentation.d.ts.map +1 -0
  191. package/lib/typescript/hooks/computer_vision/useOCR.d.ts +2 -1
  192. package/lib/typescript/hooks/computer_vision/useOCR.d.ts.map +1 -1
  193. package/lib/typescript/hooks/computer_vision/useObjectDetection.d.ts +5 -4
  194. package/lib/typescript/hooks/computer_vision/useObjectDetection.d.ts.map +1 -1
  195. package/lib/typescript/hooks/computer_vision/useStyleTransfer.d.ts +4 -2
  196. package/lib/typescript/hooks/computer_vision/useStyleTransfer.d.ts.map +1 -1
  197. package/lib/typescript/hooks/computer_vision/useVerticalOCR.d.ts +2 -1
  198. package/lib/typescript/hooks/computer_vision/useVerticalOCR.d.ts.map +1 -1
  199. package/lib/typescript/hooks/general/useExecutorchModule.d.ts +5 -6
  200. package/lib/typescript/hooks/general/useExecutorchModule.d.ts.map +1 -1
  201. package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts +6 -6
  202. package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts.map +1 -1
  203. package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts +7 -3
  204. package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts.map +1 -1
  205. package/lib/typescript/hooks/natural_language_processing/useTextEmbeddings.d.ts +13 -0
  206. package/lib/typescript/hooks/natural_language_processing/useTextEmbeddings.d.ts.map +1 -0
  207. package/lib/typescript/hooks/natural_language_processing/useTokenizer.d.ts +16 -0
  208. package/lib/typescript/hooks/natural_language_processing/useTokenizer.d.ts.map +1 -0
  209. package/lib/typescript/hooks/useModule.d.ts +11 -10
  210. package/lib/typescript/hooks/useModule.d.ts.map +1 -1
  211. package/lib/typescript/index.d.ts +15 -2
  212. package/lib/typescript/index.d.ts.map +1 -1
  213. package/lib/typescript/modules/BaseModule.d.ts +4 -5
  214. package/lib/typescript/modules/BaseModule.d.ts.map +1 -1
  215. package/lib/typescript/modules/computer_vision/ClassificationModule.d.ts +7 -7
  216. package/lib/typescript/modules/computer_vision/ClassificationModule.d.ts.map +1 -1
  217. package/lib/typescript/modules/computer_vision/ImageSegmentationModule.d.ts +32 -0
  218. package/lib/typescript/modules/computer_vision/ImageSegmentationModule.d.ts.map +1 -0
  219. package/lib/typescript/modules/computer_vision/ObjectDetectionModule.d.ts +6 -5
  220. package/lib/typescript/modules/computer_vision/ObjectDetectionModule.d.ts.map +1 -1
  221. package/lib/typescript/modules/computer_vision/StyleTransferModule.d.ts +6 -5
  222. package/lib/typescript/modules/computer_vision/StyleTransferModule.d.ts.map +1 -1
  223. package/lib/typescript/modules/general/ExecutorchModule.d.ts +4 -3
  224. package/lib/typescript/modules/general/ExecutorchModule.d.ts.map +1 -1
  225. package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts +19 -5
  226. package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts.map +1 -1
  227. package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts +7 -4
  228. package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts.map +1 -1
  229. package/lib/typescript/modules/natural_language_processing/TextEmbeddingsModule.d.ts +8 -0
  230. package/lib/typescript/modules/natural_language_processing/TextEmbeddingsModule.d.ts.map +1 -0
  231. package/lib/typescript/modules/natural_language_processing/TokenizerModule.d.ts +12 -0
  232. package/lib/typescript/modules/natural_language_processing/TokenizerModule.d.ts.map +1 -0
  233. package/lib/typescript/native/NativeClassification.d.ts.map +1 -1
  234. package/lib/typescript/native/NativeImageSegmentation.d.ts +10 -0
  235. package/lib/typescript/native/NativeImageSegmentation.d.ts.map +1 -0
  236. package/lib/typescript/native/NativeLLM.d.ts +3 -4
  237. package/lib/typescript/native/NativeLLM.d.ts.map +1 -1
  238. package/lib/typescript/native/NativeObjectDetection.d.ts +1 -1
  239. package/lib/typescript/native/NativeObjectDetection.d.ts.map +1 -1
  240. package/lib/typescript/native/NativeSpeechToText.d.ts +2 -2
  241. package/lib/typescript/native/NativeSpeechToText.d.ts.map +1 -1
  242. package/lib/typescript/native/NativeTextEmbeddings.d.ts +8 -0
  243. package/lib/typescript/native/NativeTextEmbeddings.d.ts.map +1 -0
  244. package/lib/typescript/native/NativeTokenizer.d.ts +12 -0
  245. package/lib/typescript/native/NativeTokenizer.d.ts.map +1 -0
  246. package/lib/typescript/native/RnExecutorchModules.d.ts +18 -41
  247. package/lib/typescript/native/RnExecutorchModules.d.ts.map +1 -1
  248. package/lib/typescript/types/common.d.ts +1 -26
  249. package/lib/typescript/types/common.d.ts.map +1 -1
  250. package/lib/typescript/types/imageSegmentation.d.ts +25 -0
  251. package/lib/typescript/types/imageSegmentation.d.ts.map +1 -0
  252. package/lib/typescript/types/llm.d.ts +38 -0
  253. package/lib/typescript/types/llm.d.ts.map +1 -0
  254. package/lib/typescript/types/{object_detection.d.ts → objectDetection.d.ts} +1 -1
  255. package/lib/typescript/types/objectDetection.d.ts.map +1 -0
  256. package/lib/typescript/types/ocr.d.ts +2 -1
  257. package/lib/typescript/types/ocr.d.ts.map +1 -1
  258. package/lib/typescript/types/stt.d.ts +91 -0
  259. package/lib/typescript/types/stt.d.ts.map +1 -0
  260. package/lib/typescript/utils/ResourceFetcher.d.ts +17 -0
  261. package/lib/typescript/utils/ResourceFetcher.d.ts.map +1 -0
  262. package/lib/typescript/utils/llm.d.ts +3 -0
  263. package/lib/typescript/utils/llm.d.ts.map +1 -0
  264. package/lib/typescript/utils/stt.d.ts +2 -0
  265. package/lib/typescript/utils/stt.d.ts.map +1 -0
  266. package/package.json +13 -49
  267. package/react-native-executorch.podspec +1 -1
  268. package/src/Error.ts +16 -3
  269. package/src/constants/llmDefaults.ts +14 -0
  270. package/src/constants/modelUrls.ts +146 -39
  271. package/src/constants/ocr/models.ts +453 -0
  272. package/src/constants/ocr/symbols.ts +147 -3
  273. package/src/constants/sttDefaults.ts +55 -37
  274. package/src/controllers/LLMController.ts +286 -0
  275. package/src/controllers/OCRController.ts +14 -28
  276. package/src/controllers/SpeechToTextController.ts +318 -180
  277. package/src/controllers/VerticalOCRController.ts +17 -32
  278. package/src/hooks/computer_vision/useClassification.ts +11 -26
  279. package/src/hooks/computer_vision/useImageSegmentation.ts +18 -0
  280. package/src/hooks/computer_vision/useOCR.ts +17 -5
  281. package/src/hooks/computer_vision/useObjectDetection.ts +10 -24
  282. package/src/hooks/computer_vision/useStyleTransfer.ts +9 -25
  283. package/src/hooks/computer_vision/useVerticalOCR.ts +11 -4
  284. package/src/hooks/general/useExecutorchModule.ts +10 -50
  285. package/src/hooks/natural_language_processing/useLLM.ts +80 -97
  286. package/src/hooks/natural_language_processing/useSpeechToText.ts +39 -12
  287. package/src/hooks/natural_language_processing/useTextEmbeddings.ts +18 -0
  288. package/src/hooks/natural_language_processing/useTokenizer.ts +61 -0
  289. package/src/hooks/useModule.ts +32 -92
  290. package/src/index.tsx +16 -2
  291. package/src/modules/BaseModule.ts +16 -26
  292. package/src/modules/computer_vision/ClassificationModule.ts +13 -8
  293. package/src/modules/computer_vision/ImageSegmentationModule.ts +39 -0
  294. package/src/modules/computer_vision/ObjectDetectionModule.ts +13 -8
  295. package/src/modules/computer_vision/StyleTransferModule.ts +13 -8
  296. package/src/modules/general/ExecutorchModule.ts +11 -6
  297. package/src/modules/natural_language_processing/LLMModule.ts +64 -51
  298. package/src/modules/natural_language_processing/SpeechToTextModule.ts +25 -10
  299. package/src/modules/natural_language_processing/TextEmbeddingsModule.ts +18 -0
  300. package/src/modules/natural_language_processing/TokenizerModule.ts +34 -0
  301. package/src/native/NativeClassification.ts +0 -1
  302. package/src/native/NativeImageSegmentation.ts +14 -0
  303. package/src/native/NativeLLM.ts +3 -10
  304. package/src/native/NativeObjectDetection.ts +1 -1
  305. package/src/native/NativeSpeechToText.ts +2 -2
  306. package/src/native/NativeTextEmbeddings.ts +9 -0
  307. package/src/native/NativeTokenizer.ts +13 -0
  308. package/src/native/RnExecutorchModules.ts +54 -234
  309. package/src/types/common.ts +1 -44
  310. package/src/types/imageSegmentation.ts +25 -0
  311. package/src/types/llm.ts +57 -0
  312. package/src/types/ocr.ts +3 -1
  313. package/src/types/stt.ts +93 -0
  314. package/src/utils/ResourceFetcher.ts +196 -0
  315. package/src/utils/llm.ts +34 -0
  316. package/src/utils/stt.ts +28 -0
  317. package/android/src/main/java/com/swmansion/rnexecutorch/utils/llms/ConversationManager.kt +0 -68
  318. package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/_CodeSignature/CodeResources +0 -124
  319. package/ios/RnExecutorch/utils/llms/Constants.h +0 -6
  320. package/ios/RnExecutorch/utils/llms/Constants.mm +0 -23
  321. package/ios/RnExecutorch/utils/llms/ConversationManager.h +0 -26
  322. package/ios/RnExecutorch/utils/llms/ConversationManager.mm +0 -71
  323. package/lib/module/constants/llamaDefaults.js.map +0 -1
  324. package/lib/module/modules/computer_vision/BaseCVModule.js +0 -14
  325. package/lib/module/modules/computer_vision/BaseCVModule.js.map +0 -1
  326. package/lib/module/types/object_detection.js.map +0 -1
  327. package/lib/module/utils/fetchResource.js +0 -93
  328. package/lib/module/utils/fetchResource.js.map +0 -1
  329. package/lib/module/utils/listDownloadedResources.js +0 -13
  330. package/lib/module/utils/listDownloadedResources.js.map +0 -1
  331. package/lib/typescript/constants/llamaDefaults.d.ts.map +0 -1
  332. package/lib/typescript/modules/computer_vision/BaseCVModule.d.ts +0 -9
  333. package/lib/typescript/modules/computer_vision/BaseCVModule.d.ts.map +0 -1
  334. package/lib/typescript/types/object_detection.d.ts.map +0 -1
  335. package/lib/typescript/utils/fetchResource.d.ts +0 -3
  336. package/lib/typescript/utils/fetchResource.d.ts.map +0 -1
  337. package/lib/typescript/utils/listDownloadedResources.d.ts +0 -3
  338. package/lib/typescript/utils/listDownloadedResources.d.ts.map +0 -1
  339. package/src/constants/llamaDefaults.ts +0 -9
  340. package/src/modules/computer_vision/BaseCVModule.ts +0 -22
  341. package/src/utils/fetchResource.ts +0 -106
  342. package/src/utils/listDownloadedResources.ts +0 -12
  343. /package/src/types/{object_detection.ts → objectDetection.ts} +0 -0
@@ -5,52 +5,62 @@ import {
5
5
  WHISPER_TINY_ENCODER,
6
6
  WHISPER_TINY_DECODER,
7
7
  WHISPER_TOKENIZER,
8
+ WHISPER_TINY_MULTILINGUAL_ENCODER,
9
+ WHISPER_TINY_MULTILINGUAL_DECODER,
10
+ WHISPER_TINY_MULTILINGUAL_TOKENIZER,
8
11
  } from './modelUrls';
12
+ import { AvailableModels, ModelConfig } from '../types/stt';
9
13
 
10
14
  export const SAMPLE_RATE = 16_000;
11
15
  export const SECOND = SAMPLE_RATE;
12
16
  export const HAMMING_DIST_THRESHOLD = 1;
13
17
 
14
- export interface ModelConfig {
18
+ const whisperTinyModelConfig = {
15
19
  sources: {
16
- encoder: string;
17
- decoder: string;
18
- };
20
+ encoder: WHISPER_TINY_ENCODER,
21
+ decoder: WHISPER_TINY_DECODER,
22
+ },
19
23
  tokenizer: {
20
- source: string;
21
- sos: number;
22
- eos: number;
23
- specialChar: string;
24
- };
25
- }
24
+ source: WHISPER_TOKENIZER,
25
+ bos: 50257, // FIXME: this is a placeholder and needs to be changed
26
+ eos: 50256, // FIXME: this is a placeholder and needs to be changed
27
+ },
28
+ isMultilingual: false,
29
+ };
30
+
31
+ const moonshineTinyModelConfig = {
32
+ sources: {
33
+ encoder: MOONSHINE_TINY_ENCODER,
34
+ decoder: MOONSHINE_TINY_DECODER,
35
+ },
36
+ tokenizer: {
37
+ source: MOONSHINE_TOKENIZER,
38
+ bos: 1, // FIXME: this is a placeholder and needs to be changed
39
+ eos: 2, // FIXME: this is a placeholder and needs to be changed
40
+ },
41
+ isMultilingual: false,
42
+ };
26
43
 
27
- export const MODEL_CONFIGS: { [key in 'moonshine' | 'whisper']: ModelConfig } =
28
- {
29
- moonshine: {
30
- sources: {
31
- encoder: MOONSHINE_TINY_ENCODER,
32
- decoder: MOONSHINE_TINY_DECODER,
33
- },
34
- tokenizer: {
35
- source: MOONSHINE_TOKENIZER,
36
- sos: 1,
37
- eos: 2,
38
- specialChar: '\u2581',
39
- },
40
- },
41
- whisper: {
42
- sources: {
43
- encoder: WHISPER_TINY_ENCODER,
44
- decoder: WHISPER_TINY_DECODER,
45
- },
46
- tokenizer: {
47
- source: WHISPER_TOKENIZER,
48
- sos: 50257,
49
- eos: 50256,
50
- specialChar: 'Ġ',
51
- },
52
- },
53
- };
44
+ const whisperTinyMultilingualModelConfig = {
45
+ sources: {
46
+ encoder: WHISPER_TINY_MULTILINGUAL_ENCODER,
47
+ decoder: WHISPER_TINY_MULTILINGUAL_DECODER,
48
+ },
49
+ tokenizer: {
50
+ source: WHISPER_TINY_MULTILINGUAL_TOKENIZER,
51
+ bos: 50258, // FIXME: this is a placeholder and needs to be changed
52
+ eos: 50257, // FIXME: this is a placeholder and needs to be changed
53
+ },
54
+ isMultilingual: true,
55
+ };
56
+
57
+ export const MODEL_CONFIGS: {
58
+ [key in AvailableModels]: ModelConfig;
59
+ } = {
60
+ moonshine: moonshineTinyModelConfig,
61
+ whisper: whisperTinyModelConfig,
62
+ whisperMultilingual: whisperTinyMultilingualModelConfig,
63
+ };
54
64
 
55
65
  export const MODES = {
56
66
  fast: {
@@ -66,3 +76,11 @@ export const MODES = {
66
76
  overlapSeconds: 3,
67
77
  },
68
78
  };
79
+
80
+ export const NUM_TOKENS_TO_TRIM = 3;
81
+
82
+ export enum STREAMING_ACTION {
83
+ START,
84
+ DATA,
85
+ STOP,
86
+ }
@@ -0,0 +1,286 @@
1
+ import { EventSubscription } from 'react-native';
2
+ import { ResourceSource } from '../types/common';
3
+ import { ResourceFetcher } from '../utils/ResourceFetcher';
4
+ import { ETError, getError } from '../Error';
5
+ import { Template } from '@huggingface/jinja';
6
+ import { DEFAULT_CHAT_CONFIG } from '../constants/llmDefaults';
7
+ import { readAsStringAsync } from 'expo-file-system';
8
+ import {
9
+ ChatConfig,
10
+ LLMTool,
11
+ Message,
12
+ SPECIAL_TOKENS,
13
+ ToolsConfig,
14
+ } from '../types/llm';
15
+ import { LLMNativeModule } from '../native/RnExecutorchModules';
16
+ import { parseToolCall } from '../utils/llm';
17
+
18
+ export class LLMController {
19
+ private nativeModule: typeof LLMNativeModule;
20
+ private chatConfig: ChatConfig = DEFAULT_CHAT_CONFIG;
21
+ private toolsConfig: ToolsConfig | undefined;
22
+ private tokenizerConfig: any;
23
+ private onToken: EventSubscription | null = null;
24
+ private _response = '';
25
+ private _isReady = false;
26
+ private _isGenerating = false;
27
+ private _messageHistory: Message[] = [];
28
+
29
+ // User callbacks
30
+ private responseCallback: (response: string) => void;
31
+ private messageHistoryCallback: (messageHistory: Message[]) => void;
32
+ private isReadyCallback: (isReady: boolean) => void;
33
+ private isGeneratingCallback: (isGenerating: boolean) => void;
34
+ private onDownloadProgressCallback:
35
+ | ((downloadProgress: number) => void)
36
+ | undefined;
37
+
38
+ constructor({
39
+ responseCallback,
40
+ messageHistoryCallback,
41
+ isReadyCallback,
42
+ isGeneratingCallback,
43
+ onDownloadProgressCallback,
44
+ }: {
45
+ responseCallback?: (response: string) => void;
46
+ messageHistoryCallback?: (messageHistory: Message[]) => void;
47
+ isReadyCallback?: (isReady: boolean) => void;
48
+ isGeneratingCallback?: (isGenerating: boolean) => void;
49
+ onDownloadProgressCallback?: (downloadProgress: number) => void;
50
+ }) {
51
+ this.responseCallback = (response) => {
52
+ this._response = response;
53
+ responseCallback?.(response);
54
+ };
55
+ this.messageHistoryCallback = (messageHistory) => {
56
+ this._messageHistory = messageHistory;
57
+ messageHistoryCallback?.(messageHistory);
58
+ };
59
+ this.isReadyCallback = (isReady) => {
60
+ this._isReady = isReady;
61
+ isReadyCallback?.(isReady);
62
+ };
63
+ this.isGeneratingCallback = (isGenerating) => {
64
+ this._isGenerating = isGenerating;
65
+ isGeneratingCallback?.(isGenerating);
66
+ };
67
+
68
+ this.onDownloadProgressCallback = onDownloadProgressCallback;
69
+
70
+ this.nativeModule = LLMNativeModule;
71
+ }
72
+
73
+ public get response() {
74
+ return this._response;
75
+ }
76
+ public get isReady() {
77
+ return this._isReady;
78
+ }
79
+ public get isGenerating() {
80
+ return this._isGenerating;
81
+ }
82
+ public get messageHistory() {
83
+ return this._messageHistory;
84
+ }
85
+
86
+ public async load({
87
+ modelSource,
88
+ tokenizerSource,
89
+ tokenizerConfigSource,
90
+ }: {
91
+ modelSource: ResourceSource;
92
+ tokenizerSource: ResourceSource;
93
+ tokenizerConfigSource: ResourceSource;
94
+ }) {
95
+ // reset inner state when loading new model
96
+ this.responseCallback('');
97
+ this.messageHistoryCallback(this.chatConfig.initialMessageHistory);
98
+ this.isGeneratingCallback(false);
99
+ this.isReadyCallback(false);
100
+
101
+ try {
102
+ const tokenizerFileUri = await ResourceFetcher.fetch(tokenizerSource);
103
+ const tokenizerConfigFileUri = await ResourceFetcher.fetch(
104
+ tokenizerConfigSource
105
+ );
106
+ this.tokenizerConfig = JSON.parse(
107
+ await readAsStringAsync('file://' + tokenizerConfigFileUri)
108
+ );
109
+
110
+ const modelFileUri = await ResourceFetcher.fetch(
111
+ modelSource,
112
+ this.onDownloadProgressCallback
113
+ );
114
+
115
+ await this.nativeModule.loadLLM(modelFileUri, tokenizerFileUri);
116
+ this.isReadyCallback(true);
117
+ this.onToken = this.nativeModule.onToken((data: string | undefined) => {
118
+ if (!data) {
119
+ return;
120
+ }
121
+ this.responseCallback(this._response + data);
122
+ });
123
+ } catch (e) {
124
+ this.isReadyCallback(false);
125
+ throw new Error(getError(e));
126
+ }
127
+ }
128
+
129
+ public configure({
130
+ chatConfig,
131
+ toolsConfig,
132
+ }: {
133
+ chatConfig?: Partial<ChatConfig>;
134
+ toolsConfig?: ToolsConfig;
135
+ }) {
136
+ this.chatConfig = { ...DEFAULT_CHAT_CONFIG, ...chatConfig };
137
+ this.toolsConfig = toolsConfig;
138
+
139
+ // reset inner state when loading new configuration
140
+ this.responseCallback('');
141
+ this.messageHistoryCallback(this.chatConfig.initialMessageHistory);
142
+ this.isGeneratingCallback(false);
143
+ }
144
+
145
+ public delete() {
146
+ if (this._isGenerating) {
147
+ throw new Error(
148
+ 'Model is generating! You cannot delete the model now. You need to interrupt first.'
149
+ );
150
+ }
151
+ this.onToken?.remove();
152
+ this.onToken = null;
153
+ this.nativeModule.releaseResources();
154
+ this.isReadyCallback(false);
155
+ this.isGeneratingCallback(false);
156
+ }
157
+
158
+ public async forward(input: string) {
159
+ if (!this._isReady) {
160
+ throw new Error(getError(ETError.ModuleNotLoaded));
161
+ }
162
+ try {
163
+ this.responseCallback('');
164
+ this.isGeneratingCallback(true);
165
+ await this.nativeModule.forward(input);
166
+ } catch (e) {
167
+ throw new Error(getError(e));
168
+ } finally {
169
+ this.isGeneratingCallback(false);
170
+ }
171
+ }
172
+
173
+ public interrupt() {
174
+ this.nativeModule.interrupt();
175
+ }
176
+
177
+ public async generate(messages: Message[], tools?: LLMTool[]) {
178
+ if (!this._isReady) {
179
+ throw new Error(getError(ETError.ModuleNotLoaded));
180
+ }
181
+ if (messages.length === 0) {
182
+ throw new Error(`Empty 'messages' array!`);
183
+ }
184
+ if (messages[0] && messages[0].role !== 'system') {
185
+ console.warn(
186
+ `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.`
187
+ );
188
+ }
189
+
190
+ const renderedChat: string = this.applyChatTemplate(
191
+ messages,
192
+ this.tokenizerConfig,
193
+ tools,
194
+ // eslint-disable-next-line camelcase
195
+ { tools_in_user_message: false, add_generation_prompt: true }
196
+ );
197
+
198
+ await this.forward(renderedChat);
199
+
200
+ if (!this._response) {
201
+ return;
202
+ }
203
+
204
+ const cleanedResponse = this._response
205
+ .replaceAll(this.tokenizerConfig.eos_token, '')
206
+ .replaceAll(this.tokenizerConfig.pad_token, '');
207
+ this.responseCallback(cleanedResponse);
208
+ }
209
+
210
+ public async sendMessage(message: string) {
211
+ this.messageHistoryCallback([
212
+ ...this._messageHistory,
213
+ { content: message, role: 'user' },
214
+ ]);
215
+
216
+ const messageHistoryWithPrompt: Message[] = [
217
+ { content: this.chatConfig.systemPrompt, role: 'system' },
218
+ ...this._messageHistory.slice(-this.chatConfig.contextWindowLength),
219
+ ];
220
+
221
+ await this.generate(messageHistoryWithPrompt, this.toolsConfig?.tools);
222
+
223
+ if (!this.toolsConfig || this.toolsConfig.displayToolCalls) {
224
+ this.responseCallback(
225
+ this._response.replace(this.tokenizerConfig.eos_token, '')
226
+ );
227
+ this.messageHistoryCallback([
228
+ ...this._messageHistory,
229
+ { content: this._response, role: 'assistant' },
230
+ ]);
231
+ }
232
+ if (!this.toolsConfig) {
233
+ return;
234
+ }
235
+
236
+ const toolCalls = parseToolCall(this._response);
237
+
238
+ for (const toolCall of toolCalls) {
239
+ this.toolsConfig
240
+ .executeToolCallback(toolCall)
241
+ .then((toolResponse: string | null) => {
242
+ if (toolResponse) {
243
+ this.messageHistoryCallback([
244
+ ...this._messageHistory,
245
+ { content: toolResponse, role: 'assistant' },
246
+ ]);
247
+ }
248
+ });
249
+ }
250
+ }
251
+
252
+ public deleteMessage(index: number) {
253
+ // we delete referenced message and all messages after it
254
+ // so the model responses that used them are deleted as well
255
+ const newMessageHistory = this._messageHistory.slice(0, index);
256
+
257
+ this.messageHistoryCallback(newMessageHistory);
258
+ }
259
+
260
+ private applyChatTemplate(
261
+ messages: Message[],
262
+ tokenizerConfig: any,
263
+ tools?: LLMTool[],
264
+ templateFlags?: Object
265
+ ): string {
266
+ if (!tokenizerConfig.chat_template) {
267
+ throw Error("Tokenizer config doesn't include chat_template");
268
+ }
269
+ const template = new Template(tokenizerConfig.chat_template);
270
+
271
+ const specialTokens = Object.fromEntries(
272
+ SPECIAL_TOKENS.filter((key) => key in tokenizerConfig).map((key) => [
273
+ key,
274
+ tokenizerConfig[key],
275
+ ])
276
+ );
277
+
278
+ const result = template.render({
279
+ messages,
280
+ tools,
281
+ ...templateFlags,
282
+ ...specialTokens,
283
+ });
284
+ return result;
285
+ }
286
+ }
@@ -1,15 +1,12 @@
1
1
  import { symbols } from '../constants/ocr/symbols';
2
2
  import { ETError, getError } from '../Error';
3
- import { _OCRModule } from '../native/RnExecutorchModules';
3
+ import { OCRNativeModule } from '../native/RnExecutorchModules';
4
4
  import { ResourceSource } from '../types/common';
5
5
  import { OCRLanguage } from '../types/ocr';
6
- import {
7
- fetchResource,
8
- calculateDownloadProgres,
9
- } from '../utils/fetchResource';
6
+ import { ResourceFetcher } from '../utils/ResourceFetcher';
10
7
 
11
8
  export class OCRController {
12
- private nativeModule: _OCRModule;
9
+ private nativeModule: typeof OCRNativeModule;
13
10
  public isReady: boolean = false;
14
11
  public isGenerating: boolean = false;
15
12
  public error: string | null = null;
@@ -24,7 +21,7 @@ export class OCRController {
24
21
  isGeneratingCallback = (_isGenerating: boolean) => {},
25
22
  errorCallback = (_error: string) => {},
26
23
  }) {
27
- this.nativeModule = new _OCRModule();
24
+ this.nativeModule = OCRNativeModule;
28
25
  this.modelDownloadProgressCallback = modelDownloadProgressCallback;
29
26
  this.isReadyCallback = isReadyCallback;
30
27
  this.isGeneratingCallback = isGeneratingCallback;
@@ -47,34 +44,23 @@ export class OCRController {
47
44
  if (!symbols[language]) {
48
45
  throw new Error(getError(ETError.LanguageNotSupported));
49
46
  }
47
+
50
48
  this.isReady = false;
51
49
  this.isReadyCallback(false);
52
50
 
53
- const detectorPath = await fetchResource(
51
+ const paths = await ResourceFetcher.fetchMultipleResources(
52
+ this.modelDownloadProgressCallback,
54
53
  detectorSource,
55
- calculateDownloadProgres(4, 0, this.modelDownloadProgressCallback)
54
+ recognizerSources.recognizerLarge,
55
+ recognizerSources.recognizerMedium,
56
+ recognizerSources.recognizerSmall
56
57
  );
57
58
 
58
- const recognizerPaths = {
59
- recognizerLarge: await fetchResource(
60
- recognizerSources.recognizerLarge,
61
- calculateDownloadProgres(4, 1, this.modelDownloadProgressCallback)
62
- ),
63
- recognizerMedium: await fetchResource(
64
- recognizerSources.recognizerMedium,
65
- calculateDownloadProgres(4, 2, this.modelDownloadProgressCallback)
66
- ),
67
- recognizerSmall: await fetchResource(
68
- recognizerSources.recognizerSmall,
69
- calculateDownloadProgres(4, 3, this.modelDownloadProgressCallback)
70
- ),
71
- };
72
-
73
59
  await this.nativeModule.loadModule(
74
- detectorPath,
75
- recognizerPaths.recognizerLarge,
76
- recognizerPaths.recognizerMedium,
77
- recognizerPaths.recognizerSmall,
60
+ paths[0]!,
61
+ paths[1]!,
62
+ paths[2]!,
63
+ paths[3]!,
78
64
  symbols[language]
79
65
  );
80
66