react-native-executorch 0.5.7 → 0.5.8

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 (107) hide show
  1. package/lib/Error.js +53 -0
  2. package/lib/ThreadPool.d.ts +10 -0
  3. package/lib/ThreadPool.js +28 -0
  4. package/lib/common/Logger.d.ts +8 -0
  5. package/lib/common/Logger.js +19 -0
  6. package/lib/constants/directories.js +2 -0
  7. package/lib/constants/llmDefaults.d.ts +6 -0
  8. package/lib/constants/llmDefaults.js +16 -0
  9. package/lib/constants/modelUrls.d.ts +223 -0
  10. package/lib/constants/modelUrls.js +322 -0
  11. package/lib/constants/ocr/models.d.ts +882 -0
  12. package/lib/constants/ocr/models.js +182 -0
  13. package/lib/constants/ocr/symbols.js +139 -0
  14. package/lib/constants/sttDefaults.d.ts +28 -0
  15. package/lib/constants/sttDefaults.js +68 -0
  16. package/lib/controllers/LLMController.d.ts +47 -0
  17. package/lib/controllers/LLMController.js +213 -0
  18. package/lib/controllers/OCRController.js +67 -0
  19. package/lib/controllers/SpeechToTextController.d.ts +56 -0
  20. package/lib/controllers/SpeechToTextController.js +349 -0
  21. package/lib/controllers/VerticalOCRController.js +70 -0
  22. package/lib/hooks/computer_vision/useClassification.d.ts +15 -0
  23. package/lib/hooks/computer_vision/useClassification.js +7 -0
  24. package/lib/hooks/computer_vision/useImageEmbeddings.d.ts +15 -0
  25. package/lib/hooks/computer_vision/useImageEmbeddings.js +7 -0
  26. package/lib/hooks/computer_vision/useImageSegmentation.d.ts +38 -0
  27. package/lib/hooks/computer_vision/useImageSegmentation.js +7 -0
  28. package/lib/hooks/computer_vision/useOCR.d.ts +20 -0
  29. package/lib/hooks/computer_vision/useOCR.js +41 -0
  30. package/lib/hooks/computer_vision/useObjectDetection.d.ts +15 -0
  31. package/lib/hooks/computer_vision/useObjectDetection.js +7 -0
  32. package/lib/hooks/computer_vision/useStyleTransfer.d.ts +15 -0
  33. package/lib/hooks/computer_vision/useStyleTransfer.js +7 -0
  34. package/lib/hooks/computer_vision/useVerticalOCR.d.ts +21 -0
  35. package/lib/hooks/computer_vision/useVerticalOCR.js +43 -0
  36. package/lib/hooks/general/useExecutorchModule.d.ts +13 -0
  37. package/lib/hooks/general/useExecutorchModule.js +7 -0
  38. package/lib/hooks/natural_language_processing/useLLM.d.ts +10 -0
  39. package/lib/hooks/natural_language_processing/useLLM.js +78 -0
  40. package/lib/hooks/natural_language_processing/useSpeechToText.d.ts +27 -0
  41. package/lib/hooks/natural_language_processing/useSpeechToText.js +49 -0
  42. package/lib/hooks/natural_language_processing/useTextEmbeddings.d.ts +16 -0
  43. package/lib/hooks/natural_language_processing/useTextEmbeddings.js +7 -0
  44. package/lib/hooks/natural_language_processing/useTokenizer.d.ts +17 -0
  45. package/lib/hooks/natural_language_processing/useTokenizer.js +52 -0
  46. package/lib/hooks/useModule.js +45 -0
  47. package/lib/hooks/useNonStaticModule.d.ts +20 -0
  48. package/lib/hooks/useNonStaticModule.js +49 -0
  49. package/lib/index.d.ts +48 -0
  50. package/lib/index.js +58 -0
  51. package/lib/module/modules/natural_language_processing/LLMModule.js +3 -0
  52. package/lib/module/modules/natural_language_processing/LLMModule.js.map +1 -1
  53. package/lib/modules/BaseModule.js +25 -0
  54. package/lib/modules/BaseNonStaticModule.js +14 -0
  55. package/lib/modules/computer_vision/ClassificationModule.d.ts +8 -0
  56. package/lib/modules/computer_vision/ClassificationModule.js +17 -0
  57. package/lib/modules/computer_vision/ImageEmbeddingsModule.d.ts +8 -0
  58. package/lib/modules/computer_vision/ImageEmbeddingsModule.js +17 -0
  59. package/lib/modules/computer_vision/ImageSegmentationModule.d.ts +11 -0
  60. package/lib/modules/computer_vision/ImageSegmentationModule.js +27 -0
  61. package/lib/modules/computer_vision/OCRModule.d.ts +14 -0
  62. package/lib/modules/computer_vision/OCRModule.js +17 -0
  63. package/lib/modules/computer_vision/ObjectDetectionModule.d.ts +9 -0
  64. package/lib/modules/computer_vision/ObjectDetectionModule.js +17 -0
  65. package/lib/modules/computer_vision/StyleTransferModule.d.ts +8 -0
  66. package/lib/modules/computer_vision/StyleTransferModule.js +17 -0
  67. package/lib/modules/computer_vision/VerticalOCRModule.d.ts +14 -0
  68. package/lib/modules/computer_vision/VerticalOCRModule.js +19 -0
  69. package/lib/modules/general/ExecutorchModule.d.ts +7 -0
  70. package/lib/modules/general/ExecutorchModule.js +14 -0
  71. package/lib/modules/natural_language_processing/LLMModule.d.ts +28 -0
  72. package/lib/modules/natural_language_processing/LLMModule.js +45 -0
  73. package/lib/modules/natural_language_processing/SpeechToTextModule.d.ts +24 -0
  74. package/lib/modules/natural_language_processing/SpeechToTextModule.js +36 -0
  75. package/lib/modules/natural_language_processing/TextEmbeddingsModule.d.ts +9 -0
  76. package/lib/modules/natural_language_processing/TextEmbeddingsModule.js +21 -0
  77. package/lib/modules/natural_language_processing/TokenizerModule.d.ts +12 -0
  78. package/lib/modules/natural_language_processing/TokenizerModule.js +30 -0
  79. package/lib/native/NativeETInstaller.js +2 -0
  80. package/lib/native/NativeOCR.js +2 -0
  81. package/lib/native/NativeVerticalOCR.js +2 -0
  82. package/lib/native/RnExecutorchModules.d.ts +7 -0
  83. package/lib/native/RnExecutorchModules.js +18 -0
  84. package/lib/tsconfig.tsbuildinfo +1 -0
  85. package/lib/types/common.d.ts +32 -0
  86. package/lib/types/common.js +25 -0
  87. package/lib/types/imageSegmentation.js +26 -0
  88. package/lib/types/llm.d.ts +46 -0
  89. package/lib/types/llm.js +9 -0
  90. package/lib/types/objectDetection.js +94 -0
  91. package/lib/types/ocr.js +1 -0
  92. package/lib/types/stt.d.ts +94 -0
  93. package/lib/types/stt.js +85 -0
  94. package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts +1 -0
  95. package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts.map +1 -1
  96. package/lib/typescript/types/llm.d.ts +1 -1
  97. package/lib/typescript/types/llm.d.ts.map +1 -1
  98. package/lib/utils/ResourceFetcher.d.ts +24 -0
  99. package/lib/utils/ResourceFetcher.js +305 -0
  100. package/lib/utils/ResourceFetcherUtils.d.ts +54 -0
  101. package/lib/utils/ResourceFetcherUtils.js +127 -0
  102. package/lib/utils/llm.d.ts +6 -0
  103. package/lib/utils/llm.js +72 -0
  104. package/lib/utils/stt.js +21 -0
  105. package/package.json +1 -1
  106. package/src/modules/natural_language_processing/LLMModule.ts +4 -0
  107. package/src/types/llm.ts +1 -1
@@ -0,0 +1,45 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { ETError, getError } from '../Error';
3
+ export const useModule = ({ module, loadArgs, preventLoad = false, }) => {
4
+ const [error, setError] = useState(null);
5
+ const [isReady, setIsReady] = useState(false);
6
+ const [isGenerating, setIsGenerating] = useState(false);
7
+ const [downloadProgress, setDownloadProgress] = useState(0);
8
+ useEffect(() => {
9
+ const loadModule = async () => {
10
+ try {
11
+ setIsReady(false);
12
+ module.onDownloadProgress(setDownloadProgress);
13
+ await module.load(...loadArgs);
14
+ setIsReady(true);
15
+ }
16
+ catch (err) {
17
+ setError(err.message);
18
+ }
19
+ };
20
+ if (!preventLoad) {
21
+ loadModule();
22
+ }
23
+ // eslint-disable-next-line react-hooks/exhaustive-deps
24
+ }, [...loadArgs, preventLoad]);
25
+ const forward = async (...input) => {
26
+ if (!isReady)
27
+ throw new Error(getError(ETError.ModuleNotLoaded));
28
+ if (isGenerating)
29
+ throw new Error(getError(ETError.ModelGenerating));
30
+ try {
31
+ setIsGenerating(true);
32
+ return await module.forward(...input);
33
+ }
34
+ finally {
35
+ setIsGenerating(false);
36
+ }
37
+ };
38
+ return {
39
+ error,
40
+ isReady,
41
+ isGenerating,
42
+ downloadProgress,
43
+ forward,
44
+ };
45
+ };
@@ -0,0 +1,20 @@
1
+ interface Module {
2
+ load: (...args: any[]) => Promise<void>;
3
+ forward: (...args: any[]) => Promise<any>;
4
+ delete: () => void;
5
+ }
6
+ interface ModuleConstructor<M extends Module> {
7
+ new (): M;
8
+ }
9
+ export declare const useNonStaticModule: <M extends Module, LoadArgs extends Parameters<M["load"]>, ForwardArgs extends Parameters<M["forward"]>, ForwardReturn extends Awaited<ReturnType<M["forward"]>>>({ module, model, preventLoad, }: {
10
+ module: ModuleConstructor<M>;
11
+ model: LoadArgs[0];
12
+ preventLoad?: boolean;
13
+ }) => {
14
+ error: string | null;
15
+ isReady: boolean;
16
+ isGenerating: boolean;
17
+ downloadProgress: number;
18
+ forward: (...input: ForwardArgs) => Promise<ForwardReturn>;
19
+ };
20
+ export {};
@@ -0,0 +1,49 @@
1
+ import { useEffect, useState, useMemo } from 'react';
2
+ import { ETError, getError } from '../Error';
3
+ export const useNonStaticModule = ({ module, model, preventLoad = false, }) => {
4
+ const [error, setError] = useState(null);
5
+ const [isReady, setIsReady] = useState(false);
6
+ const [isGenerating, setIsGenerating] = useState(false);
7
+ const [downloadProgress, setDownloadProgress] = useState(0);
8
+ const moduleInstance = useMemo(() => new module(), [module]);
9
+ useEffect(() => {
10
+ if (preventLoad)
11
+ return;
12
+ (async () => {
13
+ setDownloadProgress(0);
14
+ setError(null);
15
+ try {
16
+ setIsReady(false);
17
+ await moduleInstance.load(model, setDownloadProgress);
18
+ setIsReady(true);
19
+ }
20
+ catch (err) {
21
+ setError(err.message);
22
+ }
23
+ })();
24
+ return () => {
25
+ moduleInstance.delete();
26
+ };
27
+ // eslint-disable-next-line react-hooks/exhaustive-deps
28
+ }, [moduleInstance, ...Object.values(model), preventLoad]);
29
+ const forward = async (...input) => {
30
+ if (!isReady)
31
+ throw new Error(getError(ETError.ModuleNotLoaded));
32
+ if (isGenerating)
33
+ throw new Error(getError(ETError.ModelGenerating));
34
+ try {
35
+ setIsGenerating(true);
36
+ return await moduleInstance.forward(...input);
37
+ }
38
+ finally {
39
+ setIsGenerating(false);
40
+ }
41
+ };
42
+ return {
43
+ error,
44
+ isReady,
45
+ isGenerating,
46
+ downloadProgress,
47
+ forward,
48
+ };
49
+ };
package/lib/index.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ import { SpeechToTextLanguage } from './types/stt';
2
+ declare global {
3
+ var loadStyleTransfer: (source: string) => any;
4
+ var loadImageSegmentation: (source: string) => any;
5
+ var loadClassification: (source: string) => any;
6
+ var loadObjectDetection: (source: string) => any;
7
+ var loadExecutorchModule: (source: string) => any;
8
+ var loadTokenizerModule: (source: string) => any;
9
+ var loadImageEmbeddings: (source: string) => any;
10
+ var loadTextEmbeddings: (modelSource: string, tokenizerSource: string) => any;
11
+ var loadLLM: (modelSource: string, tokenizerSource: string) => any;
12
+ var loadSpeechToText: (encoderSource: string, decoderSource: string, modelName: string) => any;
13
+ }
14
+ export * from './hooks/computer_vision/useClassification';
15
+ export * from './hooks/computer_vision/useObjectDetection';
16
+ export * from './hooks/computer_vision/useStyleTransfer';
17
+ export * from './hooks/computer_vision/useImageSegmentation';
18
+ export * from './hooks/computer_vision/useOCR';
19
+ export * from './hooks/computer_vision/useVerticalOCR';
20
+ export * from './hooks/computer_vision/useImageEmbeddings';
21
+ export * from './hooks/natural_language_processing/useLLM';
22
+ export * from './hooks/natural_language_processing/useSpeechToText';
23
+ export * from './hooks/natural_language_processing/useTextEmbeddings';
24
+ export * from './hooks/natural_language_processing/useTokenizer';
25
+ export * from './hooks/general/useExecutorchModule';
26
+ export * from './modules/computer_vision/ClassificationModule';
27
+ export * from './modules/computer_vision/ObjectDetectionModule';
28
+ export * from './modules/computer_vision/StyleTransferModule';
29
+ export * from './modules/computer_vision/ImageSegmentationModule';
30
+ export * from './modules/computer_vision/OCRModule';
31
+ export * from './modules/computer_vision/VerticalOCRModule';
32
+ export * from './modules/general/ExecutorchModule';
33
+ export * from './modules/computer_vision/ImageEmbeddingsModule';
34
+ export * from './modules/natural_language_processing/LLMModule';
35
+ export * from './modules/natural_language_processing/SpeechToTextModule';
36
+ export * from './modules/natural_language_processing/TextEmbeddingsModule';
37
+ export * from './modules/natural_language_processing/TokenizerModule';
38
+ export * from './utils/ResourceFetcher';
39
+ export * from './utils/llm';
40
+ export * from './types/objectDetection';
41
+ export * from './types/ocr';
42
+ export * from './types/imageSegmentation';
43
+ export * from './types/llm';
44
+ export { SpeechToTextLanguage };
45
+ export * from './constants/modelUrls';
46
+ export * from './constants/ocr/models';
47
+ export * from './constants/llmDefaults';
48
+ export { STREAMING_ACTION, MODES, AvailableModels, } from './constants/sttDefaults';
package/lib/index.js ADDED
@@ -0,0 +1,58 @@
1
+ import { SpeechToTextLanguage } from './types/stt';
2
+ import { ETInstallerNativeModule } from './native/RnExecutorchModules';
3
+ // eslint-disable no-var
4
+ if (global.loadStyleTransfer == null ||
5
+ global.loadImageSegmentation == null ||
6
+ global.loadExecutorchModule == null ||
7
+ global.loadClassification == null ||
8
+ global.loadObjectDetection == null ||
9
+ global.loadTokenizerModule == null ||
10
+ global.loadTextEmbeddings == null ||
11
+ global.loadImageEmbeddings == null ||
12
+ global.loadLLM == null ||
13
+ global.loadSpeechToText == null) {
14
+ if (!ETInstallerNativeModule) {
15
+ throw new Error(`Failed to install react-native-executorch: The native module could not be found.`);
16
+ }
17
+ ETInstallerNativeModule.install();
18
+ }
19
+ // hooks
20
+ export * from './hooks/computer_vision/useClassification';
21
+ export * from './hooks/computer_vision/useObjectDetection';
22
+ export * from './hooks/computer_vision/useStyleTransfer';
23
+ export * from './hooks/computer_vision/useImageSegmentation';
24
+ export * from './hooks/computer_vision/useOCR';
25
+ export * from './hooks/computer_vision/useVerticalOCR';
26
+ export * from './hooks/computer_vision/useImageEmbeddings';
27
+ export * from './hooks/natural_language_processing/useLLM';
28
+ export * from './hooks/natural_language_processing/useSpeechToText';
29
+ export * from './hooks/natural_language_processing/useTextEmbeddings';
30
+ export * from './hooks/natural_language_processing/useTokenizer';
31
+ export * from './hooks/general/useExecutorchModule';
32
+ // modules
33
+ export * from './modules/computer_vision/ClassificationModule';
34
+ export * from './modules/computer_vision/ObjectDetectionModule';
35
+ export * from './modules/computer_vision/StyleTransferModule';
36
+ export * from './modules/computer_vision/ImageSegmentationModule';
37
+ export * from './modules/computer_vision/OCRModule';
38
+ export * from './modules/computer_vision/VerticalOCRModule';
39
+ export * from './modules/general/ExecutorchModule';
40
+ export * from './modules/computer_vision/ImageEmbeddingsModule';
41
+ export * from './modules/natural_language_processing/LLMModule';
42
+ export * from './modules/natural_language_processing/SpeechToTextModule';
43
+ export * from './modules/natural_language_processing/TextEmbeddingsModule';
44
+ export * from './modules/natural_language_processing/TokenizerModule';
45
+ // utils
46
+ export * from './utils/ResourceFetcher';
47
+ export * from './utils/llm';
48
+ // types
49
+ export * from './types/objectDetection';
50
+ export * from './types/ocr';
51
+ export * from './types/imageSegmentation';
52
+ export * from './types/llm';
53
+ export { SpeechToTextLanguage };
54
+ // constants
55
+ export * from './constants/modelUrls';
56
+ export * from './constants/ocr/models';
57
+ export * from './constants/llmDefaults';
58
+ export { STREAMING_ACTION, MODES, AvailableModels, } from './constants/sttDefaults';
@@ -54,6 +54,9 @@ export class LLMModule {
54
54
  interrupt() {
55
55
  this.controller.interrupt();
56
56
  }
57
+ getGeneratedTokenCount() {
58
+ return this.controller.getGeneratedTokenCount();
59
+ }
57
60
  delete() {
58
61
  this.controller.delete();
59
62
  }
@@ -1 +1 @@
1
- {"version":3,"names":["LLMController","LLMModule","constructor","tokenCallback","responseCallback","messageHistoryCallback","controller","load","model","onDownloadProgressCallback","setTokenCallback","configure","chatConfig","toolsConfig","generationConfig","forward","input","response","generate","messages","tools","sendMessage","message","messageHistory","deleteMessage","index","interrupt","delete"],"sourceRoot":"../../../../src","sources":["modules/natural_language_processing/LLMModule.ts"],"mappings":";;AAAA,SAASA,aAAa,QAAQ,iCAAiC;AAU/D,OAAO,MAAMC,SAAS,CAAC;EAGrBC,WAAWA,CAAC;IACVC,aAAa;IACbC,gBAAgB;IAChBC;EAKF,CAAC,GAAG,CAAC,CAAC,EAAE;IACN,IAAI,CAACC,UAAU,GAAG,IAAIN,aAAa,CAAC;MAClCG,aAAa;MACbC,gBAAgB;MAChBC;IACF,CAAC,CAAC;EACJ;EAEA,MAAME,IAAIA,CACRC,KAIC,EACDC,0BAAsD,GAAGA,CAAA,KAAM,CAAC,CAAC,EACjE;IACA,MAAM,IAAI,CAACH,UAAU,CAACC,IAAI,CAAC;MACzB,GAAGC,KAAK;MACRC;IACF,CAAC,CAAC;EACJ;EAEAC,gBAAgBA,CAAC;IACfP;EAGF,CAAC,EAAE;IACD,IAAI,CAACG,UAAU,CAACI,gBAAgB,CAACP,aAAa,CAAC;EACjD;EAEAQ,SAASA,CAAC;IACRC,UAAU;IACVC,WAAW;IACXC;EAKF,CAAC,EAAE;IACD,IAAI,CAACR,UAAU,CAACK,SAAS,CAAC;MAAEC,UAAU;MAAEC,WAAW;MAAEC;IAAiB,CAAC,CAAC;EAC1E;EAEA,MAAMC,OAAOA,CAACC,KAAa,EAAmB;IAC5C,MAAM,IAAI,CAACV,UAAU,CAACS,OAAO,CAACC,KAAK,CAAC;IACpC,OAAO,IAAI,CAACV,UAAU,CAACW,QAAQ;EACjC;EAEA,MAAMC,QAAQA,CAACC,QAAmB,EAAEC,KAAiB,EAAmB;IACtE,MAAM,IAAI,CAACd,UAAU,CAACY,QAAQ,CAACC,QAAQ,EAAEC,KAAK,CAAC;IAC/C,OAAO,IAAI,CAACd,UAAU,CAACW,QAAQ;EACjC;EAEA,MAAMI,WAAWA,CAACC,OAAe,EAAsB;IACrD,MAAM,IAAI,CAAChB,UAAU,CAACe,WAAW,CAACC,OAAO,CAAC;IAC1C,OAAO,IAAI,CAAChB,UAAU,CAACiB,cAAc;EACvC;EAEAC,aAAaA,CAACC,KAAa,EAAa;IACtC,IAAI,CAACnB,UAAU,CAACkB,aAAa,CAACC,KAAK,CAAC;IACpC,OAAO,IAAI,CAACnB,UAAU,CAACiB,cAAc;EACvC;EAEAG,SAASA,CAAA,EAAG;IACV,IAAI,CAACpB,UAAU,CAACoB,SAAS,CAAC,CAAC;EAC7B;EAEAC,MAAMA,CAAA,EAAG;IACP,IAAI,CAACrB,UAAU,CAACqB,MAAM,CAAC,CAAC;EAC1B;AACF","ignoreList":[]}
1
+ {"version":3,"names":["LLMController","LLMModule","constructor","tokenCallback","responseCallback","messageHistoryCallback","controller","load","model","onDownloadProgressCallback","setTokenCallback","configure","chatConfig","toolsConfig","generationConfig","forward","input","response","generate","messages","tools","sendMessage","message","messageHistory","deleteMessage","index","interrupt","getGeneratedTokenCount","delete"],"sourceRoot":"../../../../src","sources":["modules/natural_language_processing/LLMModule.ts"],"mappings":";;AAAA,SAASA,aAAa,QAAQ,iCAAiC;AAU/D,OAAO,MAAMC,SAAS,CAAC;EAGrBC,WAAWA,CAAC;IACVC,aAAa;IACbC,gBAAgB;IAChBC;EAKF,CAAC,GAAG,CAAC,CAAC,EAAE;IACN,IAAI,CAACC,UAAU,GAAG,IAAIN,aAAa,CAAC;MAClCG,aAAa;MACbC,gBAAgB;MAChBC;IACF,CAAC,CAAC;EACJ;EAEA,MAAME,IAAIA,CACRC,KAIC,EACDC,0BAAsD,GAAGA,CAAA,KAAM,CAAC,CAAC,EACjE;IACA,MAAM,IAAI,CAACH,UAAU,CAACC,IAAI,CAAC;MACzB,GAAGC,KAAK;MACRC;IACF,CAAC,CAAC;EACJ;EAEAC,gBAAgBA,CAAC;IACfP;EAGF,CAAC,EAAE;IACD,IAAI,CAACG,UAAU,CAACI,gBAAgB,CAACP,aAAa,CAAC;EACjD;EAEAQ,SAASA,CAAC;IACRC,UAAU;IACVC,WAAW;IACXC;EAKF,CAAC,EAAE;IACD,IAAI,CAACR,UAAU,CAACK,SAAS,CAAC;MAAEC,UAAU;MAAEC,WAAW;MAAEC;IAAiB,CAAC,CAAC;EAC1E;EAEA,MAAMC,OAAOA,CAACC,KAAa,EAAmB;IAC5C,MAAM,IAAI,CAACV,UAAU,CAACS,OAAO,CAACC,KAAK,CAAC;IACpC,OAAO,IAAI,CAACV,UAAU,CAACW,QAAQ;EACjC;EAEA,MAAMC,QAAQA,CAACC,QAAmB,EAAEC,KAAiB,EAAmB;IACtE,MAAM,IAAI,CAACd,UAAU,CAACY,QAAQ,CAACC,QAAQ,EAAEC,KAAK,CAAC;IAC/C,OAAO,IAAI,CAACd,UAAU,CAACW,QAAQ;EACjC;EAEA,MAAMI,WAAWA,CAACC,OAAe,EAAsB;IACrD,MAAM,IAAI,CAAChB,UAAU,CAACe,WAAW,CAACC,OAAO,CAAC;IAC1C,OAAO,IAAI,CAAChB,UAAU,CAACiB,cAAc;EACvC;EAEAC,aAAaA,CAACC,KAAa,EAAa;IACtC,IAAI,CAACnB,UAAU,CAACkB,aAAa,CAACC,KAAK,CAAC;IACpC,OAAO,IAAI,CAACnB,UAAU,CAACiB,cAAc;EACvC;EAEAG,SAASA,CAAA,EAAG;IACV,IAAI,CAACpB,UAAU,CAACoB,SAAS,CAAC,CAAC;EAC7B;EAEAC,sBAAsBA,CAAA,EAAG;IACvB,OAAO,IAAI,CAACrB,UAAU,CAACqB,sBAAsB,CAAC,CAAC;EACjD;EAEAC,MAAMA,CAAA,EAAG;IACP,IAAI,CAACtB,UAAU,CAACsB,MAAM,CAAC,CAAC;EAC1B;AACF","ignoreList":[]}
@@ -0,0 +1,25 @@
1
+ import { ResourceFetcher } from '../utils/ResourceFetcher';
2
+ import { getError } from '../Error';
3
+ export class BaseModule {
4
+ static nativeModule;
5
+ static onDownloadProgressCallback = () => { };
6
+ static async load(sources, ...loadArgs // this can be used in derived classes to pass extra args to load method
7
+ ) {
8
+ try {
9
+ const paths = await ResourceFetcher.fetch(this.onDownloadProgressCallback, ...sources);
10
+ if (paths === null || paths.length < sources.length) {
11
+ throw new Error('Download interrupted.');
12
+ }
13
+ await this.nativeModule.loadModule(...paths, ...loadArgs);
14
+ }
15
+ catch (error) {
16
+ throw new Error(getError(error));
17
+ }
18
+ }
19
+ static async forward(..._args) {
20
+ throw new Error('forward method is not implemented in the BaseModule class. Please implement it in the derived class.');
21
+ }
22
+ static onDownloadProgress(callback) {
23
+ this.onDownloadProgressCallback = callback;
24
+ }
25
+ }
@@ -0,0 +1,14 @@
1
+ export class BaseNonStaticModule {
2
+ nativeModule = null;
3
+ async forwardET(inputTensor) {
4
+ return await this.nativeModule.forward(inputTensor);
5
+ }
6
+ async getInputShape(methodName, index) {
7
+ return this.nativeModule.getInputShape(methodName, index);
8
+ }
9
+ delete() {
10
+ if (this.nativeModule !== null) {
11
+ this.nativeModule.unload();
12
+ }
13
+ }
14
+ }
@@ -0,0 +1,8 @@
1
+ import { ResourceSource } from '../../types/common';
2
+ import { BaseNonStaticModule } from '../BaseNonStaticModule';
3
+ export declare class ClassificationModule extends BaseNonStaticModule {
4
+ load(model: {
5
+ modelSource: ResourceSource;
6
+ }, onDownloadProgressCallback?: (progress: number) => void): Promise<void>;
7
+ forward(imageSource: string): Promise<any>;
8
+ }
@@ -0,0 +1,17 @@
1
+ import { ResourceFetcher } from '../../utils/ResourceFetcher';
2
+ import { ETError, getError } from '../../Error';
3
+ import { BaseNonStaticModule } from '../BaseNonStaticModule';
4
+ export class ClassificationModule extends BaseNonStaticModule {
5
+ async load(model, onDownloadProgressCallback = () => { }) {
6
+ const paths = await ResourceFetcher.fetch(onDownloadProgressCallback, model.modelSource);
7
+ if (paths === null || paths.length < 1) {
8
+ throw new Error('Download interrupted.');
9
+ }
10
+ this.nativeModule = global.loadClassification(paths[0] || '');
11
+ }
12
+ async forward(imageSource) {
13
+ if (this.nativeModule == null)
14
+ throw new Error(getError(ETError.ModuleNotLoaded));
15
+ return await this.nativeModule.generate(imageSource);
16
+ }
17
+ }
@@ -0,0 +1,8 @@
1
+ import { ResourceSource } from '../../types/common';
2
+ import { BaseNonStaticModule } from '../BaseNonStaticModule';
3
+ export declare class ImageEmbeddingsModule extends BaseNonStaticModule {
4
+ load(model: {
5
+ modelSource: ResourceSource;
6
+ }, onDownloadProgressCallback?: (progress: number) => void): Promise<void>;
7
+ forward(imageSource: string): Promise<Float32Array>;
8
+ }
@@ -0,0 +1,17 @@
1
+ import { ResourceFetcher } from '../../utils/ResourceFetcher';
2
+ import { ETError, getError } from '../../Error';
3
+ import { BaseNonStaticModule } from '../BaseNonStaticModule';
4
+ export class ImageEmbeddingsModule extends BaseNonStaticModule {
5
+ async load(model, onDownloadProgressCallback = () => { }) {
6
+ const paths = await ResourceFetcher.fetch(onDownloadProgressCallback, model.modelSource);
7
+ if (paths === null || paths.length < 1) {
8
+ throw new Error('Download interrupted.');
9
+ }
10
+ this.nativeModule = global.loadImageEmbeddings(paths[0] || '');
11
+ }
12
+ async forward(imageSource) {
13
+ if (this.nativeModule == null)
14
+ throw new Error(getError(ETError.ModuleNotLoaded));
15
+ return new Float32Array(await this.nativeModule.generate(imageSource));
16
+ }
17
+ }
@@ -0,0 +1,11 @@
1
+ import { ResourceSource } from '../../types/common';
2
+ import { DeeplabLabel } from '../../types/imageSegmentation';
3
+ import { BaseNonStaticModule } from '../BaseNonStaticModule';
4
+ export declare class ImageSegmentationModule extends BaseNonStaticModule {
5
+ load(model: {
6
+ modelSource: ResourceSource;
7
+ }, onDownloadProgressCallback?: (progress: number) => void): Promise<void>;
8
+ forward(imageSource: string, classesOfInterest?: DeeplabLabel[], resize?: boolean): Promise<{
9
+ [key in DeeplabLabel]?: number[];
10
+ }>;
11
+ }
@@ -0,0 +1,27 @@
1
+ import { ResourceFetcher } from '../../utils/ResourceFetcher';
2
+ import { DeeplabLabel } from '../../types/imageSegmentation';
3
+ import { ETError, getError } from '../../Error';
4
+ import { BaseNonStaticModule } from '../BaseNonStaticModule';
5
+ export class ImageSegmentationModule extends BaseNonStaticModule {
6
+ async load(model, onDownloadProgressCallback = () => { }) {
7
+ const paths = await ResourceFetcher.fetch(onDownloadProgressCallback, model.modelSource);
8
+ if (paths === null || paths.length < 1) {
9
+ throw new Error('Download interrupted.');
10
+ }
11
+ this.nativeModule = global.loadImageSegmentation(paths[0] || '');
12
+ }
13
+ async forward(imageSource, classesOfInterest, resize) {
14
+ if (this.nativeModule == null) {
15
+ throw new Error(getError(ETError.ModuleNotLoaded));
16
+ }
17
+ const stringDict = await this.nativeModule.generate(imageSource, (classesOfInterest || []).map((label) => DeeplabLabel[label]), resize || false);
18
+ let enumDict = {};
19
+ for (const key in stringDict) {
20
+ if (key in DeeplabLabel) {
21
+ const enumKey = DeeplabLabel[key];
22
+ enumDict[enumKey] = stringDict[key];
23
+ }
24
+ }
25
+ return enumDict;
26
+ }
27
+ }
@@ -0,0 +1,14 @@
1
+ import { OCRController } from '../../controllers/OCRController';
2
+ import { ResourceSource } from '../../types/common';
3
+ import { OCRLanguage } from '../../types/ocr';
4
+ export declare class OCRModule {
5
+ static module: OCRController;
6
+ static load(model: {
7
+ detectorSource: ResourceSource;
8
+ recognizerLarge: ResourceSource;
9
+ recognizerMedium: ResourceSource;
10
+ recognizerSmall: ResourceSource;
11
+ language: OCRLanguage;
12
+ }, onDownloadProgressCallback?: (progress: number) => void): Promise<void>;
13
+ static forward(input: string): Promise<import("../../types/ocr").OCRDetection[]>;
14
+ }
@@ -0,0 +1,17 @@
1
+ import { OCRController } from '../../controllers/OCRController';
2
+ export class OCRModule {
3
+ static module;
4
+ static async load(model, onDownloadProgressCallback = () => { }) {
5
+ this.module = new OCRController({
6
+ modelDownloadProgressCallback: onDownloadProgressCallback,
7
+ });
8
+ await this.module.loadModel(model.detectorSource, {
9
+ recognizerLarge: model.recognizerLarge,
10
+ recognizerMedium: model.recognizerMedium,
11
+ recognizerSmall: model.recognizerSmall,
12
+ }, model.language);
13
+ }
14
+ static async forward(input) {
15
+ return await this.module.forward(input);
16
+ }
17
+ }
@@ -0,0 +1,9 @@
1
+ import { ResourceSource } from '../../types/common';
2
+ import { Detection } from '../../types/objectDetection';
3
+ import { BaseNonStaticModule } from '../BaseNonStaticModule';
4
+ export declare class ObjectDetectionModule extends BaseNonStaticModule {
5
+ load(model: {
6
+ modelSource: ResourceSource;
7
+ }, onDownloadProgressCallback?: (progress: number) => void): Promise<void>;
8
+ forward(imageSource: string, detectionThreshold?: number): Promise<Detection[]>;
9
+ }
@@ -0,0 +1,17 @@
1
+ import { ResourceFetcher } from '../../utils/ResourceFetcher';
2
+ import { ETError, getError } from '../../Error';
3
+ import { BaseNonStaticModule } from '../BaseNonStaticModule';
4
+ export class ObjectDetectionModule extends BaseNonStaticModule {
5
+ async load(model, onDownloadProgressCallback = () => { }) {
6
+ const paths = await ResourceFetcher.fetch(onDownloadProgressCallback, model.modelSource);
7
+ if (paths === null || paths.length < 1) {
8
+ throw new Error('Download interrupted.');
9
+ }
10
+ this.nativeModule = global.loadObjectDetection(paths[0] || '');
11
+ }
12
+ async forward(imageSource, detectionThreshold = 0.7) {
13
+ if (this.nativeModule == null)
14
+ throw new Error(getError(ETError.ModuleNotLoaded));
15
+ return await this.nativeModule.generate(imageSource, detectionThreshold);
16
+ }
17
+ }
@@ -0,0 +1,8 @@
1
+ import { ResourceSource } from '../../types/common';
2
+ import { BaseNonStaticModule } from '../BaseNonStaticModule';
3
+ export declare class StyleTransferModule extends BaseNonStaticModule {
4
+ load(model: {
5
+ modelSource: ResourceSource;
6
+ }, onDownloadProgressCallback?: (progress: number) => void): Promise<void>;
7
+ forward(imageSource: string): Promise<string>;
8
+ }
@@ -0,0 +1,17 @@
1
+ import { ResourceFetcher } from '../../utils/ResourceFetcher';
2
+ import { ETError, getError } from '../../Error';
3
+ import { BaseNonStaticModule } from '../BaseNonStaticModule';
4
+ export class StyleTransferModule extends BaseNonStaticModule {
5
+ async load(model, onDownloadProgressCallback = () => { }) {
6
+ const paths = await ResourceFetcher.fetch(onDownloadProgressCallback, model.modelSource);
7
+ if (paths === null || paths.length < 1) {
8
+ throw new Error('Download interrupted.');
9
+ }
10
+ this.nativeModule = global.loadStyleTransfer(paths[0] || '');
11
+ }
12
+ async forward(imageSource) {
13
+ if (this.nativeModule == null)
14
+ throw new Error(getError(ETError.ModuleNotLoaded));
15
+ return await this.nativeModule.generate(imageSource);
16
+ }
17
+ }
@@ -0,0 +1,14 @@
1
+ import { VerticalOCRController } from '../../controllers/VerticalOCRController';
2
+ import { ResourceSource } from '../../types/common';
3
+ import { OCRLanguage } from '../../types/ocr';
4
+ export declare class VerticalOCRModule {
5
+ static module: VerticalOCRController;
6
+ static load(model: {
7
+ detectorLarge: ResourceSource;
8
+ detectorNarrow: ResourceSource;
9
+ recognizerLarge: ResourceSource;
10
+ recognizerSmall: ResourceSource;
11
+ language: OCRLanguage;
12
+ }, independentCharacters: boolean, onDownloadProgressCallback?: (progress: number) => void): Promise<void>;
13
+ static forward(input: string): Promise<import("../../types/ocr").OCRDetection[]>;
14
+ }
@@ -0,0 +1,19 @@
1
+ import { VerticalOCRController } from '../../controllers/VerticalOCRController';
2
+ export class VerticalOCRModule {
3
+ static module;
4
+ static async load(model, independentCharacters, onDownloadProgressCallback = () => { }) {
5
+ this.module = new VerticalOCRController({
6
+ modelDownloadProgressCallback: onDownloadProgressCallback,
7
+ });
8
+ await this.module.loadModel({
9
+ detectorLarge: model.detectorLarge,
10
+ detectorNarrow: model.detectorNarrow,
11
+ }, {
12
+ recognizerLarge: model.recognizerLarge,
13
+ recognizerSmall: model.recognizerSmall,
14
+ }, model.language, independentCharacters);
15
+ }
16
+ static async forward(input) {
17
+ return await this.module.forward(input);
18
+ }
19
+ }
@@ -0,0 +1,7 @@
1
+ import { TensorPtr } from '../../types/common';
2
+ import { BaseNonStaticModule } from '../BaseNonStaticModule';
3
+ import { ResourceSource } from '../../types/common';
4
+ export declare class ExecutorchModule extends BaseNonStaticModule {
5
+ load(modelSource: ResourceSource, onDownloadProgressCallback?: (progress: number) => void): Promise<void>;
6
+ forward(inputTensor: TensorPtr[]): Promise<TensorPtr[]>;
7
+ }
@@ -0,0 +1,14 @@
1
+ import { BaseNonStaticModule } from '../BaseNonStaticModule';
2
+ import { ResourceFetcher } from '../../utils/ResourceFetcher';
3
+ export class ExecutorchModule extends BaseNonStaticModule {
4
+ async load(modelSource, onDownloadProgressCallback = () => { }) {
5
+ const paths = await ResourceFetcher.fetch(onDownloadProgressCallback, modelSource);
6
+ if (paths === null || paths.length < 1) {
7
+ throw new Error('Download interrupted.');
8
+ }
9
+ this.nativeModule = global.loadExecutorchModule(paths[0] || '');
10
+ }
11
+ async forward(inputTensor) {
12
+ return await this.forwardET(inputTensor);
13
+ }
14
+ }
@@ -0,0 +1,28 @@
1
+ import { ResourceSource } from '../../types/common';
2
+ import { ChatConfig, LLMTool, Message, ToolsConfig } from '../../types/llm';
3
+ export declare class LLMModule {
4
+ private controller;
5
+ constructor({ tokenCallback, responseCallback, messageHistoryCallback, }?: {
6
+ tokenCallback?: (token: string) => void;
7
+ responseCallback?: (response: string) => void;
8
+ messageHistoryCallback?: (messageHistory: Message[]) => void;
9
+ });
10
+ load(model: {
11
+ modelSource: ResourceSource;
12
+ tokenizerSource: ResourceSource;
13
+ tokenizerConfigSource: ResourceSource;
14
+ }, onDownloadProgressCallback?: (progress: number) => void): Promise<void>;
15
+ setTokenCallback({ tokenCallback, }: {
16
+ tokenCallback: (token: string) => void;
17
+ }): void;
18
+ configure({ chatConfig, toolsConfig, }: {
19
+ chatConfig?: Partial<ChatConfig>;
20
+ toolsConfig?: ToolsConfig;
21
+ }): void;
22
+ forward(input: string): Promise<string>;
23
+ generate(messages: Message[], tools?: LLMTool[]): Promise<string>;
24
+ sendMessage(message: string): Promise<Message[]>;
25
+ deleteMessage(index: number): Message[];
26
+ interrupt(): void;
27
+ delete(): void;
28
+ }
@@ -0,0 +1,45 @@
1
+ import { LLMController } from '../../controllers/LLMController';
2
+ export class LLMModule {
3
+ controller;
4
+ constructor({ tokenCallback, responseCallback, messageHistoryCallback, } = {}) {
5
+ this.controller = new LLMController({
6
+ tokenCallback,
7
+ responseCallback,
8
+ messageHistoryCallback,
9
+ });
10
+ }
11
+ async load(model, onDownloadProgressCallback = () => { }) {
12
+ await this.controller.load({
13
+ ...model,
14
+ onDownloadProgressCallback,
15
+ });
16
+ }
17
+ setTokenCallback({ tokenCallback, }) {
18
+ this.controller.setTokenCallback(tokenCallback);
19
+ }
20
+ configure({ chatConfig, toolsConfig, }) {
21
+ this.controller.configure({ chatConfig, toolsConfig });
22
+ }
23
+ async forward(input) {
24
+ await this.controller.forward(input);
25
+ return this.controller.response;
26
+ }
27
+ async generate(messages, tools) {
28
+ await this.controller.generate(messages, tools);
29
+ return this.controller.response;
30
+ }
31
+ async sendMessage(message) {
32
+ await this.controller.sendMessage(message);
33
+ return this.controller.messageHistory;
34
+ }
35
+ deleteMessage(index) {
36
+ this.controller.deleteMessage(index);
37
+ return this.controller.messageHistory;
38
+ }
39
+ interrupt() {
40
+ this.controller.interrupt();
41
+ }
42
+ delete() {
43
+ this.controller.delete();
44
+ }
45
+ }
@@ -0,0 +1,24 @@
1
+ import { ResourceSource } from '../../types/common';
2
+ import { SpeechToTextController } from '../../controllers/SpeechToTextController';
3
+ import { AvailableModels, SpeechToTextLanguage } from '../../types/stt';
4
+ import { STREAMING_ACTION } from '../../constants/sttDefaults';
5
+ export declare class SpeechToTextModule {
6
+ private module;
7
+ constructor({ transcribeCallback, overlapSeconds, windowSize, streamingConfig, }?: {
8
+ transcribeCallback?: (sequence: string) => void;
9
+ overlapSeconds?: ConstructorParameters<typeof SpeechToTextController>['0']['overlapSeconds'];
10
+ windowSize?: ConstructorParameters<typeof SpeechToTextController>['0']['windowSize'];
11
+ streamingConfig?: ConstructorParameters<typeof SpeechToTextController>['0']['streamingConfig'];
12
+ });
13
+ load(model: {
14
+ modelName: AvailableModels;
15
+ encoderSource?: ResourceSource;
16
+ decoderSource?: ResourceSource;
17
+ tokenizerSource?: ResourceSource;
18
+ }, onDownloadProgressCallback?: (progress: number) => void): Promise<void>;
19
+ configureStreaming(overlapSeconds: Parameters<SpeechToTextController['configureStreaming']>[0], windowSize: Parameters<SpeechToTextController['configureStreaming']>[1], streamingConfig: Parameters<SpeechToTextController['configureStreaming']>[2]): void;
20
+ encode(waveform: Float32Array): Promise<null>;
21
+ decode(seq: number[]): Promise<number>;
22
+ transcribe(waveform: number[], audioLanguage?: SpeechToTextLanguage): ReturnType<SpeechToTextController['transcribe']>;
23
+ streamingTranscribe(streamAction: STREAMING_ACTION, waveform?: number[], audioLanguage?: SpeechToTextLanguage): ReturnType<SpeechToTextController['streamingTranscribe']>;
24
+ }