react-native-executorch 0.5.1-rc.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +132 -0
- package/common/rnexecutorch/models/speech_to_text/SpeechToText.cpp +4 -10
- package/common/rnexecutorch/models/speech_to_text/SpeechToText.h +1 -1
- package/common/rnexecutorch/models/speech_to_text/SpeechToTextStrategy.h +3 -2
- package/common/rnexecutorch/models/speech_to_text/WhisperStrategy.cpp +16 -4
- package/common/rnexecutorch/models/speech_to_text/WhisperStrategy.h +2 -2
- package/lib/Error.d.ts +30 -0
- package/lib/Error.js +50 -0
- package/lib/constants/directories.d.ts +1 -0
- package/lib/constants/directories.js +2 -0
- package/lib/constants/llmDefaults.d.ts +6 -0
- package/lib/constants/llmDefaults.js +16 -0
- package/lib/constants/modelUrls.d.ts +217 -83
- package/lib/constants/modelUrls.js +304 -98
- package/lib/constants/ocr/models.d.ts +882 -0
- package/lib/constants/ocr/models.js +182 -0
- package/lib/constants/ocr/symbols.d.ts +75 -0
- package/lib/constants/ocr/symbols.js +139 -0
- package/lib/{typescript/constants → constants}/sttDefaults.d.ts +0 -1
- package/lib/constants/sttDefaults.js +12 -10
- package/lib/controllers/LLMController.d.ts +47 -0
- package/lib/controllers/LLMController.js +14 -11
- package/lib/controllers/OCRController.d.ts +23 -0
- package/lib/controllers/OCRController.js +12 -5
- package/lib/controllers/SpeechToTextController.d.ts +8 -4
- package/lib/controllers/SpeechToTextController.js +15 -9
- package/lib/controllers/VerticalOCRController.d.ts +25 -0
- package/lib/controllers/VerticalOCRController.js +75 -0
- package/lib/hooks/computer_vision/useClassification.d.ts +15 -0
- package/lib/hooks/computer_vision/useClassification.js +7 -0
- package/lib/hooks/computer_vision/useImageEmbeddings.d.ts +15 -0
- package/lib/hooks/computer_vision/useImageEmbeddings.js +7 -0
- package/lib/hooks/computer_vision/useImageSegmentation.d.ts +38 -0
- package/lib/hooks/computer_vision/useImageSegmentation.js +7 -0
- package/lib/hooks/computer_vision/useOCR.d.ts +20 -0
- package/lib/hooks/computer_vision/useOCR.js +42 -0
- package/lib/hooks/computer_vision/useObjectDetection.d.ts +15 -0
- package/lib/hooks/computer_vision/useObjectDetection.js +7 -0
- package/lib/hooks/computer_vision/useStyleTransfer.d.ts +15 -0
- package/lib/hooks/computer_vision/useStyleTransfer.js +7 -0
- package/lib/hooks/computer_vision/useVerticalOCR.d.ts +21 -0
- package/lib/hooks/computer_vision/useVerticalOCR.js +45 -0
- package/lib/hooks/general/useExecutorchModule.d.ts +13 -0
- package/lib/hooks/general/useExecutorchModule.js +7 -0
- package/lib/hooks/natural_language_processing/useLLM.d.ts +10 -0
- package/lib/hooks/natural_language_processing/useLLM.js +78 -0
- package/lib/hooks/natural_language_processing/useSpeechToText.d.ts +27 -0
- package/lib/hooks/natural_language_processing/useSpeechToText.js +19 -14
- package/lib/hooks/natural_language_processing/useTextEmbeddings.d.ts +16 -0
- package/lib/hooks/natural_language_processing/useTextEmbeddings.js +7 -0
- package/lib/hooks/natural_language_processing/useTokenizer.d.ts +17 -0
- package/lib/hooks/natural_language_processing/useTokenizer.js +52 -0
- package/lib/hooks/useModule.d.ts +17 -0
- package/lib/hooks/useModule.js +45 -0
- package/lib/hooks/useNonStaticModule.d.ts +20 -0
- package/lib/hooks/useNonStaticModule.js +49 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +3 -2
- package/lib/module/constants/modelUrls.js +61 -36
- package/lib/module/constants/modelUrls.js.map +1 -1
- package/lib/module/constants/ocr/models.js +1 -1
- package/lib/module/hooks/natural_language_processing/useSpeechToText.js +71 -34
- package/lib/module/hooks/natural_language_processing/useSpeechToText.js.map +1 -1
- package/lib/module/index.js +2 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/modules/natural_language_processing/SpeechToTextModule.js +72 -31
- package/lib/module/modules/natural_language_processing/SpeechToTextModule.js.map +1 -1
- package/lib/module/types/stt.js +1 -85
- package/lib/module/types/stt.js.map +1 -1
- package/lib/module/utils/ResourceFetcher.js +6 -8
- package/lib/module/utils/ResourceFetcher.js.map +1 -1
- package/lib/module/utils/ResourceFetcherUtils.js +20 -20
- package/lib/module/utils/ResourceFetcherUtils.js.map +1 -1
- package/lib/module/utils/SpeechToTextModule/ASR.js +191 -0
- package/lib/module/utils/SpeechToTextModule/ASR.js.map +1 -0
- package/lib/module/utils/SpeechToTextModule/OnlineProcessor.js +73 -0
- package/lib/module/utils/SpeechToTextModule/OnlineProcessor.js.map +1 -0
- package/lib/module/utils/SpeechToTextModule/hypothesisBuffer.js +56 -0
- package/lib/module/utils/SpeechToTextModule/hypothesisBuffer.js.map +1 -0
- package/lib/modules/BaseModule.d.ts +8 -0
- package/lib/modules/BaseModule.js +25 -0
- package/lib/modules/BaseNonStaticModule.d.ts +9 -0
- package/lib/modules/BaseNonStaticModule.js +14 -0
- package/lib/modules/computer_vision/ClassificationModule.d.ts +8 -0
- package/lib/modules/computer_vision/ClassificationModule.js +17 -0
- package/lib/modules/computer_vision/ImageEmbeddingsModule.d.ts +8 -0
- package/lib/modules/computer_vision/ImageEmbeddingsModule.js +17 -0
- package/lib/modules/computer_vision/ImageSegmentationModule.d.ts +11 -0
- package/lib/modules/computer_vision/ImageSegmentationModule.js +27 -0
- package/lib/modules/computer_vision/OCRModule.d.ts +15 -0
- package/lib/modules/computer_vision/OCRModule.js +20 -0
- package/lib/modules/computer_vision/ObjectDetectionModule.d.ts +9 -0
- package/lib/modules/computer_vision/ObjectDetectionModule.js +17 -0
- package/lib/modules/computer_vision/StyleTransferModule.d.ts +8 -0
- package/lib/modules/computer_vision/StyleTransferModule.js +17 -0
- package/lib/modules/computer_vision/VerticalOCRModule.d.ts +15 -0
- package/lib/modules/computer_vision/VerticalOCRModule.js +22 -0
- package/lib/modules/general/ExecutorchModule.d.ts +7 -0
- package/lib/modules/general/ExecutorchModule.js +14 -0
- package/lib/modules/natural_language_processing/LLMModule.d.ts +28 -0
- package/lib/modules/natural_language_processing/LLMModule.js +45 -0
- package/lib/modules/natural_language_processing/SpeechToTextModule.d.ts +18 -8
- package/lib/modules/natural_language_processing/SpeechToTextModule.js +21 -15
- package/lib/modules/natural_language_processing/TextEmbeddingsModule.d.ts +9 -0
- package/lib/modules/natural_language_processing/TextEmbeddingsModule.js +21 -0
- package/lib/modules/natural_language_processing/TokenizerModule.d.ts +12 -0
- package/lib/modules/natural_language_processing/TokenizerModule.js +5 -4
- package/lib/native/NativeETInstaller.d.ts +6 -0
- package/lib/native/NativeETInstaller.js +2 -0
- package/lib/native/NativeOCR.d.ts +8 -0
- package/lib/native/NativeOCR.js +2 -0
- package/lib/native/NativeVerticalOCR.d.ts +8 -0
- package/lib/native/NativeVerticalOCR.js +2 -0
- package/lib/types/common.d.ts +31 -0
- package/lib/types/common.js +25 -0
- package/lib/types/imageSegmentation.d.ts +24 -0
- package/lib/types/imageSegmentation.js +26 -0
- package/lib/types/llm.d.ts +46 -0
- package/lib/types/llm.js +9 -0
- package/lib/types/objectDetection.d.ts +104 -0
- package/lib/types/objectDetection.js +94 -0
- package/lib/types/ocr.d.ts +11 -0
- package/lib/types/ocr.js +1 -0
- package/lib/types/stt.d.ts +94 -0
- package/lib/types/stt.js +85 -0
- package/lib/typescript/constants/modelUrls.d.ts +24 -7
- package/lib/typescript/constants/modelUrls.d.ts.map +1 -1
- package/lib/typescript/constants/ocr/models.d.ts +126 -126
- package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts +15 -24
- package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +2 -3
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts +19 -22
- package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts.map +1 -1
- package/lib/typescript/types/stt.d.ts +17 -91
- package/lib/typescript/types/stt.d.ts.map +1 -1
- package/lib/typescript/utils/ResourceFetcher.d.ts.map +1 -1
- package/lib/typescript/utils/ResourceFetcherUtils.d.ts.map +1 -1
- package/lib/typescript/utils/SpeechToTextModule/ASR.d.ts +27 -0
- package/lib/typescript/utils/SpeechToTextModule/ASR.d.ts.map +1 -0
- package/lib/typescript/utils/SpeechToTextModule/OnlineProcessor.d.ts +23 -0
- package/lib/typescript/utils/SpeechToTextModule/OnlineProcessor.d.ts.map +1 -0
- package/lib/typescript/utils/SpeechToTextModule/hypothesisBuffer.d.ts +13 -0
- package/lib/typescript/utils/SpeechToTextModule/hypothesisBuffer.d.ts.map +1 -0
- package/lib/utils/ResourceFetcher.d.ts +24 -0
- package/lib/utils/ResourceFetcher.js +305 -0
- package/lib/utils/ResourceFetcherUtils.d.ts +54 -0
- package/lib/utils/ResourceFetcherUtils.js +9 -0
- package/lib/utils/llm.d.ts +6 -0
- package/lib/utils/llm.js +1 -0
- package/lib/utils/stt.d.ts +1 -0
- package/lib/utils/stt.js +21 -0
- package/package.json +5 -3
- package/src/constants/modelUrls.ts +70 -37
- package/src/constants/ocr/models.ts +1 -1
- package/src/hooks/natural_language_processing/useSpeechToText.ts +87 -92
- package/src/index.ts +6 -8
- package/src/modules/natural_language_processing/SpeechToTextModule.ts +81 -69
- package/src/types/stt.ts +97 -92
- package/src/utils/ResourceFetcher.ts +9 -7
- package/src/utils/ResourceFetcherUtils.ts +15 -17
- package/src/utils/SpeechToTextModule/ASR.ts +303 -0
- package/src/utils/SpeechToTextModule/OnlineProcessor.ts +87 -0
- package/src/utils/SpeechToTextModule/hypothesisBuffer.ts +79 -0
- package/common/rnexecutorch/models/speech_to_text/MoonshineStrategy.cpp +0 -31
- package/common/rnexecutorch/models/speech_to_text/MoonshineStrategy.h +0 -21
- package/lib/module/constants/sttDefaults.js +0 -74
- package/lib/module/constants/sttDefaults.js.map +0 -1
- package/lib/module/controllers/SpeechToTextController.js +0 -320
- package/lib/module/controllers/SpeechToTextController.js.map +0 -1
- package/lib/typescript/constants/sttDefaults.d.ts.map +0 -1
- package/lib/typescript/controllers/SpeechToTextController.d.ts +0 -57
- package/lib/typescript/controllers/SpeechToTextController.d.ts.map +0 -1
- package/src/constants/sttDefaults.ts +0 -82
- package/src/controllers/SpeechToTextController.ts +0 -471
- package/third-party/ios/ExecutorchLib/ExecutorchLib.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/third-party/ios/ExecutorchLib/ExecutorchLib.xcodeproj/project.xcworkspace/xcuserdata/norbertklockiewicz.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/third-party/ios/ExecutorchLib/ExecutorchLib.xcodeproj/xcuserdata/norbertklockiewicz.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ResourceSource } from '../types/common';
|
|
2
|
+
import { OCRLanguage } from '../types/ocr';
|
|
3
|
+
export declare class OCRController {
|
|
4
|
+
private nativeModule;
|
|
5
|
+
isReady: boolean;
|
|
6
|
+
isGenerating: boolean;
|
|
7
|
+
error: string | null;
|
|
8
|
+
private isReadyCallback;
|
|
9
|
+
private isGeneratingCallback;
|
|
10
|
+
private errorCallback;
|
|
11
|
+
constructor({ isReadyCallback, isGeneratingCallback, errorCallback, }?: {
|
|
12
|
+
isReadyCallback?: ((_isReady: boolean) => void) | undefined;
|
|
13
|
+
isGeneratingCallback?: ((_isGenerating: boolean) => void) | undefined;
|
|
14
|
+
errorCallback?: ((_error: string) => void) | undefined;
|
|
15
|
+
});
|
|
16
|
+
load: (detectorSource: ResourceSource, recognizerSources: {
|
|
17
|
+
recognizerLarge: ResourceSource;
|
|
18
|
+
recognizerMedium: ResourceSource;
|
|
19
|
+
recognizerSmall: ResourceSource;
|
|
20
|
+
}, language: OCRLanguage, onDownloadProgressCallback?: (downloadProgress: number) => void) => Promise<void>;
|
|
21
|
+
forward: (input: string) => Promise<any>;
|
|
22
|
+
delete(): void;
|
|
23
|
+
}
|
|
@@ -6,17 +6,15 @@ export class OCRController {
|
|
|
6
6
|
isReady = false;
|
|
7
7
|
isGenerating = false;
|
|
8
8
|
error = null;
|
|
9
|
-
modelDownloadProgressCallback;
|
|
10
9
|
isReadyCallback;
|
|
11
10
|
isGeneratingCallback;
|
|
12
11
|
errorCallback;
|
|
13
|
-
constructor({
|
|
14
|
-
this.modelDownloadProgressCallback = modelDownloadProgressCallback;
|
|
12
|
+
constructor({ isReadyCallback = (_isReady) => { }, isGeneratingCallback = (_isGenerating) => { }, errorCallback = (_error) => { }, } = {}) {
|
|
15
13
|
this.isReadyCallback = isReadyCallback;
|
|
16
14
|
this.isGeneratingCallback = isGeneratingCallback;
|
|
17
15
|
this.errorCallback = errorCallback;
|
|
18
16
|
}
|
|
19
|
-
load = async (detectorSource, recognizerSources, language) => {
|
|
17
|
+
load = async (detectorSource, recognizerSources, language, onDownloadProgressCallback) => {
|
|
20
18
|
try {
|
|
21
19
|
if (!detectorSource || Object.keys(recognizerSources).length !== 3)
|
|
22
20
|
return;
|
|
@@ -25,7 +23,7 @@ export class OCRController {
|
|
|
25
23
|
}
|
|
26
24
|
this.isReady = false;
|
|
27
25
|
this.isReadyCallback(false);
|
|
28
|
-
const paths = await ResourceFetcher.fetch(
|
|
26
|
+
const paths = await ResourceFetcher.fetch(onDownloadProgressCallback, detectorSource, recognizerSources.recognizerLarge, recognizerSources.recognizerMedium, recognizerSources.recognizerSmall);
|
|
29
27
|
if (paths === null || paths?.length < 4) {
|
|
30
28
|
throw new Error('Download interrupted!');
|
|
31
29
|
}
|
|
@@ -62,4 +60,13 @@ export class OCRController {
|
|
|
62
60
|
this.isGeneratingCallback(this.isGenerating);
|
|
63
61
|
}
|
|
64
62
|
};
|
|
63
|
+
delete() {
|
|
64
|
+
if (this.isGenerating) {
|
|
65
|
+
throw new Error(getError(ETError.ModelGenerating) +
|
|
66
|
+
'You cannot delete the model. You must wait until the generating is finished.');
|
|
67
|
+
}
|
|
68
|
+
this.nativeModule.unload();
|
|
69
|
+
this.isReadyCallback(false);
|
|
70
|
+
this.isGeneratingCallback(false);
|
|
71
|
+
}
|
|
65
72
|
}
|
|
@@ -17,14 +17,12 @@ export declare class SpeechToTextController {
|
|
|
17
17
|
private numOfChunks;
|
|
18
18
|
private streaming;
|
|
19
19
|
private decodedTranscribeCallback;
|
|
20
|
-
private modelDownloadProgressCallback;
|
|
21
20
|
private isReadyCallback;
|
|
22
21
|
private isGeneratingCallback;
|
|
23
22
|
private onErrorCallback;
|
|
24
23
|
private config;
|
|
25
|
-
constructor({ transcribeCallback,
|
|
24
|
+
constructor({ transcribeCallback, isReadyCallback, isGeneratingCallback, onErrorCallback, overlapSeconds, windowSize, streamingConfig, }: {
|
|
26
25
|
transcribeCallback: (sequence: string) => void;
|
|
27
|
-
modelDownloadProgressCallback?: (downloadProgress: number) => void;
|
|
28
26
|
isReadyCallback?: (isReady: boolean) => void;
|
|
29
27
|
isGeneratingCallback?: (isGenerating: boolean) => void;
|
|
30
28
|
onErrorCallback?: (error: Error | undefined) => void;
|
|
@@ -32,7 +30,13 @@ export declare class SpeechToTextController {
|
|
|
32
30
|
windowSize?: number;
|
|
33
31
|
streamingConfig?: keyof typeof MODES;
|
|
34
32
|
});
|
|
35
|
-
|
|
33
|
+
load({ modelName, encoderSource, decoderSource, tokenizerSource, onDownloadProgressCallback, }: {
|
|
34
|
+
modelName: AvailableModels;
|
|
35
|
+
encoderSource?: ResourceSource;
|
|
36
|
+
decoderSource?: ResourceSource;
|
|
37
|
+
tokenizerSource?: ResourceSource;
|
|
38
|
+
onDownloadProgressCallback?: (downloadProgress: number) => void;
|
|
39
|
+
}): Promise<void>;
|
|
36
40
|
configureStreaming(overlapSeconds?: number, windowSize?: number, streamingConfig?: keyof typeof MODES): void;
|
|
37
41
|
private chunkWaveform;
|
|
38
42
|
private resetState;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HAMMING_DIST_THRESHOLD, MODEL_CONFIGS, SECOND, MODES, NUM_TOKENS_TO_TRIM, STREAMING_ACTION, } from '../constants/sttDefaults';
|
|
2
|
+
import { AvailableModels } from '../types/stt';
|
|
2
3
|
import { TokenizerModule } from '../modules/natural_language_processing/TokenizerModule';
|
|
3
4
|
import { ResourceFetcher } from '../utils/ResourceFetcher';
|
|
4
5
|
import { longCommonInfPref } from '../utils/stt';
|
|
@@ -20,15 +21,13 @@ export class SpeechToTextController {
|
|
|
20
21
|
streaming = false;
|
|
21
22
|
// User callbacks
|
|
22
23
|
decodedTranscribeCallback;
|
|
23
|
-
modelDownloadProgressCallback;
|
|
24
24
|
isReadyCallback;
|
|
25
25
|
isGeneratingCallback;
|
|
26
26
|
onErrorCallback;
|
|
27
27
|
config;
|
|
28
|
-
constructor({ transcribeCallback,
|
|
28
|
+
constructor({ transcribeCallback, isReadyCallback, isGeneratingCallback, onErrorCallback, overlapSeconds, windowSize, streamingConfig, }) {
|
|
29
29
|
this.tokenizerModule = new TokenizerModule();
|
|
30
30
|
this.decodedTranscribeCallback = async (seq) => transcribeCallback(await this.tokenIdsToText(seq));
|
|
31
|
-
this.modelDownloadProgressCallback = modelDownloadProgressCallback;
|
|
32
31
|
this.isReadyCallback = (isReady) => {
|
|
33
32
|
this.isReady = isReady;
|
|
34
33
|
isReadyCallback?.(isReady);
|
|
@@ -48,17 +47,24 @@ export class SpeechToTextController {
|
|
|
48
47
|
};
|
|
49
48
|
this.configureStreaming(overlapSeconds, windowSize, streamingConfig || 'balanced');
|
|
50
49
|
}
|
|
51
|
-
async
|
|
50
|
+
async load({ modelName, encoderSource, decoderSource, tokenizerSource, onDownloadProgressCallback, }) {
|
|
52
51
|
this.onErrorCallback(undefined);
|
|
53
52
|
this.isReadyCallback(false);
|
|
54
53
|
this.config = MODEL_CONFIGS[modelName];
|
|
55
54
|
try {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
const tokenizerLoadPromise = this.tokenizerModule.load({
|
|
56
|
+
tokenizerSource: tokenizerSource || this.config.tokenizer.source,
|
|
57
|
+
});
|
|
58
|
+
const pathsPromise = ResourceFetcher.fetch(onDownloadProgressCallback, encoderSource || this.config.sources.encoder, decoderSource || this.config.sources.decoder);
|
|
59
|
+
const [_, encoderDecoderResults] = await Promise.all([
|
|
60
|
+
tokenizerLoadPromise,
|
|
61
|
+
pathsPromise,
|
|
62
|
+
]);
|
|
63
|
+
encoderSource = encoderDecoderResults?.[0];
|
|
64
|
+
decoderSource = encoderDecoderResults?.[1];
|
|
65
|
+
if (!encoderSource || !decoderSource) {
|
|
59
66
|
throw new Error('Download interrupted.');
|
|
60
67
|
}
|
|
61
|
-
[encoderSource, decoderSource] = paths;
|
|
62
68
|
}
|
|
63
69
|
catch (e) {
|
|
64
70
|
this.onErrorCallback(e);
|
|
@@ -69,7 +75,7 @@ export class SpeechToTextController {
|
|
|
69
75
|
// create a separate class for multilingual version of Whisper, since it is the same. We just need
|
|
70
76
|
// the distinction here, in TS, for start tokens and such. If we introduce
|
|
71
77
|
// more versions of Whisper, such as the small one, this should be refactored.
|
|
72
|
-
modelName =
|
|
78
|
+
modelName = AvailableModels.WHISPER;
|
|
73
79
|
}
|
|
74
80
|
try {
|
|
75
81
|
const nativeSpeechToText = await global.loadSpeechToText(encoderSource, decoderSource, modelName);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ResourceSource } from '../types/common';
|
|
2
|
+
import { OCRLanguage } from '../types/ocr';
|
|
3
|
+
export declare class VerticalOCRController {
|
|
4
|
+
private ocrNativeModule;
|
|
5
|
+
isReady: boolean;
|
|
6
|
+
isGenerating: boolean;
|
|
7
|
+
error: string | null;
|
|
8
|
+
private isReadyCallback;
|
|
9
|
+
private isGeneratingCallback;
|
|
10
|
+
private errorCallback;
|
|
11
|
+
constructor({ isReadyCallback, isGeneratingCallback, errorCallback, }?: {
|
|
12
|
+
isReadyCallback?: ((_isReady: boolean) => void) | undefined;
|
|
13
|
+
isGeneratingCallback?: ((_isGenerating: boolean) => void) | undefined;
|
|
14
|
+
errorCallback?: ((_error: string) => void) | undefined;
|
|
15
|
+
});
|
|
16
|
+
load: (detectorSources: {
|
|
17
|
+
detectorLarge: ResourceSource;
|
|
18
|
+
detectorNarrow: ResourceSource;
|
|
19
|
+
}, recognizerSources: {
|
|
20
|
+
recognizerLarge: ResourceSource;
|
|
21
|
+
recognizerSmall: ResourceSource;
|
|
22
|
+
}, language: OCRLanguage, independentCharacters: boolean, onDownloadProgressCallback: (downloadProgress: number) => void) => Promise<void>;
|
|
23
|
+
forward: (input: string) => Promise<any>;
|
|
24
|
+
delete(): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { symbols } from '../constants/ocr/symbols';
|
|
2
|
+
import { ETError, getError } from '../Error';
|
|
3
|
+
import { ResourceFetcher } from '../utils/ResourceFetcher';
|
|
4
|
+
export class VerticalOCRController {
|
|
5
|
+
ocrNativeModule;
|
|
6
|
+
isReady = false;
|
|
7
|
+
isGenerating = false;
|
|
8
|
+
error = null;
|
|
9
|
+
isReadyCallback;
|
|
10
|
+
isGeneratingCallback;
|
|
11
|
+
errorCallback;
|
|
12
|
+
constructor({ isReadyCallback = (_isReady) => { }, isGeneratingCallback = (_isGenerating) => { }, errorCallback = (_error) => { }, } = {}) {
|
|
13
|
+
this.isReadyCallback = isReadyCallback;
|
|
14
|
+
this.isGeneratingCallback = isGeneratingCallback;
|
|
15
|
+
this.errorCallback = errorCallback;
|
|
16
|
+
}
|
|
17
|
+
load = async (detectorSources, recognizerSources, language, independentCharacters, onDownloadProgressCallback) => {
|
|
18
|
+
try {
|
|
19
|
+
if (Object.keys(detectorSources).length !== 2 ||
|
|
20
|
+
Object.keys(recognizerSources).length !== 2)
|
|
21
|
+
return;
|
|
22
|
+
if (!symbols[language]) {
|
|
23
|
+
throw new Error(getError(ETError.LanguageNotSupported));
|
|
24
|
+
}
|
|
25
|
+
this.isReady = false;
|
|
26
|
+
this.isReadyCallback(this.isReady);
|
|
27
|
+
const paths = await ResourceFetcher.fetch(onDownloadProgressCallback, detectorSources.detectorLarge, detectorSources.detectorNarrow, independentCharacters
|
|
28
|
+
? recognizerSources.recognizerSmall
|
|
29
|
+
: recognizerSources.recognizerLarge);
|
|
30
|
+
if (paths === null || paths.length < 3) {
|
|
31
|
+
throw new Error('Download interrupted');
|
|
32
|
+
}
|
|
33
|
+
this.ocrNativeModule = global.loadVerticalOCR(paths[0], paths[1], paths[2], symbols[language], independentCharacters);
|
|
34
|
+
this.isReady = true;
|
|
35
|
+
this.isReadyCallback(this.isReady);
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
if (this.errorCallback) {
|
|
39
|
+
this.errorCallback(getError(e));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
throw new Error(getError(e));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
forward = async (input) => {
|
|
47
|
+
if (!this.isReady) {
|
|
48
|
+
throw new Error(getError(ETError.ModuleNotLoaded));
|
|
49
|
+
}
|
|
50
|
+
if (this.isGenerating) {
|
|
51
|
+
throw new Error(getError(ETError.ModelGenerating));
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
this.isGenerating = true;
|
|
55
|
+
this.isGeneratingCallback(this.isGenerating);
|
|
56
|
+
return await this.ocrNativeModule.generate(input);
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
throw new Error(getError(e));
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
this.isGenerating = false;
|
|
63
|
+
this.isGeneratingCallback(this.isGenerating);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
delete() {
|
|
67
|
+
if (this.isGenerating) {
|
|
68
|
+
throw new Error(getError(ETError.ModelGenerating) +
|
|
69
|
+
'You cannot delete the model. You must wait until the generating is finished.');
|
|
70
|
+
}
|
|
71
|
+
this.ocrNativeModule.unload();
|
|
72
|
+
this.isReadyCallback(false);
|
|
73
|
+
this.isGeneratingCallback(false);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ResourceSource } from '../../types/common';
|
|
2
|
+
interface Props {
|
|
3
|
+
model: {
|
|
4
|
+
modelSource: ResourceSource;
|
|
5
|
+
};
|
|
6
|
+
preventLoad?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const useClassification: ({ model, preventLoad }: Props) => {
|
|
9
|
+
error: string | null;
|
|
10
|
+
isReady: boolean;
|
|
11
|
+
isGenerating: boolean;
|
|
12
|
+
downloadProgress: number;
|
|
13
|
+
forward: (imageSource: string) => Promise<any>;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useNonStaticModule } from '../useNonStaticModule';
|
|
2
|
+
import { ClassificationModule } from '../../modules/computer_vision/ClassificationModule';
|
|
3
|
+
export const useClassification = ({ model, preventLoad = false }) => useNonStaticModule({
|
|
4
|
+
module: ClassificationModule,
|
|
5
|
+
model,
|
|
6
|
+
preventLoad: preventLoad,
|
|
7
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ResourceSource } from '../../types/common';
|
|
2
|
+
interface Props {
|
|
3
|
+
model: {
|
|
4
|
+
modelSource: ResourceSource;
|
|
5
|
+
};
|
|
6
|
+
preventLoad?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const useImageEmbeddings: ({ model, preventLoad }: Props) => {
|
|
9
|
+
error: string | null;
|
|
10
|
+
isReady: boolean;
|
|
11
|
+
isGenerating: boolean;
|
|
12
|
+
downloadProgress: number;
|
|
13
|
+
forward: (imageSource: string) => Promise<Float32Array<ArrayBufferLike>>;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ImageEmbeddingsModule } from '../../modules/computer_vision/ImageEmbeddingsModule';
|
|
2
|
+
import { useNonStaticModule } from '../useNonStaticModule';
|
|
3
|
+
export const useImageEmbeddings = ({ model, preventLoad = false }) => useNonStaticModule({
|
|
4
|
+
module: ImageEmbeddingsModule,
|
|
5
|
+
model,
|
|
6
|
+
preventLoad,
|
|
7
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ResourceSource } from '../../types/common';
|
|
2
|
+
interface Props {
|
|
3
|
+
model: {
|
|
4
|
+
modelSource: ResourceSource;
|
|
5
|
+
};
|
|
6
|
+
preventLoad?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const useImageSegmentation: ({ model, preventLoad }: Props) => {
|
|
9
|
+
error: string | null;
|
|
10
|
+
isReady: boolean;
|
|
11
|
+
isGenerating: boolean;
|
|
12
|
+
downloadProgress: number;
|
|
13
|
+
forward: (imageSource: string, classesOfInterest?: import("../..").DeeplabLabel[] | undefined, resize?: boolean | undefined) => Promise<{
|
|
14
|
+
0?: number[] | undefined;
|
|
15
|
+
1?: number[] | undefined;
|
|
16
|
+
2?: number[] | undefined;
|
|
17
|
+
3?: number[] | undefined;
|
|
18
|
+
4?: number[] | undefined;
|
|
19
|
+
5?: number[] | undefined;
|
|
20
|
+
6?: number[] | undefined;
|
|
21
|
+
7?: number[] | undefined;
|
|
22
|
+
8?: number[] | undefined;
|
|
23
|
+
9?: number[] | undefined;
|
|
24
|
+
10?: number[] | undefined;
|
|
25
|
+
11?: number[] | undefined;
|
|
26
|
+
12?: number[] | undefined;
|
|
27
|
+
13?: number[] | undefined;
|
|
28
|
+
14?: number[] | undefined;
|
|
29
|
+
15?: number[] | undefined;
|
|
30
|
+
16?: number[] | undefined;
|
|
31
|
+
17?: number[] | undefined;
|
|
32
|
+
18?: number[] | undefined;
|
|
33
|
+
19?: number[] | undefined;
|
|
34
|
+
20?: number[] | undefined;
|
|
35
|
+
21?: number[] | undefined;
|
|
36
|
+
}>;
|
|
37
|
+
};
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useNonStaticModule } from '../useNonStaticModule';
|
|
2
|
+
import { ImageSegmentationModule } from '../../modules/computer_vision/ImageSegmentationModule';
|
|
3
|
+
export const useImageSegmentation = ({ model, preventLoad = false }) => useNonStaticModule({
|
|
4
|
+
module: ImageSegmentationModule,
|
|
5
|
+
model,
|
|
6
|
+
preventLoad,
|
|
7
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ResourceSource } from '../../types/common';
|
|
2
|
+
import { OCRDetection, OCRLanguage } from '../../types/ocr';
|
|
3
|
+
interface OCRModule {
|
|
4
|
+
error: string | null;
|
|
5
|
+
isReady: boolean;
|
|
6
|
+
isGenerating: boolean;
|
|
7
|
+
forward: (input: string) => Promise<OCRDetection[]>;
|
|
8
|
+
downloadProgress: number;
|
|
9
|
+
}
|
|
10
|
+
export declare const useOCR: ({ model, preventLoad, }: {
|
|
11
|
+
model: {
|
|
12
|
+
detectorSource: ResourceSource;
|
|
13
|
+
recognizerLarge: ResourceSource;
|
|
14
|
+
recognizerMedium: ResourceSource;
|
|
15
|
+
recognizerSmall: ResourceSource;
|
|
16
|
+
language: OCRLanguage;
|
|
17
|
+
};
|
|
18
|
+
preventLoad?: boolean;
|
|
19
|
+
}) => OCRModule;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { OCRController } from '../../controllers/OCRController';
|
|
3
|
+
export const useOCR = ({ 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 controllerInstance = useMemo(() => new OCRController({
|
|
9
|
+
isReadyCallback: setIsReady,
|
|
10
|
+
isGeneratingCallback: setIsGenerating,
|
|
11
|
+
errorCallback: setError,
|
|
12
|
+
}), []);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (preventLoad)
|
|
15
|
+
return;
|
|
16
|
+
(async () => {
|
|
17
|
+
await controllerInstance.load(model.detectorSource, {
|
|
18
|
+
recognizerLarge: model.recognizerLarge,
|
|
19
|
+
recognizerMedium: model.recognizerMedium,
|
|
20
|
+
recognizerSmall: model.recognizerSmall,
|
|
21
|
+
}, model.language, setDownloadProgress);
|
|
22
|
+
})();
|
|
23
|
+
return () => {
|
|
24
|
+
controllerInstance.delete();
|
|
25
|
+
};
|
|
26
|
+
}, [
|
|
27
|
+
controllerInstance,
|
|
28
|
+
model.detectorSource,
|
|
29
|
+
model.recognizerLarge,
|
|
30
|
+
model.recognizerMedium,
|
|
31
|
+
model.recognizerSmall,
|
|
32
|
+
model.language,
|
|
33
|
+
preventLoad,
|
|
34
|
+
]);
|
|
35
|
+
return {
|
|
36
|
+
error,
|
|
37
|
+
isReady,
|
|
38
|
+
isGenerating,
|
|
39
|
+
forward: controllerInstance.forward,
|
|
40
|
+
downloadProgress,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ResourceSource } from '../../types/common';
|
|
2
|
+
interface Props {
|
|
3
|
+
model: {
|
|
4
|
+
modelSource: ResourceSource;
|
|
5
|
+
};
|
|
6
|
+
preventLoad?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const useObjectDetection: ({ model, preventLoad }: Props) => {
|
|
9
|
+
error: string | null;
|
|
10
|
+
isReady: boolean;
|
|
11
|
+
isGenerating: boolean;
|
|
12
|
+
downloadProgress: number;
|
|
13
|
+
forward: (imageSource: string, detectionThreshold?: number | undefined) => Promise<import("../..").Detection[]>;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useNonStaticModule } from '../useNonStaticModule';
|
|
2
|
+
import { ObjectDetectionModule } from '../../modules/computer_vision/ObjectDetectionModule';
|
|
3
|
+
export const useObjectDetection = ({ model, preventLoad = false }) => useNonStaticModule({
|
|
4
|
+
module: ObjectDetectionModule,
|
|
5
|
+
model,
|
|
6
|
+
preventLoad: preventLoad,
|
|
7
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ResourceSource } from '../../types/common';
|
|
2
|
+
interface Props {
|
|
3
|
+
model: {
|
|
4
|
+
modelSource: ResourceSource;
|
|
5
|
+
};
|
|
6
|
+
preventLoad?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const useStyleTransfer: ({ model, preventLoad }: Props) => {
|
|
9
|
+
error: string | null;
|
|
10
|
+
isReady: boolean;
|
|
11
|
+
isGenerating: boolean;
|
|
12
|
+
downloadProgress: number;
|
|
13
|
+
forward: (imageSource: string) => Promise<string>;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useNonStaticModule } from '../useNonStaticModule';
|
|
2
|
+
import { StyleTransferModule } from '../../modules/computer_vision/StyleTransferModule';
|
|
3
|
+
export const useStyleTransfer = ({ model, preventLoad = false }) => useNonStaticModule({
|
|
4
|
+
module: StyleTransferModule,
|
|
5
|
+
model,
|
|
6
|
+
preventLoad: preventLoad,
|
|
7
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ResourceSource } from '../../types/common';
|
|
2
|
+
import { OCRDetection, OCRLanguage } from '../../types/ocr';
|
|
3
|
+
interface OCRModule {
|
|
4
|
+
error: string | null;
|
|
5
|
+
isReady: boolean;
|
|
6
|
+
isGenerating: boolean;
|
|
7
|
+
forward: (input: string) => Promise<OCRDetection[]>;
|
|
8
|
+
downloadProgress: number;
|
|
9
|
+
}
|
|
10
|
+
export declare const useVerticalOCR: ({ model, independentCharacters, preventLoad, }: {
|
|
11
|
+
model: {
|
|
12
|
+
detectorLarge: ResourceSource;
|
|
13
|
+
detectorNarrow: ResourceSource;
|
|
14
|
+
recognizerLarge: ResourceSource;
|
|
15
|
+
recognizerSmall: ResourceSource;
|
|
16
|
+
language: OCRLanguage;
|
|
17
|
+
};
|
|
18
|
+
independentCharacters?: boolean;
|
|
19
|
+
preventLoad?: boolean;
|
|
20
|
+
}) => OCRModule;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { VerticalOCRController } from '../../controllers/VerticalOCRController';
|
|
3
|
+
export const useVerticalOCR = ({ model, independentCharacters = false, 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 controllerInstance = useMemo(() => new VerticalOCRController({
|
|
9
|
+
isReadyCallback: setIsReady,
|
|
10
|
+
isGeneratingCallback: setIsGenerating,
|
|
11
|
+
errorCallback: setError,
|
|
12
|
+
}), []);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (preventLoad)
|
|
15
|
+
return;
|
|
16
|
+
(async () => {
|
|
17
|
+
await controllerInstance.load({
|
|
18
|
+
detectorLarge: model.detectorLarge,
|
|
19
|
+
detectorNarrow: model.detectorNarrow,
|
|
20
|
+
}, {
|
|
21
|
+
recognizerLarge: model.recognizerLarge,
|
|
22
|
+
recognizerSmall: model.recognizerSmall,
|
|
23
|
+
}, model.language, independentCharacters, setDownloadProgress);
|
|
24
|
+
})();
|
|
25
|
+
return () => {
|
|
26
|
+
controllerInstance.delete();
|
|
27
|
+
};
|
|
28
|
+
}, [
|
|
29
|
+
controllerInstance,
|
|
30
|
+
model.detectorLarge,
|
|
31
|
+
model.detectorNarrow,
|
|
32
|
+
model.recognizerLarge,
|
|
33
|
+
model.recognizerSmall,
|
|
34
|
+
model.language,
|
|
35
|
+
independentCharacters,
|
|
36
|
+
preventLoad,
|
|
37
|
+
]);
|
|
38
|
+
return {
|
|
39
|
+
error,
|
|
40
|
+
isReady,
|
|
41
|
+
isGenerating,
|
|
42
|
+
forward: controllerInstance.forward,
|
|
43
|
+
downloadProgress,
|
|
44
|
+
};
|
|
45
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ResourceSource } from '../../types/common';
|
|
2
|
+
interface Props {
|
|
3
|
+
modelSource: ResourceSource;
|
|
4
|
+
preventLoad?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare const useExecutorchModule: ({ modelSource, preventLoad, }: Props) => {
|
|
7
|
+
error: string | null;
|
|
8
|
+
isReady: boolean;
|
|
9
|
+
isGenerating: boolean;
|
|
10
|
+
downloadProgress: number;
|
|
11
|
+
forward: (inputTensor: import("../../types/common").TensorPtr[]) => Promise<import("../../types/common").TensorPtr[]>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ExecutorchModule } from '../../modules/general/ExecutorchModule';
|
|
2
|
+
import { useNonStaticModule } from '../useNonStaticModule';
|
|
3
|
+
export const useExecutorchModule = ({ modelSource, preventLoad = false, }) => useNonStaticModule({
|
|
4
|
+
module: ExecutorchModule,
|
|
5
|
+
model: { modelSource },
|
|
6
|
+
preventLoad,
|
|
7
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ResourceSource } from '../../types/common';
|
|
2
|
+
import { LLMType } from '../../types/llm';
|
|
3
|
+
export declare const useLLM: ({ model, preventLoad, }: {
|
|
4
|
+
model: {
|
|
5
|
+
modelSource: ResourceSource;
|
|
6
|
+
tokenizerSource: ResourceSource;
|
|
7
|
+
tokenizerConfigSource: ResourceSource;
|
|
8
|
+
};
|
|
9
|
+
preventLoad?: boolean;
|
|
10
|
+
}) => LLMType;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { LLMController } from '../../controllers/LLMController';
|
|
3
|
+
/*
|
|
4
|
+
Hook version of LLMModule
|
|
5
|
+
*/
|
|
6
|
+
export const useLLM = ({ model, preventLoad = false, }) => {
|
|
7
|
+
const [token, setToken] = useState('');
|
|
8
|
+
const [response, setResponse] = useState('');
|
|
9
|
+
const [messageHistory, setMessageHistory] = useState([]);
|
|
10
|
+
const [isReady, setIsReady] = useState(false);
|
|
11
|
+
const [isGenerating, setIsGenerating] = useState(false);
|
|
12
|
+
const [downloadProgress, setDownloadProgress] = useState(0);
|
|
13
|
+
const [error, setError] = useState(null);
|
|
14
|
+
const tokenCallback = useCallback((newToken) => {
|
|
15
|
+
setToken(newToken);
|
|
16
|
+
setResponse((prevResponse) => prevResponse + newToken);
|
|
17
|
+
}, []);
|
|
18
|
+
const controllerInstance = useMemo(() => new LLMController({
|
|
19
|
+
tokenCallback: tokenCallback,
|
|
20
|
+
messageHistoryCallback: setMessageHistory,
|
|
21
|
+
isReadyCallback: setIsReady,
|
|
22
|
+
isGeneratingCallback: setIsGenerating,
|
|
23
|
+
}), [tokenCallback]);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
setDownloadProgress(0);
|
|
26
|
+
setError(null);
|
|
27
|
+
if (preventLoad)
|
|
28
|
+
return;
|
|
29
|
+
(async () => {
|
|
30
|
+
try {
|
|
31
|
+
await controllerInstance.load({
|
|
32
|
+
modelSource: model.modelSource,
|
|
33
|
+
tokenizerSource: model.tokenizerSource,
|
|
34
|
+
tokenizerConfigSource: model.tokenizerConfigSource,
|
|
35
|
+
onDownloadProgressCallback: setDownloadProgress,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
setError(e);
|
|
40
|
+
}
|
|
41
|
+
})();
|
|
42
|
+
return () => {
|
|
43
|
+
controllerInstance.delete();
|
|
44
|
+
};
|
|
45
|
+
}, [
|
|
46
|
+
controllerInstance,
|
|
47
|
+
model.modelSource,
|
|
48
|
+
model.tokenizerSource,
|
|
49
|
+
model.tokenizerConfigSource,
|
|
50
|
+
preventLoad,
|
|
51
|
+
]);
|
|
52
|
+
// memoization of returned functions
|
|
53
|
+
const configure = useCallback(({ chatConfig, toolsConfig, }) => controllerInstance.configure({ chatConfig, toolsConfig }), [controllerInstance]);
|
|
54
|
+
const generate = useCallback((messages, tools) => {
|
|
55
|
+
setResponse('');
|
|
56
|
+
return controllerInstance.generate(messages, tools);
|
|
57
|
+
}, [controllerInstance]);
|
|
58
|
+
const sendMessage = useCallback((message) => {
|
|
59
|
+
setResponse('');
|
|
60
|
+
return controllerInstance.sendMessage(message);
|
|
61
|
+
}, [controllerInstance]);
|
|
62
|
+
const deleteMessage = useCallback((index) => controllerInstance.deleteMessage(index), [controllerInstance]);
|
|
63
|
+
const interrupt = useCallback(() => controllerInstance.interrupt(), [controllerInstance]);
|
|
64
|
+
return {
|
|
65
|
+
messageHistory,
|
|
66
|
+
response,
|
|
67
|
+
token,
|
|
68
|
+
isReady,
|
|
69
|
+
isGenerating,
|
|
70
|
+
downloadProgress,
|
|
71
|
+
error,
|
|
72
|
+
configure: configure,
|
|
73
|
+
generate: generate,
|
|
74
|
+
sendMessage: sendMessage,
|
|
75
|
+
deleteMessage: deleteMessage,
|
|
76
|
+
interrupt: interrupt,
|
|
77
|
+
};
|
|
78
|
+
};
|