react-native-executorch 0.5.15 → 0.6.0-nightly-897eae9-20251213

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 (277) hide show
  1. package/README.md +42 -36
  2. package/android/CMakeLists.txt +13 -25
  3. package/android/build.gradle +2 -3
  4. package/android/libs/classes.jar +0 -0
  5. package/android/src/main/cpp/CMakeLists.txt +2 -1
  6. package/common/rnexecutorch/RnExecutorchInstaller.cpp +18 -0
  7. package/common/rnexecutorch/TokenizerModule.cpp +3 -3
  8. package/common/rnexecutorch/data_processing/Numerical.cpp +31 -23
  9. package/common/rnexecutorch/data_processing/Numerical.h +6 -1
  10. package/common/rnexecutorch/data_processing/dsp.cpp +0 -46
  11. package/common/rnexecutorch/host_objects/JsiConversions.h +16 -0
  12. package/common/rnexecutorch/host_objects/ModelHostObject.h +26 -11
  13. package/common/rnexecutorch/jsi/OwningArrayBuffer.h +19 -2
  14. package/common/rnexecutorch/metaprogramming/TypeConcepts.h +0 -20
  15. package/common/rnexecutorch/models/BaseModel.cpp +12 -11
  16. package/common/rnexecutorch/models/BaseModel.h +18 -10
  17. package/common/rnexecutorch/models/embeddings/BaseEmbeddings.cpp +3 -11
  18. package/common/rnexecutorch/models/embeddings/text/TextEmbeddings.cpp +0 -1
  19. package/common/rnexecutorch/models/image_segmentation/ImageSegmentation.cpp +6 -12
  20. package/common/rnexecutorch/models/llm/LLM.cpp +25 -8
  21. package/common/rnexecutorch/models/llm/LLM.h +4 -4
  22. package/common/rnexecutorch/models/ocr/CTCLabelConverter.h +1 -1
  23. package/common/rnexecutorch/models/ocr/utils/RecognitionHandlerUtils.cpp +7 -4
  24. package/common/rnexecutorch/models/speech_to_text/SpeechToText.cpp +8 -13
  25. package/common/rnexecutorch/models/speech_to_text/SpeechToText.h +1 -3
  26. package/common/rnexecutorch/models/speech_to_text/asr/ASR.cpp +12 -19
  27. package/common/rnexecutorch/models/speech_to_text/asr/ASR.h +4 -5
  28. package/common/rnexecutorch/models/text_to_image/Constants.h +9 -0
  29. package/common/rnexecutorch/models/text_to_image/Decoder.cpp +32 -0
  30. package/common/rnexecutorch/models/text_to_image/Decoder.h +24 -0
  31. package/common/rnexecutorch/models/text_to_image/Encoder.cpp +44 -0
  32. package/common/rnexecutorch/models/text_to_image/Encoder.h +32 -0
  33. package/common/rnexecutorch/models/text_to_image/Scheduler.cpp +152 -0
  34. package/common/rnexecutorch/models/text_to_image/Scheduler.h +41 -0
  35. package/common/rnexecutorch/models/text_to_image/TextToImage.cpp +141 -0
  36. package/common/rnexecutorch/models/text_to_image/TextToImage.h +64 -0
  37. package/common/rnexecutorch/models/text_to_image/UNet.cpp +38 -0
  38. package/common/rnexecutorch/models/text_to_image/UNet.h +28 -0
  39. package/common/rnexecutorch/models/voice_activity_detection/Constants.h +27 -0
  40. package/common/rnexecutorch/models/voice_activity_detection/Types.h +12 -0
  41. package/common/rnexecutorch/models/voice_activity_detection/Utils.cpp +15 -0
  42. package/common/rnexecutorch/models/voice_activity_detection/Utils.h +13 -0
  43. package/common/rnexecutorch/models/voice_activity_detection/VoiceActivityDetection.cpp +160 -0
  44. package/common/rnexecutorch/models/voice_activity_detection/VoiceActivityDetection.h +36 -0
  45. package/common/rnexecutorch/tests/CMakeLists.txt +30 -0
  46. package/common/rnexecutorch/tests/NumericalTest.cpp +110 -0
  47. package/common/rnexecutorch/tests/README.md +30 -13
  48. package/common/rnexecutorch/threads/GlobalThreadPool.h +4 -0
  49. package/common/runner/arange_util.cpp +44 -0
  50. package/common/runner/arange_util.h +37 -0
  51. package/common/runner/constants.h +28 -0
  52. package/common/runner/io_manager.h +240 -0
  53. package/common/runner/irunner.h +87 -16
  54. package/common/runner/kernel_includes.h +23 -0
  55. package/common/runner/runner.cpp +151 -66
  56. package/common/runner/runner.h +39 -22
  57. package/common/runner/sampler.cpp +8 -1
  58. package/common/runner/sampler.h +4 -2
  59. package/common/runner/stats.h +1 -4
  60. package/common/runner/text_decoder_runner.cpp +26 -12
  61. package/common/runner/text_decoder_runner.h +52 -31
  62. package/common/runner/text_prefiller.cpp +46 -12
  63. package/common/runner/text_prefiller.h +38 -4
  64. package/common/runner/text_token_generator.h +51 -26
  65. package/common/runner/util.h +53 -8
  66. package/ios/RnExecutorch.xcodeproj/project.pbxproj +0 -23
  67. package/lib/module/Error.js +1 -0
  68. package/lib/module/Error.js.map +1 -1
  69. package/lib/module/constants/directories.js +1 -1
  70. package/lib/module/constants/directories.js.map +1 -1
  71. package/lib/module/constants/modelUrls.js +32 -1
  72. package/lib/module/constants/modelUrls.js.map +1 -1
  73. package/lib/module/constants/ocr/models.js +7 -7
  74. package/lib/module/constants/ocr/models.js.map +1 -1
  75. package/lib/module/constants/ocr/symbols.js +3 -2
  76. package/lib/module/constants/ocr/symbols.js.map +1 -1
  77. package/lib/module/controllers/LLMController.js +10 -1
  78. package/lib/module/controllers/LLMController.js.map +1 -1
  79. package/lib/module/controllers/OCRController.js +3 -3
  80. package/lib/module/controllers/OCRController.js.map +1 -1
  81. package/lib/module/controllers/VerticalOCRController.js +2 -2
  82. package/lib/module/controllers/VerticalOCRController.js.map +1 -1
  83. package/lib/module/hooks/computer_vision/useOCR.js +3 -3
  84. package/lib/module/hooks/computer_vision/useOCR.js.map +1 -1
  85. package/lib/module/hooks/{useNonStaticModule.js → computer_vision/useTextToImage.js} +21 -16
  86. package/lib/module/hooks/computer_vision/useTextToImage.js.map +1 -0
  87. package/lib/module/hooks/computer_vision/useVerticalOCR.js +3 -3
  88. package/lib/module/hooks/computer_vision/useVerticalOCR.js.map +1 -1
  89. package/lib/module/hooks/natural_language_processing/useLLM.js +3 -3
  90. package/lib/module/hooks/natural_language_processing/useLLM.js.map +1 -1
  91. package/lib/module/hooks/natural_language_processing/useTokenizer.js +5 -5
  92. package/lib/module/hooks/natural_language_processing/useTokenizer.js.map +1 -1
  93. package/lib/module/hooks/natural_language_processing/useVAD.js +13 -0
  94. package/lib/module/hooks/natural_language_processing/useVAD.js.map +1 -0
  95. package/lib/module/index.js +7 -2
  96. package/lib/module/index.js.map +1 -1
  97. package/lib/module/modules/computer_vision/OCRModule.js +2 -2
  98. package/lib/module/modules/computer_vision/OCRModule.js.map +1 -1
  99. package/lib/module/modules/computer_vision/TextToImageModule.js +48 -0
  100. package/lib/module/modules/computer_vision/TextToImageModule.js.map +1 -0
  101. package/lib/module/modules/computer_vision/VerticalOCRModule.js +2 -2
  102. package/lib/module/modules/computer_vision/VerticalOCRModule.js.map +1 -1
  103. package/lib/module/modules/natural_language_processing/SpeechToTextModule.js +7 -4
  104. package/lib/module/modules/natural_language_processing/SpeechToTextModule.js.map +1 -1
  105. package/lib/module/modules/natural_language_processing/VADModule.js +19 -0
  106. package/lib/module/modules/natural_language_processing/VADModule.js.map +1 -0
  107. package/lib/module/types/llm.js.map +1 -1
  108. package/lib/module/types/vad.js +2 -0
  109. package/lib/module/types/vad.js.map +1 -0
  110. package/lib/module/utils/ResourceFetcher.js +2 -1
  111. package/lib/module/utils/ResourceFetcher.js.map +1 -1
  112. package/lib/module/utils/ResourceFetcherUtils.js +6 -6
  113. package/lib/module/utils/ResourceFetcherUtils.js.map +1 -1
  114. package/lib/typescript/Error.d.ts +1 -0
  115. package/lib/typescript/Error.d.ts.map +1 -1
  116. package/lib/typescript/constants/modelUrls.d.ts +23 -0
  117. package/lib/typescript/constants/modelUrls.d.ts.map +1 -1
  118. package/lib/typescript/constants/ocr/symbols.d.ts +1 -1
  119. package/lib/typescript/constants/ocr/symbols.d.ts.map +1 -1
  120. package/lib/typescript/controllers/LLMController.d.ts.map +1 -1
  121. package/lib/typescript/controllers/OCRController.d.ts +1 -1
  122. package/lib/typescript/controllers/OCRController.d.ts.map +1 -1
  123. package/lib/typescript/controllers/VerticalOCRController.d.ts +1 -1
  124. package/lib/typescript/controllers/VerticalOCRController.d.ts.map +1 -1
  125. package/lib/typescript/hooks/computer_vision/useOCR.d.ts +1 -1
  126. package/lib/typescript/hooks/computer_vision/useOCR.d.ts.map +1 -1
  127. package/lib/typescript/hooks/computer_vision/useTextToImage.d.ts +22 -0
  128. package/lib/typescript/hooks/computer_vision/useTextToImage.d.ts.map +1 -0
  129. package/lib/typescript/hooks/computer_vision/useVerticalOCR.d.ts +1 -1
  130. package/lib/typescript/hooks/computer_vision/useVerticalOCR.d.ts.map +1 -1
  131. package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts.map +1 -1
  132. package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts +2 -2
  133. package/lib/typescript/hooks/natural_language_processing/useVAD.d.ts +16 -0
  134. package/lib/typescript/hooks/natural_language_processing/useVAD.d.ts.map +1 -0
  135. package/lib/typescript/index.d.ts +8 -1
  136. package/lib/typescript/index.d.ts.map +1 -1
  137. package/lib/typescript/modules/computer_vision/OCRModule.d.ts +1 -1
  138. package/lib/typescript/modules/computer_vision/OCRModule.d.ts.map +1 -1
  139. package/lib/typescript/modules/computer_vision/TextToImageModule.d.ts +16 -0
  140. package/lib/typescript/modules/computer_vision/TextToImageModule.d.ts.map +1 -0
  141. package/lib/typescript/modules/computer_vision/VerticalOCRModule.d.ts +1 -1
  142. package/lib/typescript/modules/computer_vision/VerticalOCRModule.d.ts.map +1 -1
  143. package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts +3 -2
  144. package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts.map +1 -1
  145. package/lib/typescript/modules/natural_language_processing/VADModule.d.ts +10 -0
  146. package/lib/typescript/modules/natural_language_processing/VADModule.d.ts.map +1 -0
  147. package/lib/typescript/types/llm.d.ts +2 -0
  148. package/lib/typescript/types/llm.d.ts.map +1 -1
  149. package/lib/typescript/types/vad.d.ts +5 -0
  150. package/lib/typescript/types/vad.d.ts.map +1 -0
  151. package/lib/typescript/utils/ResourceFetcher.d.ts +29 -0
  152. package/lib/typescript/utils/ResourceFetcher.d.ts.map +1 -1
  153. package/lib/typescript/utils/ResourceFetcherUtils.d.ts +2 -2
  154. package/lib/typescript/utils/ResourceFetcherUtils.d.ts.map +1 -1
  155. package/package.json +11 -8
  156. package/react-native-executorch.podspec +9 -9
  157. package/src/Error.ts +1 -0
  158. package/src/constants/directories.ts +1 -1
  159. package/src/constants/modelUrls.ts +36 -1
  160. package/src/constants/ocr/models.ts +7 -7
  161. package/src/constants/ocr/symbols.ts +3 -2
  162. package/src/controllers/LLMController.ts +12 -1
  163. package/src/controllers/OCRController.ts +3 -3
  164. package/src/controllers/VerticalOCRController.ts +2 -2
  165. package/src/hooks/computer_vision/useOCR.ts +4 -5
  166. package/src/hooks/computer_vision/useTextToImage.ts +92 -0
  167. package/src/hooks/computer_vision/useVerticalOCR.ts +4 -5
  168. package/src/hooks/natural_language_processing/useLLM.ts +3 -4
  169. package/src/hooks/natural_language_processing/useTokenizer.ts +5 -5
  170. package/src/hooks/natural_language_processing/useVAD.ts +15 -0
  171. package/src/index.ts +20 -1
  172. package/src/modules/computer_vision/OCRModule.ts +2 -2
  173. package/src/modules/computer_vision/TextToImageModule.ts +93 -0
  174. package/src/modules/computer_vision/VerticalOCRModule.ts +2 -2
  175. package/src/modules/natural_language_processing/SpeechToTextModule.ts +8 -4
  176. package/src/modules/natural_language_processing/VADModule.ts +27 -0
  177. package/src/types/llm.ts +2 -0
  178. package/src/types/vad.ts +4 -0
  179. package/src/utils/ResourceFetcher.ts +2 -1
  180. package/src/utils/ResourceFetcherUtils.ts +8 -8
  181. package/third-party/android/libs/cpuinfo/arm64-v8a/libcpuinfo.so +0 -0
  182. package/third-party/android/libs/executorch/arm64-v8a/libexecutorch.so +0 -0
  183. package/third-party/android/libs/executorch/x86_64/libexecutorch.so +0 -0
  184. package/third-party/android/libs/pthreadpool/arm64-v8a/libpthreadpool.so +0 -0
  185. package/third-party/include/c10/macros/Export.h +0 -78
  186. package/third-party/include/c10/macros/Macros.h +1 -520
  187. package/third-party/include/c10/util/BFloat16-inl.h +1 -339
  188. package/third-party/include/c10/util/BFloat16.h +1 -122
  189. package/third-party/include/c10/util/Half-inl.h +1 -347
  190. package/third-party/include/c10/util/Half.h +6 -419
  191. package/third-party/include/c10/util/TypeSafeSignMath.h +1 -133
  192. package/third-party/include/c10/util/bit_cast.h +1 -43
  193. package/third-party/include/c10/util/complex.h +1 -568
  194. package/third-party/include/c10/util/floating_point_utils.h +1 -33
  195. package/third-party/include/c10/util/irange.h +1 -1
  196. package/third-party/include/c10/util/llvmMathExtras.h +866 -0
  197. package/third-party/include/c10/util/safe_numerics.h +97 -0
  198. package/third-party/include/executorch/ExecuTorchError.h +6 -7
  199. package/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLM.h +12 -0
  200. package/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLMConfig.h +56 -0
  201. package/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLMError.h +16 -0
  202. package/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLMMultimodalRunner.h +227 -0
  203. package/third-party/include/executorch/ExecuTorchLLM/ExecuTorchLLMTextRunner.h +97 -0
  204. package/third-party/include/executorch/ExecuTorchLLM/module.modulemap +4 -0
  205. package/third-party/include/executorch/ExecuTorchLog.h +1 -0
  206. package/third-party/include/executorch/ExecuTorchModule.h +177 -4
  207. package/third-party/include/executorch/ExecuTorchTensor.h +3 -4
  208. package/third-party/include/executorch/ExecuTorchValue.h +1 -7
  209. package/third-party/include/executorch/extension/module/module.h +139 -8
  210. package/third-party/include/executorch/extension/tensor/tensor.h +1 -0
  211. package/third-party/include/executorch/extension/tensor/tensor_ptr.h +88 -26
  212. package/third-party/include/executorch/extension/threadpool/threadpool.h +4 -1
  213. package/third-party/include/executorch/runtime/backend/backend_init_context.h +6 -0
  214. package/third-party/include/executorch/runtime/backend/interface.h +1 -1
  215. package/third-party/include/executorch/runtime/core/error.h +76 -49
  216. package/third-party/include/executorch/runtime/core/exec_aten/util/scalar_type_util.h +18 -4
  217. package/third-party/include/executorch/runtime/core/memory_allocator.h +12 -2
  218. package/third-party/include/executorch/runtime/core/named_data_map.h +1 -11
  219. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/macros/Export.h +0 -78
  220. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/macros/Macros.h +1 -520
  221. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16-inl.h +1 -339
  222. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/BFloat16.h +1 -122
  223. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/Half-inl.h +1 -347
  224. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/Half.h +6 -419
  225. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/TypeSafeSignMath.h +1 -133
  226. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/bit_cast.h +1 -43
  227. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/complex.h +1 -568
  228. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/floating_point_utils.h +1 -33
  229. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/irange.h +1 -1
  230. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/llvmMathExtras.h +866 -0
  231. package/third-party/include/executorch/runtime/core/portable_type/c10/c10/util/safe_numerics.h +97 -0
  232. package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/macros/Export.h +66 -0
  233. package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/macros/Macros.h +553 -0
  234. package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/BFloat16.h +477 -0
  235. package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/Half.h +781 -0
  236. package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/TypeSafeSignMath.h +141 -0
  237. package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/bit_cast.h +49 -0
  238. package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/complex.h +593 -0
  239. package/third-party/include/executorch/runtime/core/portable_type/c10/torch/headeronly/util/floating_point_utils.h +38 -0
  240. package/third-party/include/executorch/runtime/core/tensor_layout.h +1 -1
  241. package/third-party/include/executorch/runtime/executor/merged_data_map.h +142 -0
  242. package/third-party/include/executorch/runtime/executor/method.h +21 -8
  243. package/third-party/include/executorch/runtime/executor/method_meta.h +20 -2
  244. package/third-party/include/executorch/runtime/executor/program.h +0 -10
  245. package/third-party/include/executorch/runtime/kernel/operator_registry.h +1 -1
  246. package/third-party/include/executorch/runtime/platform/compiler.h +2 -0
  247. package/third-party/include/executorch/schema/extended_header.h +10 -1
  248. package/third-party/include/torch/headeronly/macros/Export.h +66 -0
  249. package/third-party/include/torch/headeronly/macros/Macros.h +553 -0
  250. package/third-party/include/torch/headeronly/util/BFloat16.h +477 -0
  251. package/third-party/include/torch/headeronly/util/Half.h +781 -0
  252. package/third-party/include/torch/headeronly/util/TypeSafeSignMath.h +141 -0
  253. package/third-party/include/torch/headeronly/util/bit_cast.h +49 -0
  254. package/third-party/include/torch/headeronly/util/complex.h +593 -0
  255. package/third-party/include/torch/headeronly/util/floating_point_utils.h +38 -0
  256. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/ExecutorchLib +0 -0
  257. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Info.plist +0 -0
  258. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/ExecutorchLib +0 -0
  259. package/third-party/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Info.plist +0 -0
  260. package/common/rnexecutorch/tests/run_all_tests.sh +0 -14
  261. package/common/rnexecutorch/tests/run_test.sh +0 -18
  262. package/ios/RnExecutorch/utils/Conversions.h +0 -14
  263. package/ios/RnExecutorch/utils/ETError.h +0 -26
  264. package/ios/RnExecutorch/utils/ImageProcessor.h +0 -15
  265. package/ios/RnExecutorch/utils/ImageProcessor.mm +0 -147
  266. package/ios/RnExecutorch/utils/Numerical.h +0 -3
  267. package/ios/RnExecutorch/utils/Numerical.mm +0 -18
  268. package/ios/RnExecutorch/utils/ScalarType.h +0 -14
  269. package/ios/RnExecutorch/utils/ScalarType.mm +0 -21
  270. package/lib/module/hooks/useNonStaticModule.js.map +0 -1
  271. package/lib/typescript/hooks/useNonStaticModule.d.ts +0 -21
  272. package/lib/typescript/hooks/useNonStaticModule.d.ts.map +0 -1
  273. package/src/hooks/useNonStaticModule.ts +0 -74
  274. package/third-party/include/executorch/extension/kernel_util/make_boxed_from_unboxed_functor.h +0 -181
  275. package/third-party/include/executorch/extension/kernel_util/meta_programming.h +0 -108
  276. package/third-party/include/executorch/extension/kernel_util/type_list.h +0 -137
  277. package/third-party/include/executorch/extension/threadpool/threadpool_guard.h +0 -35
package/README.md CHANGED
@@ -1,21 +1,24 @@
1
- <div align="right">
2
- <h1 align="left" style="display:inline-block">React Native ExecuTorch
3
- <!-- Discord Badge -->
4
- <a href="https://discord.gg/ZGqqY55qkP">
5
- <img src="https://img.shields.io/badge/Discord-Join%20Us-00008B?logo=discord&logoColor=white&style=for-the-badge" alt="Join our Discord community">
6
- </a>
1
+ <div align="center">
2
+ <h1 align="center" style="display:inline-block">React Native ExecuTorch
7
3
  </h1>
8
4
  </div>
9
5
 
6
+ <div align="center">
7
+ <a href="https://github.com/software-mansion/react-native-executorch/graphs/contributors"><img src="https://img.shields.io/github/contributors/software-mansion/react-native-executorch?style=for-the-badge&color=00008B" alt="GitHub - Contributors"></a>
8
+ <a href="https://github.com/software-mansion/react-native-executorch/stargazers"><img src="https://img.shields.io/github/stars/software-mansion/react-native-executorch?style=for-the-badge&color=00008B" alt="GitHub - Stars"></a>
9
+ <a href="https://discord.gg/ZGqqY55qkP"><img src="https://img.shields.io/badge/Discord-Join%20Us-00008B?logo=discord&logoColor=white&style=for-the-badge" alt="Join our Discord community"></a>
10
+ <a href="https://docs.swmansion.com/react-native-executorch/"><img src="https://img.shields.io/badge/Documentation-00008B?logo=googledocs&logoColor=white&style=for-the-badge" alt="Documentation"></a>
11
+ </div>
12
+
10
13
  ![Software Mansion banner](https://github.com/user-attachments/assets/fa2c4735-e75c-4cc1-970d-88905d95e3a4)
11
14
 
12
15
  <p align="center">
13
- <a href="https://github.com/software-mansion/react-native-executorch/blob/release/0.5/README.md">English</a>
14
- <a href="https://github.com/software-mansion/react-native-executorch/blob/release/0.5/readmes/README_es.md">Español</a>
15
- <a href="https://github.com/software-mansion/react-native-executorch/blob/release/0.5/readmes/README_fr.md">Français</a>
16
- <a href="https://github.com/software-mansion/react-native-executorch/blob/release/0.5/readmes/README_cn.md">简体中文</a>
17
- <a href="https://github.com/software-mansion/react-native-executorch/blob/release/0.5/readmes/README_pt.md">Português</a>
18
- <a href="https://github.com/software-mansion/react-native-executorch/blob/release/0.5/readmes/README_in.md">हिंदी</a>
16
+ <a href="https://github.com/software-mansion/react-native-executorch/blob/main/README.md">English</a>
17
+ <a href="https://github.com/software-mansion/react-native-executorch/blob/main/readmes/README_es.md">Español</a>
18
+ <a href="https://github.com/software-mansion/react-native-executorch/blob/main/readmes/README_fr.md">Français</a>
19
+ <a href="https://github.com/software-mansion/react-native-executorch/blob/main/readmes/README_cn.md">简体中文</a>
20
+ <a href="https://github.com/software-mansion/react-native-executorch/blob/main/readmes/README_pt.md">Português</a>
21
+ <a href="https://github.com/software-mansion/react-native-executorch/blob/main/readmes/README_in.md">हिंदी</a>
19
22
  </p>
20
23
 
21
24
  **React Native ExecuTorch** provides a declarative way to run AI models on-device using React Native, powered by **ExecuTorch** :rocket:. It offers out-of-the-box support for a wide range of LLMs, computer vision models, and more. Visit our [HuggingFace](https://huggingface.co/software-mansion) page to explore these models.
@@ -27,35 +30,33 @@ React Native ExecuTorch bridges the gap between React Native and native platform
27
30
  [![npm version](https://img.shields.io/npm/v/react-native-executorch?color=00008B)](https://www.npmjs.com/package/react-native-executorch)
28
31
  [![CI](https://github.com/software-mansion/react-native-executorch/actions/workflows/ci.yml/badge.svg)](https://github.com/software-mansion/react-native-executorch/actions/workflows/ci.yml)
29
32
 
30
- **Table of contents:**
33
+ <details>
34
+ <summary><strong> :blue_book: Table of Contents </strong></summary>
31
35
 
32
- - [:yin_yang: Supported versions](#yin_yang-supported-versions)
33
- - [:books: Documentation](#books-documentation)
34
- - [:earth_africa: Real-World Example](#earth_africa-real-world-example)
36
+ - [:yin_yang: Supported Versions](#yin_yang-supported-versions)
37
+ - [:earth_africa: Real-world Example](#earth_africa-real-world-example)
35
38
  - [:llama: Quickstart - Running Llama](#llama-quickstart---running-llama)
36
- - [:calling: Demo apps](#calling-demo-apps)
37
- - [:robot: Ready-made models](#robot-ready-made-models)
39
+ - [:calling: Demo Apps](#calling-demo-apps)
40
+ - [:robot: Ready-made Models](#robot-ready-made-models)
41
+ - [:books: Documentation](#books-documentation)
38
42
  - [:balance_scale: License](#balance_scale-license)
39
- - [:soon: What's next?](#soon-whats-next)
43
+ - [:soon: What's Next?](#soon-whats-next)
40
44
 
41
- ## :yin_yang: Supported versions
45
+ </details>
42
46
 
43
- The minimal supported version are:
47
+ ## :yin_yang: Supported Versions
48
+
49
+ The minimal supported version are:
44
50
  * iOS 17.0
45
51
  * Android 13
46
- * React Native 0.76
52
+ * React Native 0.81
47
53
 
48
- > [!IMPORTANT]
49
- > React Native Executorch supports only the [New React Native architecture](https://reactnative.dev/architecture/landing-page).
54
+ > [!IMPORTANT]
55
+ > React Native ExecuTorch supports only the [New React Native architecture](https://reactnative.dev/architecture/landing-page).
50
56
 
51
- ## :books: Documentation
57
+ ## :earth_africa: Real-world Example
52
58
 
53
- Check out how our library can help you build your React Native AI features by visiting our docs:
54
- https://docs.swmansion.com/react-native-executorch
55
-
56
- ## :earth_africa: Real-World Example
57
-
58
- React Native ExecuTorch is powering [Private Mind](https://github.com/software-mansion-labs/private-mind), a privacy-first mobile AI app available on [App Store](https://apps.apple.com/gb/app/private-mind/id6746713439) and [Google Play](https://play.google.com/store/apps/details?id=com.swmansion.privatemind).
59
+ React Native ExecuTorch is powering [Private Mind](https://privatemind.swmansion.com/), a privacy-first mobile AI app available on [App Store](https://apps.apple.com/gb/app/private-mind/id6746713439) and [Google Play](https://play.google.com/store/apps/details?id=com.swmansion.privatemind).
59
60
 
60
61
  <img width="2720" height="1085" alt="Private Mind promo" src="https://github.com/user-attachments/assets/b12296fe-19ac-48fc-9726-da9242700346" />
61
62
 
@@ -90,7 +91,7 @@ function MyComponent() {
90
91
  }
91
92
  ```
92
93
 
93
- ### :three: **Run the model!**
94
+ ### :three: **Run the Model!**
94
95
 
95
96
  ```tsx
96
97
  const handleGenerate = async () => {
@@ -105,7 +106,7 @@ const handleGenerate = async () => {
105
106
  };
106
107
  ```
107
108
 
108
- ## :calling: Demo apps
109
+ ## :calling: Demo Apps
109
110
 
110
111
  We currently host a few example [apps](https://github.com/software-mansion/react-native-executorch/tree/main/apps) demonstrating use cases of our library:
111
112
 
@@ -126,18 +127,23 @@ Then, depending on the platform, choose either iOS or Android:
126
127
  yarn expo run:< ios | android >
127
128
  ```
128
129
 
129
- > [!WARNING]
130
+ > [!WARNING]
130
131
  > Running LLMs requires a significant amount of RAM. If you are encountering unexpected app crashes, try to increase the amount of RAM allocated to the emulator.
131
132
 
132
- ## :robot: Ready-made models
133
+ ## :robot: Ready-made Models
133
134
 
134
135
  Our library has a number of ready-to-use AI models; a complete list is available in the documentation. If you're interested in running your own AI model, you need to first export it to the `.pte` format. Instructions on how to do this are available in the [Python API](https://docs.pytorch.org/executorch/stable/using-executorch-export.html) and [optimum-executorch README](https://github.com/huggingface/optimum-executorch?tab=readme-ov-file#option-2-export-and-load-separately).
135
136
 
137
+ ## :books: Documentation
138
+
139
+ Check out how our library can help you build your React Native AI features by visiting our docs:
140
+ https://docs.swmansion.com/react-native-executorch
141
+
136
142
  ## :balance_scale: License
137
143
 
138
144
  This library is licensed under [The MIT License](./LICENSE).
139
145
 
140
- ## :soon: What's next?
146
+ ## :soon: What's Next?
141
147
 
142
148
  To learn about our upcoming plans and developments, please visit our [milestones](https://github.com/software-mansion/react-native-executorch/milestones).
143
149
 
@@ -2,11 +2,20 @@ cmake_minimum_required(VERSION 3.13)
2
2
  project(RnExecutorch)
3
3
 
4
4
  set (CMAKE_VERBOSE_MAKEFILE ON)
5
+ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
5
6
  set (CMAKE_CXX_STANDARD 20)
6
7
 
7
8
  include("${REACT_NATIVE_DIR}/ReactAndroid/cmake-utils/folly-flags.cmake")
8
9
  add_compile_options(${folly_FLAGS})
9
10
 
11
+
12
+ if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 80)
13
+ include("${REACT_NATIVE_DIR}/ReactCommon/cmake-utils/react-native-flags.cmake")
14
+ target_compile_reactnative_options(react-native-executorch PRIVATE)
15
+ else()
16
+ string(APPEND CMAKE_CXX_FLAGS " -O2 -fstack-protector-all -fexceptions -frtti -std=c++${CMAKE_CXX_STANDARD} -Wall")
17
+ endif()
18
+
10
19
  string(APPEND CMAKE_CXX_FLAGS " -DRCT_NEW_ARCH_ENABLED")
11
20
 
12
21
  set(ANDROID_CPP_DIR "${CMAKE_SOURCE_DIR}/src/main/cpp")
@@ -14,28 +23,7 @@ set(COMMON_CPP_DIR "${CMAKE_SOURCE_DIR}/../common")
14
23
  set(LIBS_DIR "${CMAKE_SOURCE_DIR}/../third-party/android/libs")
15
24
  set(INCLUDE_DIR "${CMAKE_SOURCE_DIR}/../third-party/include")
16
25
 
17
- # FIXME: Below u can see miserable attempts of trying to link tokenizers-cpp
18
- # directly into react-native-executorch instead of it being linked against ExecuTorch
19
- # and then transitively to our library. Please go back to this when we bump ET runtime to the next version.
20
- # The problem with directly linking tokenizers-cpp using a submodule is that we get unresolved symbols for
21
- # some android logging libraries, which are referenced by sentencepiece.
22
-
23
- # set(TOKENIZERS_CPP_DIR "${CMAKE_SOURCE_DIR}/../../../third-party/tokenizers-cpp")
24
- # add_subdirectory("${TOKENIZERS_CPP_DIR}" tokenizers-cpp)
25
-
26
- # # Link Android log library to sentencepiece targets
27
- # if(TARGET sentencepiece-static)
28
- # target_link_libraries(sentencepiece-static INTERFACE log)
29
- # endif()
30
- # if(TARGET sentencepiece_train-static)
31
- # target_link_libraries(sentencepiece_train-static INTERFACE log)
32
- # endif()
33
-
34
- # # Link log library to sentencepiece executables
35
- # foreach(exe spm_encode spm_decode spm_normalize spm_train spm_export_vocab)
36
- # if(TARGET ${exe})
37
- # target_link_libraries(${exe} log)
38
- # endif()
39
- # endforeach()
40
-
41
- add_subdirectory("${ANDROID_CPP_DIR}")
26
+ # Treat third-party headers as system headers to suppress deprecation warnings
27
+ include_directories(SYSTEM "${INCLUDE_DIR}")
28
+
29
+ add_subdirectory("${ANDROID_CPP_DIR}")
@@ -117,12 +117,12 @@ android {
117
117
  targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
118
118
  externalNativeBuild {
119
119
  cmake {
120
- cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all -fopenmp -static-openmp"
121
120
  abiFilters (*reactNativeArchitectures())
122
121
  arguments "-DANDROID_STL=c++_shared",
123
122
  "-DREACT_NATIVE_DIR=${toPlatformFileString(reactNativeRootDir.path)}",
124
123
  "-DBUILD_DIR=${project.buildDir}",
125
- "-DANDROID_TOOLCHAIN=clang"
124
+ "-DANDROID_TOOLCHAIN=clang",
125
+ "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
126
126
  }
127
127
  }
128
128
  }
@@ -168,6 +168,5 @@ dependencies {
168
168
  implementation 'com.facebook.fbjni:fbjni:0.6.0'
169
169
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
170
170
  implementation files('libs/classes.jar')
171
- implementation 'org.opencv:opencv:4.10.0'
172
171
  implementation("com.squareup.okhttp3:okhttp:4.9.2")
173
172
  }
Binary file
@@ -102,7 +102,8 @@ target_link_libraries(
102
102
  ${OPENCV_LIBS}
103
103
  ${OPENCV_THIRD_PARTY_LIBS}
104
104
  ${TOKENIZERS_LIBS}
105
+ ${TOKENIZERS_THIRD_PARTY_LIBS}
105
106
  executorch
106
107
  ${EXECUTORCH_LIBS}
107
108
  z
108
- )
109
+ )
@@ -11,10 +11,18 @@
11
11
  #include <rnexecutorch/models/ocr/OCR.h>
12
12
  #include <rnexecutorch/models/speech_to_text/SpeechToText.h>
13
13
  #include <rnexecutorch/models/style_transfer/StyleTransfer.h>
14
+ #include <rnexecutorch/models/text_to_image/TextToImage.h>
14
15
  #include <rnexecutorch/models/vertical_ocr/VerticalOCR.h>
16
+ #include <rnexecutorch/models/voice_activity_detection/VoiceActivityDetection.h>
15
17
  #include <rnexecutorch/threads/GlobalThreadPool.h>
16
18
  #include <rnexecutorch/threads/utils/ThreadUtils.h>
17
19
 
20
+ #if defined(__ANDROID__) && defined(__aarch64__)
21
+ #include <executorch/extension/threadpool/cpuinfo_utils.h>
22
+ #include <executorch/extension/threadpool/threadpool.h>
23
+ #include <rnexecutorch/Log.h>
24
+ #endif
25
+
18
26
  namespace rnexecutorch {
19
27
 
20
28
  // This function fetches data from a url address. It is implemented in
@@ -38,6 +46,11 @@ void RnExecutorchInstaller::injectJSIBindings(
38
46
  models::image_segmentation::ImageSegmentation>(
39
47
  jsiRuntime, jsCallInvoker, "loadImageSegmentation"));
40
48
 
49
+ jsiRuntime->global().setProperty(
50
+ *jsiRuntime, "loadTextToImage",
51
+ RnExecutorchInstaller::loadModel<models::text_to_image::TextToImage>(
52
+ jsiRuntime, jsCallInvoker, "loadTextToImage"));
53
+
41
54
  jsiRuntime->global().setProperty(
42
55
  *jsiRuntime, "loadClassification",
43
56
  RnExecutorchInstaller::loadModel<models::classification::Classification>(
@@ -87,6 +100,11 @@ void RnExecutorchInstaller::injectJSIBindings(
87
100
  *jsiRuntime, "loadSpeechToText",
88
101
  RnExecutorchInstaller::loadModel<models::speech_to_text::SpeechToText>(
89
102
  jsiRuntime, jsCallInvoker, "loadSpeechToText"));
103
+ jsiRuntime->global().setProperty(
104
+ *jsiRuntime, "loadVAD",
105
+ RnExecutorchInstaller::loadModel<
106
+ models::voice_activity_detection::VoiceActivityDetection>(
107
+ jsiRuntime, jsCallInvoker, "loadVAD"));
90
108
 
91
109
  threads::utils::unsafeSetupThreadPool();
92
110
  threads::GlobalThreadPool::initialize();
@@ -8,9 +8,9 @@ using namespace facebook;
8
8
 
9
9
  TokenizerModule::TokenizerModule(
10
10
  std::string source, std::shared_ptr<react::CallInvoker> callInvoker)
11
- : memorySizeLowerBound(std::filesystem::file_size(source)),
12
- tokenizer(tokenizers::Tokenizer::FromBlobJSON(
13
- file_utils::loadBytesFromFile(source))) {}
11
+ : tokenizer(tokenizers::Tokenizer::FromBlobJSON(
12
+ file_utils::loadBytesFromFile(source))),
13
+ memorySizeLowerBound(std::filesystem::file_size(source)) {}
14
14
 
15
15
  void TokenizerModule::ensureTokenizerLoaded(
16
16
  const std::string &methodName) const {
@@ -4,21 +4,27 @@
4
4
  #include <cmath>
5
5
  #include <limits>
6
6
  #include <numeric>
7
- #include <span>
8
7
  #include <sstream>
9
8
  #include <string>
10
9
 
11
10
  namespace rnexecutorch::numerical {
12
- void softmax(std::span<float> v) {
13
- float max = *std::max_element(v.begin(), v.end());
14
11
 
15
- float sum = 0.0f;
16
- for (float &x : v) {
17
- x = std::exp(x - max);
18
- sum += x;
12
+ void softmax(std::span<float> input) {
13
+ if (input.empty()) {
14
+ return;
19
15
  }
20
- for (float &x : v) {
21
- x /= sum;
16
+
17
+ const auto maxElement = *std::ranges::max_element(input);
18
+
19
+ for (auto &value : input) {
20
+ value = std::exp(value - maxElement);
21
+ }
22
+
23
+ const auto sum = std::reduce(input.begin(), input.end());
24
+
25
+ // sum is at least 1 since exp(max - max) == exp(0) == 1
26
+ for (auto &value : input) {
27
+ value /= sum;
22
28
  }
23
29
  }
24
30
 
@@ -74,22 +80,24 @@ std::vector<float> meanPooling(std::span<const float> modelOutput,
74
80
  auto attnMaskLength = attnMask.size();
75
81
  auto embeddingDim = modelOutput.size() / attnMaskLength;
76
82
 
77
- float maskSum = 0;
78
- for (const auto &v : attnMask) {
79
- maskSum += static_cast<float>(v);
83
+ auto maskSum = std::reduce(attnMask.begin(), attnMask.end());
84
+ std::vector<float> result(embeddingDim, 0.0F);
85
+ if (maskSum == 0LL) {
86
+ return result;
80
87
  }
81
- maskSum = std::max(maskSum, 1e-9f);
82
-
83
- auto result = std::vector<float>();
84
- result.reserve(embeddingDim);
85
- for (size_t i = 0; i < embeddingDim; i++) {
86
- float dimensionSum = 0;
87
- for (size_t j = 0; j < attnMaskLength; j++) {
88
- dimensionSum +=
89
- modelOutput[j * embeddingDim + i] * static_cast<float>(attnMask[j]);
88
+
89
+ for (std::size_t i = 0; i < attnMaskLength; ++i) {
90
+ if (attnMask[i] != 0LL) {
91
+ for (std::size_t j = 0; j < embeddingDim; ++j) {
92
+ result[j] += modelOutput[i * embeddingDim + j];
93
+ }
90
94
  }
91
- result.push_back(dimensionSum / maskSum);
92
95
  }
96
+
97
+ for (auto &value : result) {
98
+ value /= static_cast<float>(maskSum);
99
+ }
100
+
93
101
  return result;
94
102
  }
95
103
 
@@ -100,4 +108,4 @@ template <typename T> bool isClose(T a, T b, T atol) {
100
108
  template bool isClose<float>(float, float, float);
101
109
  template bool isClose<double>(double, double, double);
102
110
 
103
- } // namespace rnexecutorch::numerical
111
+ } // namespace rnexecutorch::numerical
@@ -3,6 +3,10 @@
3
3
  #include <span>
4
4
  #include <vector>
5
5
 
6
+ /**
7
+ * @namespace rnexecutorch::numerical
8
+ * @brief Namespace for numerical operations and transformations.
9
+ */
6
10
  namespace rnexecutorch::numerical {
7
11
 
8
12
  /**
@@ -59,6 +63,7 @@ void normalize(std::span<float> input);
59
63
  */
60
64
  std::vector<float> meanPooling(std::span<const float> modelOutput,
61
65
  std::span<const int64_t> attnMask);
66
+
62
67
  /**
63
68
  * @brief Checks if two floating-point numbers are considered equal.
64
69
  */
@@ -69,4 +74,4 @@ bool isClose(T a, T b,
69
74
  extern template bool isClose<float>(float, float, float);
70
75
  extern template bool isClose<double>(double, double, double);
71
76
 
72
- } // namespace rnexecutorch::numerical
77
+ } // namespace rnexecutorch::numerical
@@ -1,6 +1,4 @@
1
- #include <algorithm>
2
1
  #include <cstddef>
3
- #include <limits>
4
2
  #include <math.h>
5
3
  #include <rnexecutorch/data_processing/FFT.h>
6
4
  #include <rnexecutorch/data_processing/dsp.h>
@@ -18,48 +16,4 @@ std::vector<float> hannWindow(size_t size) {
18
16
  return window;
19
17
  }
20
18
 
21
- std::vector<float> stftFromWaveform(std::span<const float> waveform,
22
- size_t fftWindowSize, size_t hopSize) {
23
- // Initialize FFT
24
- FFT fft(fftWindowSize);
25
-
26
- const auto numFrames = 1 + (waveform.size() - fftWindowSize) / hopSize;
27
- const auto numBins = fftWindowSize / 2;
28
- const auto hann = hannWindow(fftWindowSize);
29
- auto inBuffer = std::vector<float>(fftWindowSize);
30
- auto outBuffer = std::vector<std::complex<float>>(fftWindowSize);
31
-
32
- // Output magnitudes in dB
33
- std::vector<float> magnitudes;
34
- magnitudes.reserve(numFrames * numBins);
35
- const auto magnitudeScale = 1.0f / static_cast<float>(fftWindowSize);
36
- constexpr auto epsilon = std::numeric_limits<float>::epsilon();
37
- constexpr auto dbConversionFactor = 20.0f;
38
-
39
- for (size_t t = 0; t < numFrames; ++t) {
40
- const size_t offset = t * hopSize;
41
- // Clear the input buffer first
42
- std::ranges::fill(inBuffer, 0.0f);
43
-
44
- // Fill frame with windowed signal
45
- const size_t samplesToRead =
46
- std::min(fftWindowSize, waveform.size() - offset);
47
- for (size_t i = 0; i < samplesToRead; i++) {
48
- inBuffer[i] = waveform[offset + i] * hann[i];
49
- }
50
-
51
- fft.doFFT(inBuffer.data(), outBuffer);
52
-
53
- // Calculate magnitudes in dB (only positive frequencies)
54
- for (size_t i = 0; i < numBins; i++) {
55
- const auto magnitude = std::abs(outBuffer[i]) * magnitudeScale;
56
- const auto magnitude_db =
57
- dbConversionFactor * log10f(magnitude + epsilon);
58
- magnitudes.push_back(magnitude_db);
59
- }
60
- }
61
-
62
- return magnitudes;
63
- }
64
-
65
19
  } // namespace rnexecutorch::dsp
@@ -17,6 +17,7 @@
17
17
  #include <rnexecutorch/models/object_detection/Constants.h>
18
18
  #include <rnexecutorch/models/object_detection/Types.h>
19
19
  #include <rnexecutorch/models/ocr/Types.h>
20
+ #include <rnexecutorch/models/voice_activity_detection/Types.h>
20
21
 
21
22
  namespace rnexecutorch::jsi_conversion {
22
23
 
@@ -399,4 +400,19 @@ getJsiValue(const std::vector<models::ocr::types::OCRDetection> &detections,
399
400
  return jsiDetections;
400
401
  }
401
402
 
403
+ inline jsi::Value
404
+ getJsiValue(const std::vector<models::voice_activity_detection::types::Segment>
405
+ &speechSegments,
406
+ jsi::Runtime &runtime) {
407
+ auto jsiSegments = jsi::Array(runtime, speechSegments.size());
408
+ for (size_t i = 0; i < speechSegments.size(); i++) {
409
+ const auto &[start, end] = speechSegments[i];
410
+ auto jsiSegmentObject = jsi::Object(runtime);
411
+ jsiSegmentObject.setProperty(runtime, "start", static_cast<int>(start));
412
+ jsiSegmentObject.setProperty(runtime, "end", static_cast<int>(end));
413
+ jsiSegments.setValueAtIndex(runtime, i, jsiSegmentObject);
414
+ }
415
+ return jsiSegments;
416
+ }
417
+
402
418
  } // namespace rnexecutorch::jsi_conversion
@@ -18,6 +18,8 @@
18
18
  #include <rnexecutorch/models/BaseModel.h>
19
19
  #include <rnexecutorch/models/llm/LLM.h>
20
20
  #include <rnexecutorch/models/ocr/OCR.h>
21
+ #include <rnexecutorch/models/speech_to_text/SpeechToText.h>
22
+ #include <rnexecutorch/models/text_to_image/TextToImage.h>
21
23
  #include <rnexecutorch/models/vertical_ocr/VerticalOCR.h>
22
24
  #include <rnexecutorch/threads/GlobalThreadPool.h>
23
25
 
@@ -63,28 +65,26 @@ public:
63
65
  "decode"));
64
66
  }
65
67
 
66
- if constexpr (meta::HasTranscribe<Model>) {
68
+ if constexpr (meta::SameAs<Model, models::speech_to_text::SpeechToText>) {
69
+ addFunctions(JSI_EXPORT_FUNCTION(ModelHostObject<Model>,
70
+ synchronousHostFunction<&Model::unload>,
71
+ "unload"));
72
+
67
73
  addFunctions(JSI_EXPORT_FUNCTION(ModelHostObject<Model>,
68
74
  promiseHostFunction<&Model::transcribe>,
69
75
  "transcribe"));
70
- }
71
76
 
72
- if constexpr (meta::HasStream<Model>) {
73
77
  addFunctions(JSI_EXPORT_FUNCTION(ModelHostObject<Model>,
74
78
  promiseHostFunction<&Model::stream>,
75
79
  "stream"));
76
- }
77
80
 
78
- if constexpr (meta::HasStreamInsert<Model>) {
79
81
  addFunctions(JSI_EXPORT_FUNCTION(
80
- ModelHostObject<Model>, promiseHostFunction<&Model::streamInsert>,
82
+ ModelHostObject<Model>, synchronousHostFunction<&Model::streamInsert>,
81
83
  "streamInsert"));
82
- }
83
84
 
84
- if constexpr (meta::HasStreamStop<Model>) {
85
- addFunctions(JSI_EXPORT_FUNCTION(ModelHostObject<Model>,
86
- promiseHostFunction<&Model::streamStop>,
87
- "streamStop"));
85
+ addFunctions(JSI_EXPORT_FUNCTION(
86
+ ModelHostObject<Model>, synchronousHostFunction<&Model::streamStop>,
87
+ "streamStop"));
88
88
  }
89
89
 
90
90
  if constexpr (meta::SameAs<Model, TokenizerModule>) {
@@ -128,10 +128,25 @@ public:
128
128
  addFunctions(JSI_EXPORT_FUNCTION(
129
129
  ModelHostObject<Model>,
130
130
  synchronousHostFunction<&Model::setTimeInterval>, "setTimeInterval"));
131
+
132
+ addFunctions(JSI_EXPORT_FUNCTION(
133
+ ModelHostObject<Model>,
134
+ synchronousHostFunction<&Model::setTemperature>, "setTemperature"));
135
+
136
+ addFunctions(JSI_EXPORT_FUNCTION(ModelHostObject<Model>,
137
+ synchronousHostFunction<&Model::setTopp>,
138
+ "setTopp"));
139
+
131
140
  addFunctions(
132
141
  JSI_EXPORT_FUNCTION(ModelHostObject<Model>, unload, "unload"));
133
142
  }
134
143
 
144
+ if constexpr (meta::SameAs<Model, models::text_to_image::TextToImage>) {
145
+ addFunctions(JSI_EXPORT_FUNCTION(
146
+ ModelHostObject<Model>, synchronousHostFunction<&Model::interrupt>,
147
+ "interrupt"));
148
+ }
149
+
135
150
  if constexpr (meta::SameAs<Model, models::ocr::OCR>) {
136
151
  addFunctions(
137
152
  JSI_EXPORT_FUNCTION(ModelHostObject<Model>, unload, "unload"));
@@ -1,6 +1,7 @@
1
1
  #pragma once
2
2
 
3
3
  #include <jsi/jsi.h>
4
+ #include <vector>
4
5
 
5
6
  namespace rnexecutorch {
6
7
 
@@ -19,8 +20,24 @@ using namespace facebook;
19
20
  */
20
21
  class OwningArrayBuffer : public jsi::MutableBuffer {
21
22
  public:
22
- OwningArrayBuffer(const size_t size) : size_(size) {
23
- data_ = new uint8_t[size];
23
+ /**
24
+ * @param size Size of the buffer in bytes.
25
+ */
26
+ OwningArrayBuffer(size_t size) : size_(size) {
27
+ data_ = new uint8_t[size_];
28
+ }
29
+ /**
30
+ * @param data Pointer to the source data.
31
+ * @param size Size of the data in bytes.
32
+ */
33
+ OwningArrayBuffer(const auto &data, size_t size) : size_(size) {
34
+ data_ = new uint8_t[size_];
35
+ std::memcpy(data_, data, size_);
36
+ }
37
+ template <typename T>
38
+ OwningArrayBuffer(const std::vector<T> &vec) : size_(vec.size() * sizeof(T)) {
39
+ data_ = new uint8_t[size_];
40
+ std::memcpy(data_, vec.data(), size_);
24
41
  }
25
42
  ~OwningArrayBuffer() override { delete[] data_; }
26
43
 
@@ -26,26 +26,6 @@ concept HasDecode = requires(T t) {
26
26
  { &T::decode };
27
27
  };
28
28
 
29
- template <typename T>
30
- concept HasTranscribe = requires(T t) {
31
- { &T::transcribe };
32
- };
33
-
34
- template <typename T>
35
- concept HasStream = requires(T t) {
36
- { &T::stream };
37
- };
38
-
39
- template <typename T>
40
- concept HasStreamInsert = requires(T t) {
41
- { &T::streamInsert };
42
- };
43
-
44
- template <typename T>
45
- concept HasStreamStop = requires(T t) {
46
- { &T::streamStop };
47
- };
48
-
49
29
  template <typename T>
50
30
  concept IsNumeric = std::is_arithmetic_v<T>;
51
31