react-native-executorch 0.7.0-nightly-b4770df-20260205 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (296) hide show
  1. package/common/rnexecutorch/ErrorCodes.h +15 -30
  2. package/common/rnexecutorch/host_objects/ModelHostObject.h +5 -0
  3. package/common/rnexecutorch/models/llm/LLM.cpp +7 -0
  4. package/common/rnexecutorch/models/llm/LLM.h +1 -0
  5. package/lib/module/constants/llmDefaults.js +31 -0
  6. package/lib/module/constants/llmDefaults.js.map +1 -1
  7. package/lib/module/constants/modelUrls.js +220 -0
  8. package/lib/module/constants/modelUrls.js.map +1 -1
  9. package/lib/module/constants/ocr/models.js +255 -73
  10. package/lib/module/constants/ocr/models.js.map +1 -1
  11. package/lib/module/constants/ocr/symbols.js +4 -0
  12. package/lib/module/constants/ocr/symbols.js.map +1 -1
  13. package/lib/module/constants/tts/models.js +6 -2
  14. package/lib/module/constants/tts/models.js.map +1 -1
  15. package/lib/module/constants/tts/voices.js +27 -3
  16. package/lib/module/constants/tts/voices.js.map +1 -1
  17. package/lib/module/constants/versions.js +2 -2
  18. package/lib/module/controllers/LLMController.js +9 -0
  19. package/lib/module/controllers/LLMController.js.map +1 -1
  20. package/lib/module/errors/ErrorCodes.js +54 -0
  21. package/lib/module/errors/ErrorCodes.js.map +1 -1
  22. package/lib/module/errors/errorUtils.js +30 -6
  23. package/lib/module/errors/errorUtils.js.map +1 -1
  24. package/lib/module/hooks/computer_vision/useClassification.js +7 -0
  25. package/lib/module/hooks/computer_vision/useClassification.js.map +1 -1
  26. package/lib/module/hooks/computer_vision/useImageEmbeddings.js +8 -0
  27. package/lib/module/hooks/computer_vision/useImageEmbeddings.js.map +1 -1
  28. package/lib/module/hooks/computer_vision/useImageSegmentation.js +7 -0
  29. package/lib/module/hooks/computer_vision/useImageSegmentation.js.map +1 -1
  30. package/lib/module/hooks/computer_vision/useOCR.js +7 -0
  31. package/lib/module/hooks/computer_vision/useOCR.js.map +1 -1
  32. package/lib/module/hooks/computer_vision/useObjectDetection.js +7 -0
  33. package/lib/module/hooks/computer_vision/useObjectDetection.js.map +1 -1
  34. package/lib/module/hooks/computer_vision/useStyleTransfer.js +7 -0
  35. package/lib/module/hooks/computer_vision/useStyleTransfer.js.map +1 -1
  36. package/lib/module/hooks/computer_vision/useTextToImage.js +7 -0
  37. package/lib/module/hooks/computer_vision/useTextToImage.js.map +1 -1
  38. package/lib/module/hooks/computer_vision/useVerticalOCR.js +7 -0
  39. package/lib/module/hooks/computer_vision/useVerticalOCR.js.map +1 -1
  40. package/lib/module/hooks/general/useExecutorchModule.js +8 -0
  41. package/lib/module/hooks/general/useExecutorchModule.js.map +1 -1
  42. package/lib/module/hooks/natural_language_processing/useLLM.js +11 -3
  43. package/lib/module/hooks/natural_language_processing/useLLM.js.map +1 -1
  44. package/lib/module/hooks/natural_language_processing/useSpeechToText.js +8 -0
  45. package/lib/module/hooks/natural_language_processing/useSpeechToText.js.map +1 -1
  46. package/lib/module/hooks/natural_language_processing/useTextEmbeddings.js +7 -0
  47. package/lib/module/hooks/natural_language_processing/useTextEmbeddings.js.map +1 -1
  48. package/lib/module/hooks/natural_language_processing/useTextToSpeech.js +8 -0
  49. package/lib/module/hooks/natural_language_processing/useTextToSpeech.js.map +1 -1
  50. package/lib/module/hooks/natural_language_processing/useTokenizer.js +7 -0
  51. package/lib/module/hooks/natural_language_processing/useTokenizer.js.map +1 -1
  52. package/lib/module/hooks/natural_language_processing/useVAD.js +7 -0
  53. package/lib/module/hooks/natural_language_processing/useVAD.js.map +1 -1
  54. package/lib/module/hooks/useModule.js +12 -0
  55. package/lib/module/hooks/useModule.js.map +1 -1
  56. package/lib/module/index.js +10 -1
  57. package/lib/module/index.js.map +1 -1
  58. package/lib/module/modules/BaseModule.js +22 -0
  59. package/lib/module/modules/BaseModule.js.map +1 -1
  60. package/lib/module/modules/computer_vision/ClassificationModule.js +20 -0
  61. package/lib/module/modules/computer_vision/ClassificationModule.js.map +1 -1
  62. package/lib/module/modules/computer_vision/ImageEmbeddingsModule.js +19 -0
  63. package/lib/module/modules/computer_vision/ImageEmbeddingsModule.js.map +1 -1
  64. package/lib/module/modules/computer_vision/ImageSegmentationModule.js +22 -0
  65. package/lib/module/modules/computer_vision/ImageSegmentationModule.js.map +1 -1
  66. package/lib/module/modules/computer_vision/OCRModule.js +26 -0
  67. package/lib/module/modules/computer_vision/OCRModule.js.map +1 -1
  68. package/lib/module/modules/computer_vision/ObjectDetectionModule.js +22 -0
  69. package/lib/module/modules/computer_vision/ObjectDetectionModule.js.map +1 -1
  70. package/lib/module/modules/computer_vision/StyleTransferModule.js +20 -0
  71. package/lib/module/modules/computer_vision/StyleTransferModule.js.map +1 -1
  72. package/lib/module/modules/computer_vision/TextToImageModule.js +33 -0
  73. package/lib/module/modules/computer_vision/TextToImageModule.js.map +1 -1
  74. package/lib/module/modules/computer_vision/VerticalOCRModule.js +27 -0
  75. package/lib/module/modules/computer_vision/VerticalOCRModule.js.map +1 -1
  76. package/lib/module/modules/general/ExecutorchModule.js +21 -0
  77. package/lib/module/modules/general/ExecutorchModule.js.map +1 -1
  78. package/lib/module/modules/natural_language_processing/LLMModule.js +104 -0
  79. package/lib/module/modules/natural_language_processing/LLMModule.js.map +1 -1
  80. package/lib/module/modules/natural_language_processing/SpeechToTextModule.js +67 -21
  81. package/lib/module/modules/natural_language_processing/SpeechToTextModule.js.map +1 -1
  82. package/lib/module/modules/natural_language_processing/TextEmbeddingsModule.js +21 -0
  83. package/lib/module/modules/natural_language_processing/TextEmbeddingsModule.js.map +1 -1
  84. package/lib/module/modules/natural_language_processing/TextToSpeechModule.js +40 -0
  85. package/lib/module/modules/natural_language_processing/TextToSpeechModule.js.map +1 -1
  86. package/lib/module/modules/natural_language_processing/TokenizerModule.js +54 -2
  87. package/lib/module/modules/natural_language_processing/TokenizerModule.js.map +1 -1
  88. package/lib/module/modules/natural_language_processing/VADModule.js +20 -0
  89. package/lib/module/modules/natural_language_processing/VADModule.js.map +1 -1
  90. package/lib/module/types/classification.js +4 -0
  91. package/lib/module/types/classification.js.map +1 -0
  92. package/lib/module/types/common.js +96 -0
  93. package/lib/module/types/common.js.map +1 -1
  94. package/lib/module/types/executorchModule.js +4 -0
  95. package/lib/module/types/executorchModule.js.map +1 -0
  96. package/lib/module/types/imageEmbeddings.js +4 -0
  97. package/lib/module/types/imageEmbeddings.js.map +1 -0
  98. package/lib/module/types/imageSegmentation.js +22 -1
  99. package/lib/module/types/imageSegmentation.js.map +1 -1
  100. package/lib/module/types/llm.js +80 -2
  101. package/lib/module/types/llm.js.map +1 -1
  102. package/lib/module/types/objectDetection.js +42 -2
  103. package/lib/module/types/objectDetection.js.map +1 -1
  104. package/lib/module/types/styleTransfer.js +4 -0
  105. package/lib/module/types/styleTransfer.js.map +1 -0
  106. package/lib/module/types/textEmbeddings.js +4 -0
  107. package/lib/module/types/textEmbeddings.js.map +1 -0
  108. package/lib/module/types/tokenizer.js +4 -0
  109. package/lib/module/types/tokenizer.js.map +1 -0
  110. package/lib/module/types/tti.js +4 -0
  111. package/lib/module/types/tti.js.map +1 -0
  112. package/lib/module/types/vad.js +2 -0
  113. package/lib/module/utils/ResourceFetcher.js +63 -0
  114. package/lib/module/utils/ResourceFetcher.js.map +1 -1
  115. package/lib/module/utils/llm.js +24 -1
  116. package/lib/module/utils/llm.js.map +1 -1
  117. package/lib/typescript/constants/llmDefaults.d.ts +27 -0
  118. package/lib/typescript/constants/llmDefaults.d.ts.map +1 -1
  119. package/lib/typescript/constants/modelUrls.d.ts +165 -0
  120. package/lib/typescript/constants/modelUrls.d.ts.map +1 -1
  121. package/lib/typescript/constants/ocr/models.d.ts +189 -315
  122. package/lib/typescript/constants/ocr/models.d.ts.map +1 -1
  123. package/lib/typescript/constants/ocr/symbols.d.ts +3 -0
  124. package/lib/typescript/constants/ocr/symbols.d.ts.map +1 -1
  125. package/lib/typescript/constants/tts/models.d.ts +4 -0
  126. package/lib/typescript/constants/tts/models.d.ts.map +1 -1
  127. package/lib/typescript/constants/tts/voices.d.ts +24 -0
  128. package/lib/typescript/constants/tts/voices.d.ts.map +1 -1
  129. package/lib/typescript/constants/versions.d.ts +2 -2
  130. package/lib/typescript/controllers/LLMController.d.ts +2 -0
  131. package/lib/typescript/controllers/LLMController.d.ts.map +1 -1
  132. package/lib/typescript/errors/ErrorCodes.d.ts +54 -0
  133. package/lib/typescript/errors/ErrorCodes.d.ts.map +1 -1
  134. package/lib/typescript/errors/errorUtils.d.ts +9 -0
  135. package/lib/typescript/errors/errorUtils.d.ts.map +1 -1
  136. package/lib/typescript/hooks/computer_vision/useClassification.d.ts +9 -15
  137. package/lib/typescript/hooks/computer_vision/useClassification.d.ts.map +1 -1
  138. package/lib/typescript/hooks/computer_vision/useImageEmbeddings.d.ts +9 -15
  139. package/lib/typescript/hooks/computer_vision/useImageEmbeddings.d.ts.map +1 -1
  140. package/lib/typescript/hooks/computer_vision/useImageSegmentation.d.ts +9 -38
  141. package/lib/typescript/hooks/computer_vision/useImageSegmentation.d.ts.map +1 -1
  142. package/lib/typescript/hooks/computer_vision/useOCR.d.ts +9 -19
  143. package/lib/typescript/hooks/computer_vision/useOCR.d.ts.map +1 -1
  144. package/lib/typescript/hooks/computer_vision/useObjectDetection.d.ts +9 -15
  145. package/lib/typescript/hooks/computer_vision/useObjectDetection.d.ts.map +1 -1
  146. package/lib/typescript/hooks/computer_vision/useStyleTransfer.d.ts +9 -15
  147. package/lib/typescript/hooks/computer_vision/useStyleTransfer.d.ts.map +1 -1
  148. package/lib/typescript/hooks/computer_vision/useTextToImage.d.ts +9 -22
  149. package/lib/typescript/hooks/computer_vision/useTextToImage.d.ts.map +1 -1
  150. package/lib/typescript/hooks/computer_vision/useVerticalOCR.d.ts +9 -20
  151. package/lib/typescript/hooks/computer_vision/useVerticalOCR.d.ts.map +1 -1
  152. package/lib/typescript/hooks/general/useExecutorchModule.d.ts +9 -13
  153. package/lib/typescript/hooks/general/useExecutorchModule.d.ts.map +1 -1
  154. package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts +9 -10
  155. package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts.map +1 -1
  156. package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts +9 -19
  157. package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts.map +1 -1
  158. package/lib/typescript/hooks/natural_language_processing/useTextEmbeddings.d.ts +9 -16
  159. package/lib/typescript/hooks/natural_language_processing/useTextEmbeddings.d.ts.map +1 -1
  160. package/lib/typescript/hooks/natural_language_processing/useTextToSpeech.d.ts +9 -15
  161. package/lib/typescript/hooks/natural_language_processing/useTextToSpeech.d.ts.map +1 -1
  162. package/lib/typescript/hooks/natural_language_processing/useTokenizer.d.ts +9 -18
  163. package/lib/typescript/hooks/natural_language_processing/useTokenizer.d.ts.map +1 -1
  164. package/lib/typescript/hooks/natural_language_processing/useVAD.d.ts +9 -15
  165. package/lib/typescript/hooks/natural_language_processing/useVAD.d.ts.map +1 -1
  166. package/lib/typescript/hooks/useModule.d.ts +12 -0
  167. package/lib/typescript/hooks/useModule.d.ts.map +1 -1
  168. package/lib/typescript/index.d.ts +10 -1
  169. package/lib/typescript/index.d.ts.map +1 -1
  170. package/lib/typescript/modules/BaseModule.d.ts +20 -0
  171. package/lib/typescript/modules/BaseModule.d.ts.map +1 -1
  172. package/lib/typescript/modules/computer_vision/ClassificationModule.d.ts +21 -1
  173. package/lib/typescript/modules/computer_vision/ClassificationModule.d.ts.map +1 -1
  174. package/lib/typescript/modules/computer_vision/ImageEmbeddingsModule.d.ts +17 -0
  175. package/lib/typescript/modules/computer_vision/ImageEmbeddingsModule.d.ts.map +1 -1
  176. package/lib/typescript/modules/computer_vision/ImageSegmentationModule.d.ts +21 -3
  177. package/lib/typescript/modules/computer_vision/ImageSegmentationModule.d.ts.map +1 -1
  178. package/lib/typescript/modules/computer_vision/OCRModule.d.ts +25 -2
  179. package/lib/typescript/modules/computer_vision/OCRModule.d.ts.map +1 -1
  180. package/lib/typescript/modules/computer_vision/ObjectDetectionModule.d.ts +20 -0
  181. package/lib/typescript/modules/computer_vision/ObjectDetectionModule.d.ts.map +1 -1
  182. package/lib/typescript/modules/computer_vision/StyleTransferModule.d.ts +18 -0
  183. package/lib/typescript/modules/computer_vision/StyleTransferModule.d.ts.map +1 -1
  184. package/lib/typescript/modules/computer_vision/TextToImageModule.d.ts +29 -0
  185. package/lib/typescript/modules/computer_vision/TextToImageModule.d.ts.map +1 -1
  186. package/lib/typescript/modules/computer_vision/VerticalOCRModule.d.ts +26 -2
  187. package/lib/typescript/modules/computer_vision/VerticalOCRModule.d.ts.map +1 -1
  188. package/lib/typescript/modules/general/ExecutorchModule.d.ts +19 -0
  189. package/lib/typescript/modules/general/ExecutorchModule.d.ts.map +1 -1
  190. package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts +97 -7
  191. package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts.map +1 -1
  192. package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts +62 -4
  193. package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts.map +1 -1
  194. package/lib/typescript/modules/natural_language_processing/TextEmbeddingsModule.d.ts +19 -0
  195. package/lib/typescript/modules/natural_language_processing/TextEmbeddingsModule.d.ts.map +1 -1
  196. package/lib/typescript/modules/natural_language_processing/TextToSpeechModule.d.ts +37 -2
  197. package/lib/typescript/modules/natural_language_processing/TextToSpeechModule.d.ts.map +1 -1
  198. package/lib/typescript/modules/natural_language_processing/TokenizerModule.d.ts +47 -2
  199. package/lib/typescript/modules/natural_language_processing/TokenizerModule.d.ts.map +1 -1
  200. package/lib/typescript/modules/natural_language_processing/VADModule.d.ts +18 -0
  201. package/lib/typescript/modules/natural_language_processing/VADModule.d.ts.map +1 -1
  202. package/lib/typescript/types/classification.d.ts +50 -0
  203. package/lib/typescript/types/classification.d.ts.map +1 -0
  204. package/lib/typescript/types/common.d.ts +92 -0
  205. package/lib/typescript/types/common.d.ts.map +1 -1
  206. package/lib/typescript/types/executorchModule.d.ts +45 -0
  207. package/lib/typescript/types/executorchModule.d.ts.map +1 -0
  208. package/lib/typescript/types/imageEmbeddings.d.ts +48 -0
  209. package/lib/typescript/types/imageEmbeddings.d.ts.map +1 -0
  210. package/lib/typescript/types/imageSegmentation.d.ts +55 -0
  211. package/lib/typescript/types/imageSegmentation.d.ts.map +1 -1
  212. package/lib/typescript/types/llm.d.ts +193 -5
  213. package/lib/typescript/types/llm.d.ts.map +1 -1
  214. package/lib/typescript/types/objectDetection.d.ts +71 -2
  215. package/lib/typescript/types/objectDetection.d.ts.map +1 -1
  216. package/lib/typescript/types/ocr.d.ts +97 -2
  217. package/lib/typescript/types/ocr.d.ts.map +1 -1
  218. package/lib/typescript/types/stt.d.ts +114 -0
  219. package/lib/typescript/types/stt.d.ts.map +1 -1
  220. package/lib/typescript/types/styleTransfer.d.ts +48 -0
  221. package/lib/typescript/types/styleTransfer.d.ts.map +1 -0
  222. package/lib/typescript/types/textEmbeddings.d.ts +53 -0
  223. package/lib/typescript/types/textEmbeddings.d.ts.map +1 -0
  224. package/lib/typescript/types/tokenizer.d.ts +75 -0
  225. package/lib/typescript/types/tokenizer.d.ts.map +1 -0
  226. package/lib/typescript/types/tti.d.ts +74 -0
  227. package/lib/typescript/types/tti.d.ts.map +1 -0
  228. package/lib/typescript/types/tts.d.ts +77 -0
  229. package/lib/typescript/types/tts.d.ts.map +1 -1
  230. package/lib/typescript/types/vad.d.ts +53 -0
  231. package/lib/typescript/types/vad.d.ts.map +1 -1
  232. package/lib/typescript/utils/ResourceFetcher.d.ts +55 -0
  233. package/lib/typescript/utils/ResourceFetcher.d.ts.map +1 -1
  234. package/lib/typescript/utils/llm.d.ts +22 -0
  235. package/lib/typescript/utils/llm.d.ts.map +1 -1
  236. package/package.json +1 -1
  237. package/src/constants/llmDefaults.ts +27 -0
  238. package/src/constants/modelUrls.ts +166 -0
  239. package/src/constants/ocr/models.ts +192 -266
  240. package/src/constants/ocr/symbols.ts +3 -0
  241. package/src/constants/tts/models.ts +6 -2
  242. package/src/constants/tts/voices.ts +27 -3
  243. package/src/constants/versions.ts +2 -2
  244. package/src/controllers/LLMController.ts +15 -0
  245. package/src/errors/ErrorCodes.ts +54 -0
  246. package/src/errors/errorUtils.ts +37 -17
  247. package/src/hooks/computer_vision/useClassification.ts +15 -7
  248. package/src/hooks/computer_vision/useImageEmbeddings.ts +15 -7
  249. package/src/hooks/computer_vision/useImageSegmentation.ts +15 -7
  250. package/src/hooks/computer_vision/useOCR.ts +9 -21
  251. package/src/hooks/computer_vision/useObjectDetection.ts +15 -7
  252. package/src/hooks/computer_vision/useStyleTransfer.ts +15 -7
  253. package/src/hooks/computer_vision/useTextToImage.ts +9 -26
  254. package/src/hooks/computer_vision/useVerticalOCR.ts +9 -19
  255. package/src/hooks/general/useExecutorchModule.ts +12 -7
  256. package/src/hooks/natural_language_processing/useLLM.ts +24 -28
  257. package/src/hooks/natural_language_processing/useSpeechToText.ts +13 -5
  258. package/src/hooks/natural_language_processing/useTextEmbeddings.ts +15 -10
  259. package/src/hooks/natural_language_processing/useTextToSpeech.ts +10 -6
  260. package/src/hooks/natural_language_processing/useTokenizer.ts +10 -6
  261. package/src/hooks/natural_language_processing/useVAD.ts +9 -7
  262. package/src/hooks/useModule.ts +15 -0
  263. package/src/index.ts +10 -5
  264. package/src/modules/BaseModule.ts +20 -0
  265. package/src/modules/computer_vision/ClassificationModule.ts +19 -1
  266. package/src/modules/computer_vision/ImageEmbeddingsModule.ts +17 -0
  267. package/src/modules/computer_vision/ImageSegmentationModule.ts +21 -1
  268. package/src/modules/computer_vision/OCRModule.ts +25 -2
  269. package/src/modules/computer_vision/ObjectDetectionModule.ts +20 -0
  270. package/src/modules/computer_vision/StyleTransferModule.ts +18 -0
  271. package/src/modules/computer_vision/TextToImageModule.ts +29 -0
  272. package/src/modules/computer_vision/VerticalOCRModule.ts +26 -2
  273. package/src/modules/general/ExecutorchModule.ts +19 -0
  274. package/src/modules/natural_language_processing/LLMModule.ts +104 -18
  275. package/src/modules/natural_language_processing/SpeechToTextModule.ts +63 -39
  276. package/src/modules/natural_language_processing/TextEmbeddingsModule.ts +19 -0
  277. package/src/modules/natural_language_processing/TextToSpeechModule.ts +43 -2
  278. package/src/modules/natural_language_processing/TokenizerModule.ts +51 -3
  279. package/src/modules/natural_language_processing/VADModule.ts +18 -0
  280. package/src/types/classification.ts +51 -0
  281. package/src/types/common.ts +93 -0
  282. package/src/types/executorchModule.ts +50 -0
  283. package/src/types/imageEmbeddings.ts +51 -0
  284. package/src/types/imageSegmentation.ts +64 -1
  285. package/src/types/llm.ts +208 -11
  286. package/src/types/objectDetection.ts +79 -1
  287. package/src/types/ocr.ts +107 -2
  288. package/src/types/stt.ts +136 -1
  289. package/src/types/styleTransfer.ts +51 -0
  290. package/src/types/textEmbeddings.ts +58 -0
  291. package/src/types/tokenizer.ts +86 -0
  292. package/src/types/tti.ts +87 -0
  293. package/src/types/tts.ts +85 -2
  294. package/src/types/vad.ts +58 -0
  295. package/src/utils/ResourceFetcher.ts +55 -0
  296. package/src/utils/llm.ts +22 -1
@@ -1,22 +1,33 @@
1
1
  import { LLMController } from '../../controllers/LLMController';
2
2
  import { ResourceSource } from '../../types/common';
3
- import {
4
- ChatConfig,
5
- GenerationConfig,
6
- LLMTool,
7
- Message,
8
- ToolsConfig,
9
- } from '../../types/llm';
3
+ import { LLMConfig, LLMTool, Message } from '../../types/llm';
10
4
 
5
+ /**
6
+ * Module for managing a Large Language Model (LLM) instance.
7
+ *
8
+ * @category Typescript API
9
+ */
11
10
  export class LLMModule {
12
11
  private controller: LLMController;
13
12
 
13
+ /**
14
+ * Creates a new instance of `LLMModule` with optional callbacks.
15
+ * @param optionalCallbacks - Object containing optional callbacks.
16
+ *
17
+ * @returns A new LLMModule instance.
18
+ */
14
19
  constructor({
15
20
  tokenCallback,
16
21
  messageHistoryCallback,
17
22
  }: {
23
+ /**
24
+ * An optional function that will be called on every generated token (`string`) with that token as its only argument.
25
+ */
18
26
  tokenCallback?: (token: string) => void;
19
- responseCallback?: (response: string) => void;
27
+ /**
28
+ * An optional function called on every finished message (`Message[]`).
29
+ * Returns the entire message history.
30
+ */
20
31
  messageHistoryCallback?: (messageHistory: Message[]) => void;
21
32
  } = {}) {
22
33
  this.controller = new LLMController({
@@ -25,6 +36,15 @@ export class LLMModule {
25
36
  });
26
37
  }
27
38
 
39
+ /**
40
+ * Loads the LLM model and tokenizer.
41
+ *
42
+ * @param model - Object containing model, tokenizer, and tokenizer config sources.
43
+ * @param model.modelSource - `ResourceSource` that specifies the location of the model binary.
44
+ * @param model.tokenizerSource - `ResourceSource` pointing to the JSON file which contains the tokenizer.
45
+ * @param model.tokenizerConfigSource - `ResourceSource` pointing to the JSON file which contains the tokenizer config.
46
+ * @param onDownloadProgressCallback - Optional callback to track download progress (value between 0 and 1).
47
+ */
28
48
  async load(
29
49
  model: {
30
50
  modelSource: ResourceSource;
@@ -39,6 +59,11 @@ export class LLMModule {
39
59
  });
40
60
  }
41
61
 
62
+ /**
63
+ * Sets new token callback invoked on every token batch.
64
+ *
65
+ * @param tokenCallback - Callback function to handle new tokens.
66
+ */
42
67
  setTokenCallback({
43
68
  tokenCallback,
44
69
  }: {
@@ -47,44 +72,105 @@ export class LLMModule {
47
72
  this.controller.setTokenCallback(tokenCallback);
48
73
  }
49
74
 
50
- configure({
51
- chatConfig,
52
- toolsConfig,
53
- generationConfig,
54
- }: {
55
- chatConfig?: Partial<ChatConfig>;
56
- toolsConfig?: ToolsConfig;
57
- generationConfig?: GenerationConfig;
58
- }) {
75
+ /**
76
+ * Configures chat and tool calling and generation settings.
77
+ * See [Configuring the model](https://docs.swmansion.com/react-native-executorch/docs/hooks/natural-language-processing/useLLM#configuring-the-model) for details.
78
+ *
79
+ * @param configuration - Configuration object containing `chatConfig`, `toolsConfig`, and `generationConfig`.
80
+ */
81
+ configure({ chatConfig, toolsConfig, generationConfig }: LLMConfig) {
59
82
  this.controller.configure({ chatConfig, toolsConfig, generationConfig });
60
83
  }
61
84
 
85
+ /**
86
+ * Runs model inference with raw input string.
87
+ * You need to provide entire conversation and prompt (in correct format and with special tokens!) in input string to this method.
88
+ * It doesn't manage conversation context. It is intended for users that need access to the model itself without any wrapper.
89
+ * If you want a simple chat with model the consider using `sendMessage`
90
+ *
91
+ * @param input - Raw input string containing the prompt and conversation history.
92
+ * @returns The generated response as a string.
93
+ */
62
94
  async forward(input: string): Promise<string> {
63
95
  return await this.controller.forward(input);
64
96
  }
65
97
 
98
+ /**
99
+ * Runs model to complete chat passed in `messages` argument. It doesn't manage conversation context.
100
+ *
101
+ * @param messages - Array of messages representing the chat history.
102
+ * @param tools - Optional array of tools that can be used during generation.
103
+ * @returns The generated response as a string.
104
+ */
66
105
  async generate(messages: Message[], tools?: LLMTool[]): Promise<string> {
67
106
  return await this.controller.generate(messages, tools);
68
107
  }
69
108
 
109
+ /**
110
+ * Method to add user message to conversation.
111
+ * After model responds it will call `messageHistoryCallback()` containing both user message and model response.
112
+ * It also returns them.
113
+ *
114
+ * @param message - The message string to send.
115
+ * @returns - Updated message history including the new user message and model response.
116
+ */
70
117
  async sendMessage(message: string): Promise<Message[]> {
71
118
  await this.controller.sendMessage(message);
72
119
  return this.controller.messageHistory;
73
120
  }
74
121
 
122
+ /**
123
+ * Deletes all messages starting with message on `index` position.
124
+ * After deletion it will call `messageHistoryCallback()` containing new history.
125
+ * It also returns it.
126
+ *
127
+ * @param index - The index of the message to delete from history.
128
+ * @returns - Updated message history after deletion.
129
+ */
75
130
  deleteMessage(index: number): Message[] {
76
131
  this.controller.deleteMessage(index);
77
132
  return this.controller.messageHistory;
78
133
  }
79
134
 
135
+ /**
136
+ * Interrupts model generation. It may return one more token after interrupt.
137
+ */
80
138
  interrupt() {
81
139
  this.controller.interrupt();
82
140
  }
83
141
 
84
- getGeneratedTokenCount() {
142
+ /**
143
+ * Returns the number of tokens generated in the last response.
144
+ *
145
+ * @returns The count of generated tokens.
146
+ */
147
+ getGeneratedTokenCount(): number {
85
148
  return this.controller.getGeneratedTokenCount();
86
149
  }
87
150
 
151
+ /**
152
+ * Returns the number of prompt tokens in the last message.
153
+ *
154
+ * @returns The count of prompt token.
155
+ */
156
+ getPromptTokensCount() {
157
+ return this.controller.getPromptTokenCount();
158
+ }
159
+
160
+ /**
161
+ * Returns the number of total tokens from the previous generation. This is a sum of prompt tokens and generated tokens.
162
+ *
163
+ * @returns The count of prompt and generated tokens.
164
+ */
165
+ getTotalTokensCount() {
166
+ return this.controller.getTotalTokenCount();
167
+ }
168
+
169
+ /**
170
+ * Method to delete the model from memory.
171
+ * Note you cannot delete model while it's generating.
172
+ * You need to interrupt it first and make sure model stopped generation.
173
+ */
88
174
  delete() {
89
175
  this.controller.delete();
90
176
  }
@@ -1,9 +1,13 @@
1
- import { Logger } from '../../common/Logger';
2
1
  import { DecodingOptions, SpeechToTextModelConfig } from '../../types/stt';
3
2
  import { ResourceFetcher } from '../../utils/ResourceFetcher';
4
3
  import { RnExecutorchErrorCode } from '../../errors/ErrorCodes';
5
4
  import { RnExecutorchError, parseUnknownError } from '../../errors/errorUtils';
6
5
 
6
+ /**
7
+ * Module for Speech to Text (STT) functionalities.
8
+ *
9
+ * @category Typescript API
10
+ */
7
11
  export class SpeechToTextModule {
8
12
  private nativeModule: any;
9
13
 
@@ -14,6 +18,13 @@ export class SpeechToTextModule {
14
18
  ignoreBOM: true,
15
19
  });
16
20
 
21
+ /**
22
+ * Loads the model specified by the config object.
23
+ * `onDownloadProgressCallback` allows you to monitor the current progress of the model download.
24
+ *
25
+ * @param model - Configuration object containing model sources.
26
+ * @param onDownloadProgressCallback - Optional callback to monitor download progress.
27
+ */
17
28
  public async load(
18
29
  model: SpeechToTextModelConfig,
19
30
  onDownloadProgressCallback: (progress: number) => void = () => {}
@@ -48,55 +59,54 @@ export class SpeechToTextModule {
48
59
  );
49
60
  }
50
61
 
62
+ /**
63
+ * Unloads the model from memory.
64
+ */
51
65
  public delete(): void {
52
66
  this.nativeModule.unload();
53
67
  }
54
68
 
55
- public async encode(
56
- waveform: Float32Array | number[]
57
- ): Promise<Float32Array> {
58
- if (Array.isArray(waveform)) {
59
- Logger.info(
60
- 'Passing waveform as number[] is deprecated, use Float32Array instead'
61
- );
62
- waveform = new Float32Array(waveform);
63
- }
69
+ /**
70
+ * Runs the encoding part of the model on the provided waveform.
71
+ * Returns the encoded waveform as a Float32Array.
72
+ *
73
+ * @param waveform - The input audio waveform.
74
+ * @returns The encoded output.
75
+ */
76
+ public async encode(waveform: Float32Array): Promise<Float32Array> {
64
77
  return new Float32Array(await this.nativeModule.encode(waveform));
65
78
  }
66
79
 
80
+ /**
81
+ * Runs the decoder of the model.
82
+ *
83
+ * @param tokens - The input tokens.
84
+ * @param encoderOutput - The encoder output.
85
+ * @returns Decoded output.
86
+ */
67
87
  public async decode(
68
- tokens: Int32Array | number[],
69
- encoderOutput: Float32Array | number[]
88
+ tokens: Int32Array,
89
+ encoderOutput: Float32Array
70
90
  ): Promise<Float32Array> {
71
- if (Array.isArray(tokens)) {
72
- Logger.info(
73
- 'Passing tokens as number[] is deprecated, use Int32Array instead'
74
- );
75
- tokens = new Int32Array(tokens);
76
- }
77
- if (Array.isArray(encoderOutput)) {
78
- Logger.info(
79
- 'Passing encoderOutput as number[] is deprecated, use Float32Array instead'
80
- );
81
- encoderOutput = new Float32Array(encoderOutput);
82
- }
83
91
  return new Float32Array(
84
92
  await this.nativeModule.decode(tokens, encoderOutput)
85
93
  );
86
94
  }
87
95
 
96
+ /**
97
+ * Starts a transcription process for a given input array (16kHz waveform).
98
+ * For multilingual models, specify the language in `options`.
99
+ * Returns the transcription as a string. Passing `number[]` is deprecated.
100
+ *
101
+ * @param waveform - The Float32Array audio data.
102
+ * @param options - Decoding options including language.
103
+ * @returns The transcription string.
104
+ */
88
105
  public async transcribe(
89
- waveform: Float32Array | number[],
106
+ waveform: Float32Array,
90
107
  options: DecodingOptions = {}
91
108
  ): Promise<string> {
92
109
  this.validateOptions(options);
93
-
94
- if (Array.isArray(waveform)) {
95
- Logger.info(
96
- 'Passing waveform as number[] is deprecated, use Float32Array instead'
97
- );
98
- waveform = new Float32Array(waveform);
99
- }
100
110
  const transcriptionBytes = await this.nativeModule.transcribe(
101
111
  waveform,
102
112
  options.language || ''
@@ -104,6 +114,18 @@ export class SpeechToTextModule {
104
114
  return this.textDecoder.decode(new Uint8Array(transcriptionBytes));
105
115
  }
106
116
 
117
+ /**
118
+ * Starts a streaming transcription session.
119
+ * Yields objects with `committed` and `nonCommitted` transcriptions.
120
+ * Committed transcription contains the part of the transcription that is finalized and will not change.
121
+ * Useful for displaying stable results during streaming.
122
+ * Non-committed transcription contains the part of the transcription that is still being processed and may change.
123
+ * Useful for displaying live, partial results during streaming.
124
+ * Use with `streamInsert` and `streamStop` to control the stream.
125
+ *
126
+ * @param options - Decoding options including language.
127
+ * @returns An async generator yielding transcription updates.
128
+ */
107
129
  public async *stream(
108
130
  options: DecodingOptions = {}
109
131
  ): AsyncGenerator<{ committed: string; nonCommitted: string }> {
@@ -159,16 +181,18 @@ export class SpeechToTextModule {
159
181
  }
160
182
  }
161
183
 
162
- public streamInsert(waveform: Float32Array | number[]): void {
163
- if (Array.isArray(waveform)) {
164
- Logger.info(
165
- 'Passing waveform as number[] is deprecated, use Float32Array instead'
166
- );
167
- waveform = new Float32Array(waveform);
168
- }
184
+ /**
185
+ * Inserts a new audio chunk into the streaming transcription session.
186
+ *
187
+ * @param waveform - The audio chunk to insert.
188
+ */
189
+ public streamInsert(waveform: Float32Array): void {
169
190
  this.nativeModule.streamInsert(waveform);
170
191
  }
171
192
 
193
+ /**
194
+ * Stops the current streaming transcription session.
195
+ */
172
196
  public streamStop(): void {
173
197
  this.nativeModule.streamStop();
174
198
  }
@@ -4,7 +4,20 @@ import { BaseModule } from '../BaseModule';
4
4
  import { RnExecutorchErrorCode } from '../../errors/ErrorCodes';
5
5
  import { RnExecutorchError } from '../../errors/errorUtils';
6
6
 
7
+ /**
8
+ * Module for generating text embeddings from input text.
9
+ *
10
+ * @category Typescript API
11
+ */
7
12
  export class TextEmbeddingsModule extends BaseModule {
13
+ /**
14
+ * Loads the model and tokenizer specified by the config object.
15
+ *
16
+ * @param model - Object containing model and tokenizer sources.
17
+ * @param model.modelSource - `ResourceSource` that specifies the location of the text embeddings model binary.
18
+ * @param model.tokenizerSource - `ResourceSource` that specifies the location of the tokenizer JSON file.
19
+ * @param onDownloadProgressCallback - Optional callback to track download progress (value between 0 and 1).
20
+ */
8
21
  async load(
9
22
  model: { modelSource: ResourceSource; tokenizerSource: ResourceSource },
10
23
  onDownloadProgressCallback: (progress: number) => void = () => {}
@@ -32,6 +45,12 @@ export class TextEmbeddingsModule extends BaseModule {
32
45
  this.nativeModule = global.loadTextEmbeddings(modelPath, tokenizerPath);
33
46
  }
34
47
 
48
+ /**
49
+ * Executes the model's forward pass, where `input` is a text that will be embedded.
50
+ *
51
+ * @param input - The text string to embed.
52
+ * @returns A Float32Array containing the vector embeddings.
53
+ */
35
54
  async forward(input: string): Promise<Float32Array> {
36
55
  return new Float32Array(await this.nativeModule.generate(input));
37
56
  }
@@ -8,9 +8,24 @@ import {
8
8
  VoiceConfig,
9
9
  } from '../../types/tts';
10
10
 
11
+ /**
12
+ * Module for Text to Speech (TTS) functionalities.
13
+ *
14
+ * @category Typescript API
15
+ */
11
16
  export class TextToSpeechModule {
17
+ /**
18
+ * Native module instance
19
+ */
12
20
  nativeModule: any = null;
13
21
 
22
+ /**
23
+ * Loads the model and voice assets specified by the config object.
24
+ * `onDownloadProgressCallback` allows you to monitor the current progress.
25
+ *
26
+ * @param config - Configuration object containing `model` source and `voice`.
27
+ * @param onDownloadProgressCallback - Optional callback to monitor download progress.
28
+ */
14
29
  public async load(
15
30
  config: TextToSpeechConfig,
16
31
  onDownloadProgressCallback: (progress: number) => void = () => {}
@@ -73,7 +88,18 @@ export class TextToSpeechModule {
73
88
  );
74
89
  }
75
90
 
76
- public async forward(text: string, speed: number = 1.0) {
91
+ /**
92
+ * Synthesizes the provided text into speech.
93
+ * Returns a promise that resolves to the full audio waveform as a `Float32Array`.
94
+ *
95
+ * @param text The input text to be synthesized.
96
+ * @param speed Optional speed multiplier for the speech synthesis (default is 1.0).
97
+ * @returns A promise resolving to the synthesized audio waveform.
98
+ */
99
+ public async forward(
100
+ text: string,
101
+ speed: number = 1.0
102
+ ): Promise<Float32Array> {
77
103
  if (this.nativeModule == null)
78
104
  throw new RnExecutorchError(
79
105
  RnExecutorchErrorCode.ModuleNotLoaded,
@@ -82,7 +108,16 @@ export class TextToSpeechModule {
82
108
  return await this.nativeModule.generate(text, speed);
83
109
  }
84
110
 
85
- public async *stream({ text, speed }: TextToSpeechStreamingInput) {
111
+ /**
112
+ * Starts a streaming synthesis session. Yields audio chunks as they are generated.
113
+ *
114
+ * @param input - Input object containing text and optional speed.
115
+ * @returns An async generator yielding Float32Array audio chunks.
116
+ */
117
+ public async *stream({
118
+ text,
119
+ speed,
120
+ }: TextToSpeechStreamingInput): AsyncGenerator<Float32Array> {
86
121
  // Stores computed audio segments
87
122
  const queue: Float32Array[] = [];
88
123
 
@@ -124,10 +159,16 @@ export class TextToSpeechModule {
124
159
  }
125
160
  }
126
161
 
162
+ /**
163
+ * Stops the streaming process if there is any ongoing.
164
+ */
127
165
  public streamStop(): void {
128
166
  this.nativeModule.streamStop();
129
167
  }
130
168
 
169
+ /**
170
+ * Unloads the model from memory.
171
+ */
131
172
  delete() {
132
173
  if (this.nativeModule !== null) {
133
174
  this.nativeModule.unload();
@@ -3,9 +3,24 @@ import { ResourceFetcher } from '../../utils/ResourceFetcher';
3
3
  import { RnExecutorchError } from '../../errors/errorUtils';
4
4
  import { RnExecutorchErrorCode } from '../../errors/ErrorCodes';
5
5
 
6
+ /**
7
+ * Module for Tokenizer functionalities.
8
+ *
9
+ * @category Typescript API
10
+ */
6
11
  export class TokenizerModule {
12
+ /**
13
+ * Native module instance
14
+ */
7
15
  nativeModule: any;
8
16
 
17
+ /**
18
+ * Loads the tokenizer from the specified source.
19
+ * `tokenizerSource` is a string that points to the location of the tokenizer JSON file.
20
+ *
21
+ * @param tokenizer - Object containing `tokenizerSource`.
22
+ * @param onDownloadProgressCallback - Optional callback to monitor download progress.
23
+ */
9
24
  async load(
10
25
  tokenizer: { tokenizerSource: ResourceSource },
11
26
  onDownloadProgressCallback: (progress: number) => void = () => {}
@@ -24,25 +39,58 @@ export class TokenizerModule {
24
39
  this.nativeModule = global.loadTokenizerModule(path);
25
40
  }
26
41
 
27
- async encode(s: string) {
28
- return await this.nativeModule.encode(s);
42
+ /**
43
+ * Converts a string into an array of token IDs.
44
+ *
45
+ * @param input - The input string to be tokenized.
46
+ * @returns An array of token IDs.
47
+ */
48
+ async encode(input: string): Promise<number[]> {
49
+ return await this.nativeModule.encode(input);
29
50
  }
30
51
 
31
- async decode(tokens: number[], skipSpecialTokens: boolean = true) {
52
+ /**
53
+ * Converts an array of token IDs into a string.
54
+ *
55
+ * @param tokens - Array of token IDs to be decoded.
56
+ * @param skipSpecialTokens - Whether to skip special tokens during decoding (default: true).
57
+ * @returns The decoded string.
58
+ */
59
+ async decode(
60
+ tokens: number[],
61
+ skipSpecialTokens: boolean = true
62
+ ): Promise<string> {
32
63
  if (tokens.length === 0) {
33
64
  return '';
34
65
  }
35
66
  return await this.nativeModule.decode(tokens, skipSpecialTokens);
36
67
  }
37
68
 
69
+ /**
70
+ * Returns the size of the tokenizer's vocabulary.
71
+ *
72
+ * @returns The vocabulary size.
73
+ */
38
74
  async getVocabSize(): Promise<number> {
39
75
  return await this.nativeModule.getVocabSize();
40
76
  }
41
77
 
78
+ /**
79
+ * Returns the token associated to the ID.
80
+ *
81
+ * @param tokenId - ID of the token.
82
+ * @returns The token string associated to ID.
83
+ */
42
84
  async idToToken(tokenId: number): Promise<string> {
43
85
  return this.nativeModule.idToToken(tokenId);
44
86
  }
45
87
 
88
+ /**
89
+ * Returns the ID associated to the token.
90
+ *
91
+ * @param token - The token string.
92
+ * @returns The ID associated to the token.
93
+ */
46
94
  async tokenToId(token: string): Promise<number> {
47
95
  return await this.nativeModule.tokenToId(token);
48
96
  }
@@ -5,7 +5,19 @@ import { BaseModule } from '../BaseModule';
5
5
  import { RnExecutorchErrorCode } from '../../errors/ErrorCodes';
6
6
  import { RnExecutorchError } from '../../errors/errorUtils';
7
7
 
8
+ /**
9
+ * Module for Voice Activity Detection (VAD) functionalities.
10
+ *
11
+ * @category Typescript API
12
+ */
8
13
  export class VADModule extends BaseModule {
14
+ /**
15
+ * Loads the model, where `modelSource` is a string that specifies the location of the model binary.
16
+ * To track the download progress, supply a callback function `onDownloadProgressCallback`.
17
+ *
18
+ * @param model - Object containing `modelSource`.
19
+ * @param onDownloadProgressCallback - Optional callback to monitor download progress.
20
+ */
9
21
  async load(
10
22
  model: { modelSource: ResourceSource },
11
23
  onDownloadProgressCallback: (progress: number) => void = () => {}
@@ -23,6 +35,12 @@ export class VADModule extends BaseModule {
23
35
  this.nativeModule = global.loadVAD(paths[0] || '');
24
36
  }
25
37
 
38
+ /**
39
+ * Executes the model's forward pass, where `waveform` is a Float32Array representing the audio signal (16kHz).
40
+ *
41
+ * @param waveform - The input audio waveform as a Float32Array. It must represent a mono audio signal sampled at 16kHz.
42
+ * @returns A promise resolving to an array of detected speech segments.
43
+ */
26
44
  async forward(waveform: Float32Array): Promise<Segment[]> {
27
45
  if (this.nativeModule == null)
28
46
  throw new RnExecutorchError(
@@ -0,0 +1,51 @@
1
+ import { RnExecutorchError } from '../errors/errorUtils';
2
+ import { ResourceSource } from './common';
3
+
4
+ /**
5
+ * Props for the `useClassification` hook.
6
+ *
7
+ * @category Types
8
+ * @property {Object} model - An object containing the model source.
9
+ * @property {ResourceSource} model.modelSource - The source of the classification model binary.
10
+ * @property {boolean} [preventLoad] - Boolean that can prevent automatic model loading (and downloading the data if you load it for the first time) after running the hook.
11
+ */
12
+ export interface ClassificationProps {
13
+ model: { modelSource: ResourceSource };
14
+ preventLoad?: boolean;
15
+ }
16
+
17
+ /**
18
+ * Return type for the `useClassification` hook.
19
+ * Manages the state and operations for Computer Vision image classification.
20
+ *
21
+ * @category Types
22
+ */
23
+ export interface ClassificationType {
24
+ /**
25
+ * Contains the error object if the model failed to load, download, or encountered a runtime error during classification.
26
+ */
27
+ error: RnExecutorchError | null;
28
+
29
+ /**
30
+ * Indicates whether the classification model is loaded and ready to process images.
31
+ */
32
+ isReady: boolean;
33
+
34
+ /**
35
+ * Indicates whether the model is currently processing an image.
36
+ */
37
+ isGenerating: boolean;
38
+
39
+ /**
40
+ * Represents the download progress of the model binary as a value between 0 and 1.
41
+ */
42
+ downloadProgress: number;
43
+
44
+ /**
45
+ * Executes the model's forward pass to classify the provided image.
46
+ * @param imageSource - A string representing the image source (e.g., a file path, URI, or base64 string) to be classified.
47
+ * @returns A Promise that resolves to the classification result (typically containing labels and confidence scores).
48
+ * @throws {RnExecutorchError} If the model is not loaded or is currently processing another image.
49
+ */
50
+ forward: (imageSource: string) => Promise<{ [category: string]: number }>;
51
+ }