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.
- package/common/rnexecutorch/ErrorCodes.h +15 -30
- package/common/rnexecutorch/host_objects/ModelHostObject.h +5 -0
- package/common/rnexecutorch/models/llm/LLM.cpp +7 -0
- package/common/rnexecutorch/models/llm/LLM.h +1 -0
- package/lib/module/constants/llmDefaults.js +31 -0
- package/lib/module/constants/llmDefaults.js.map +1 -1
- package/lib/module/constants/modelUrls.js +220 -0
- package/lib/module/constants/modelUrls.js.map +1 -1
- package/lib/module/constants/ocr/models.js +255 -73
- package/lib/module/constants/ocr/models.js.map +1 -1
- package/lib/module/constants/ocr/symbols.js +4 -0
- package/lib/module/constants/ocr/symbols.js.map +1 -1
- package/lib/module/constants/tts/models.js +6 -2
- package/lib/module/constants/tts/models.js.map +1 -1
- package/lib/module/constants/tts/voices.js +27 -3
- package/lib/module/constants/tts/voices.js.map +1 -1
- package/lib/module/constants/versions.js +2 -2
- package/lib/module/controllers/LLMController.js +9 -0
- package/lib/module/controllers/LLMController.js.map +1 -1
- package/lib/module/errors/ErrorCodes.js +54 -0
- package/lib/module/errors/ErrorCodes.js.map +1 -1
- package/lib/module/errors/errorUtils.js +30 -6
- package/lib/module/errors/errorUtils.js.map +1 -1
- package/lib/module/hooks/computer_vision/useClassification.js +7 -0
- package/lib/module/hooks/computer_vision/useClassification.js.map +1 -1
- package/lib/module/hooks/computer_vision/useImageEmbeddings.js +8 -0
- package/lib/module/hooks/computer_vision/useImageEmbeddings.js.map +1 -1
- package/lib/module/hooks/computer_vision/useImageSegmentation.js +7 -0
- package/lib/module/hooks/computer_vision/useImageSegmentation.js.map +1 -1
- package/lib/module/hooks/computer_vision/useOCR.js +7 -0
- package/lib/module/hooks/computer_vision/useOCR.js.map +1 -1
- package/lib/module/hooks/computer_vision/useObjectDetection.js +7 -0
- package/lib/module/hooks/computer_vision/useObjectDetection.js.map +1 -1
- package/lib/module/hooks/computer_vision/useStyleTransfer.js +7 -0
- package/lib/module/hooks/computer_vision/useStyleTransfer.js.map +1 -1
- package/lib/module/hooks/computer_vision/useTextToImage.js +7 -0
- package/lib/module/hooks/computer_vision/useTextToImage.js.map +1 -1
- package/lib/module/hooks/computer_vision/useVerticalOCR.js +7 -0
- package/lib/module/hooks/computer_vision/useVerticalOCR.js.map +1 -1
- package/lib/module/hooks/general/useExecutorchModule.js +8 -0
- package/lib/module/hooks/general/useExecutorchModule.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useLLM.js +11 -3
- package/lib/module/hooks/natural_language_processing/useLLM.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useSpeechToText.js +8 -0
- package/lib/module/hooks/natural_language_processing/useSpeechToText.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useTextEmbeddings.js +7 -0
- package/lib/module/hooks/natural_language_processing/useTextEmbeddings.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useTextToSpeech.js +8 -0
- package/lib/module/hooks/natural_language_processing/useTextToSpeech.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useTokenizer.js +7 -0
- package/lib/module/hooks/natural_language_processing/useTokenizer.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useVAD.js +7 -0
- package/lib/module/hooks/natural_language_processing/useVAD.js.map +1 -1
- package/lib/module/hooks/useModule.js +12 -0
- package/lib/module/hooks/useModule.js.map +1 -1
- package/lib/module/index.js +10 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/modules/BaseModule.js +22 -0
- package/lib/module/modules/BaseModule.js.map +1 -1
- package/lib/module/modules/computer_vision/ClassificationModule.js +20 -0
- package/lib/module/modules/computer_vision/ClassificationModule.js.map +1 -1
- package/lib/module/modules/computer_vision/ImageEmbeddingsModule.js +19 -0
- package/lib/module/modules/computer_vision/ImageEmbeddingsModule.js.map +1 -1
- package/lib/module/modules/computer_vision/ImageSegmentationModule.js +22 -0
- package/lib/module/modules/computer_vision/ImageSegmentationModule.js.map +1 -1
- package/lib/module/modules/computer_vision/OCRModule.js +26 -0
- package/lib/module/modules/computer_vision/OCRModule.js.map +1 -1
- package/lib/module/modules/computer_vision/ObjectDetectionModule.js +22 -0
- package/lib/module/modules/computer_vision/ObjectDetectionModule.js.map +1 -1
- package/lib/module/modules/computer_vision/StyleTransferModule.js +20 -0
- package/lib/module/modules/computer_vision/StyleTransferModule.js.map +1 -1
- package/lib/module/modules/computer_vision/TextToImageModule.js +33 -0
- package/lib/module/modules/computer_vision/TextToImageModule.js.map +1 -1
- package/lib/module/modules/computer_vision/VerticalOCRModule.js +27 -0
- package/lib/module/modules/computer_vision/VerticalOCRModule.js.map +1 -1
- package/lib/module/modules/general/ExecutorchModule.js +21 -0
- package/lib/module/modules/general/ExecutorchModule.js.map +1 -1
- package/lib/module/modules/natural_language_processing/LLMModule.js +104 -0
- package/lib/module/modules/natural_language_processing/LLMModule.js.map +1 -1
- package/lib/module/modules/natural_language_processing/SpeechToTextModule.js +67 -21
- package/lib/module/modules/natural_language_processing/SpeechToTextModule.js.map +1 -1
- package/lib/module/modules/natural_language_processing/TextEmbeddingsModule.js +21 -0
- package/lib/module/modules/natural_language_processing/TextEmbeddingsModule.js.map +1 -1
- package/lib/module/modules/natural_language_processing/TextToSpeechModule.js +40 -0
- package/lib/module/modules/natural_language_processing/TextToSpeechModule.js.map +1 -1
- package/lib/module/modules/natural_language_processing/TokenizerModule.js +54 -2
- package/lib/module/modules/natural_language_processing/TokenizerModule.js.map +1 -1
- package/lib/module/modules/natural_language_processing/VADModule.js +20 -0
- package/lib/module/modules/natural_language_processing/VADModule.js.map +1 -1
- package/lib/module/types/classification.js +4 -0
- package/lib/module/types/classification.js.map +1 -0
- package/lib/module/types/common.js +96 -0
- package/lib/module/types/common.js.map +1 -1
- package/lib/module/types/executorchModule.js +4 -0
- package/lib/module/types/executorchModule.js.map +1 -0
- package/lib/module/types/imageEmbeddings.js +4 -0
- package/lib/module/types/imageEmbeddings.js.map +1 -0
- package/lib/module/types/imageSegmentation.js +22 -1
- package/lib/module/types/imageSegmentation.js.map +1 -1
- package/lib/module/types/llm.js +80 -2
- package/lib/module/types/llm.js.map +1 -1
- package/lib/module/types/objectDetection.js +42 -2
- package/lib/module/types/objectDetection.js.map +1 -1
- package/lib/module/types/styleTransfer.js +4 -0
- package/lib/module/types/styleTransfer.js.map +1 -0
- package/lib/module/types/textEmbeddings.js +4 -0
- package/lib/module/types/textEmbeddings.js.map +1 -0
- package/lib/module/types/tokenizer.js +4 -0
- package/lib/module/types/tokenizer.js.map +1 -0
- package/lib/module/types/tti.js +4 -0
- package/lib/module/types/tti.js.map +1 -0
- package/lib/module/types/vad.js +2 -0
- package/lib/module/utils/ResourceFetcher.js +63 -0
- package/lib/module/utils/ResourceFetcher.js.map +1 -1
- package/lib/module/utils/llm.js +24 -1
- package/lib/module/utils/llm.js.map +1 -1
- package/lib/typescript/constants/llmDefaults.d.ts +27 -0
- package/lib/typescript/constants/llmDefaults.d.ts.map +1 -1
- package/lib/typescript/constants/modelUrls.d.ts +165 -0
- package/lib/typescript/constants/modelUrls.d.ts.map +1 -1
- package/lib/typescript/constants/ocr/models.d.ts +189 -315
- package/lib/typescript/constants/ocr/models.d.ts.map +1 -1
- package/lib/typescript/constants/ocr/symbols.d.ts +3 -0
- package/lib/typescript/constants/ocr/symbols.d.ts.map +1 -1
- package/lib/typescript/constants/tts/models.d.ts +4 -0
- package/lib/typescript/constants/tts/models.d.ts.map +1 -1
- package/lib/typescript/constants/tts/voices.d.ts +24 -0
- package/lib/typescript/constants/tts/voices.d.ts.map +1 -1
- package/lib/typescript/constants/versions.d.ts +2 -2
- package/lib/typescript/controllers/LLMController.d.ts +2 -0
- package/lib/typescript/controllers/LLMController.d.ts.map +1 -1
- package/lib/typescript/errors/ErrorCodes.d.ts +54 -0
- package/lib/typescript/errors/ErrorCodes.d.ts.map +1 -1
- package/lib/typescript/errors/errorUtils.d.ts +9 -0
- package/lib/typescript/errors/errorUtils.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useClassification.d.ts +9 -15
- package/lib/typescript/hooks/computer_vision/useClassification.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useImageEmbeddings.d.ts +9 -15
- package/lib/typescript/hooks/computer_vision/useImageEmbeddings.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useImageSegmentation.d.ts +9 -38
- package/lib/typescript/hooks/computer_vision/useImageSegmentation.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useOCR.d.ts +9 -19
- package/lib/typescript/hooks/computer_vision/useOCR.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useObjectDetection.d.ts +9 -15
- package/lib/typescript/hooks/computer_vision/useObjectDetection.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useStyleTransfer.d.ts +9 -15
- package/lib/typescript/hooks/computer_vision/useStyleTransfer.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useTextToImage.d.ts +9 -22
- package/lib/typescript/hooks/computer_vision/useTextToImage.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useVerticalOCR.d.ts +9 -20
- package/lib/typescript/hooks/computer_vision/useVerticalOCR.d.ts.map +1 -1
- package/lib/typescript/hooks/general/useExecutorchModule.d.ts +9 -13
- package/lib/typescript/hooks/general/useExecutorchModule.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts +9 -10
- package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts +9 -19
- package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useTextEmbeddings.d.ts +9 -16
- package/lib/typescript/hooks/natural_language_processing/useTextEmbeddings.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useTextToSpeech.d.ts +9 -15
- package/lib/typescript/hooks/natural_language_processing/useTextToSpeech.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useTokenizer.d.ts +9 -18
- package/lib/typescript/hooks/natural_language_processing/useTokenizer.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useVAD.d.ts +9 -15
- package/lib/typescript/hooks/natural_language_processing/useVAD.d.ts.map +1 -1
- package/lib/typescript/hooks/useModule.d.ts +12 -0
- package/lib/typescript/hooks/useModule.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +10 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/modules/BaseModule.d.ts +20 -0
- package/lib/typescript/modules/BaseModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/ClassificationModule.d.ts +21 -1
- package/lib/typescript/modules/computer_vision/ClassificationModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/ImageEmbeddingsModule.d.ts +17 -0
- package/lib/typescript/modules/computer_vision/ImageEmbeddingsModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/ImageSegmentationModule.d.ts +21 -3
- package/lib/typescript/modules/computer_vision/ImageSegmentationModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/OCRModule.d.ts +25 -2
- package/lib/typescript/modules/computer_vision/OCRModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/ObjectDetectionModule.d.ts +20 -0
- package/lib/typescript/modules/computer_vision/ObjectDetectionModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/StyleTransferModule.d.ts +18 -0
- package/lib/typescript/modules/computer_vision/StyleTransferModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/TextToImageModule.d.ts +29 -0
- package/lib/typescript/modules/computer_vision/TextToImageModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/VerticalOCRModule.d.ts +26 -2
- package/lib/typescript/modules/computer_vision/VerticalOCRModule.d.ts.map +1 -1
- package/lib/typescript/modules/general/ExecutorchModule.d.ts +19 -0
- package/lib/typescript/modules/general/ExecutorchModule.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts +97 -7
- package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts +62 -4
- package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/TextEmbeddingsModule.d.ts +19 -0
- package/lib/typescript/modules/natural_language_processing/TextEmbeddingsModule.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/TextToSpeechModule.d.ts +37 -2
- package/lib/typescript/modules/natural_language_processing/TextToSpeechModule.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/TokenizerModule.d.ts +47 -2
- package/lib/typescript/modules/natural_language_processing/TokenizerModule.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/VADModule.d.ts +18 -0
- package/lib/typescript/modules/natural_language_processing/VADModule.d.ts.map +1 -1
- package/lib/typescript/types/classification.d.ts +50 -0
- package/lib/typescript/types/classification.d.ts.map +1 -0
- package/lib/typescript/types/common.d.ts +92 -0
- package/lib/typescript/types/common.d.ts.map +1 -1
- package/lib/typescript/types/executorchModule.d.ts +45 -0
- package/lib/typescript/types/executorchModule.d.ts.map +1 -0
- package/lib/typescript/types/imageEmbeddings.d.ts +48 -0
- package/lib/typescript/types/imageEmbeddings.d.ts.map +1 -0
- package/lib/typescript/types/imageSegmentation.d.ts +55 -0
- package/lib/typescript/types/imageSegmentation.d.ts.map +1 -1
- package/lib/typescript/types/llm.d.ts +193 -5
- package/lib/typescript/types/llm.d.ts.map +1 -1
- package/lib/typescript/types/objectDetection.d.ts +71 -2
- package/lib/typescript/types/objectDetection.d.ts.map +1 -1
- package/lib/typescript/types/ocr.d.ts +97 -2
- package/lib/typescript/types/ocr.d.ts.map +1 -1
- package/lib/typescript/types/stt.d.ts +114 -0
- package/lib/typescript/types/stt.d.ts.map +1 -1
- package/lib/typescript/types/styleTransfer.d.ts +48 -0
- package/lib/typescript/types/styleTransfer.d.ts.map +1 -0
- package/lib/typescript/types/textEmbeddings.d.ts +53 -0
- package/lib/typescript/types/textEmbeddings.d.ts.map +1 -0
- package/lib/typescript/types/tokenizer.d.ts +75 -0
- package/lib/typescript/types/tokenizer.d.ts.map +1 -0
- package/lib/typescript/types/tti.d.ts +74 -0
- package/lib/typescript/types/tti.d.ts.map +1 -0
- package/lib/typescript/types/tts.d.ts +77 -0
- package/lib/typescript/types/tts.d.ts.map +1 -1
- package/lib/typescript/types/vad.d.ts +53 -0
- package/lib/typescript/types/vad.d.ts.map +1 -1
- package/lib/typescript/utils/ResourceFetcher.d.ts +55 -0
- package/lib/typescript/utils/ResourceFetcher.d.ts.map +1 -1
- package/lib/typescript/utils/llm.d.ts +22 -0
- package/lib/typescript/utils/llm.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/constants/llmDefaults.ts +27 -0
- package/src/constants/modelUrls.ts +166 -0
- package/src/constants/ocr/models.ts +192 -266
- package/src/constants/ocr/symbols.ts +3 -0
- package/src/constants/tts/models.ts +6 -2
- package/src/constants/tts/voices.ts +27 -3
- package/src/constants/versions.ts +2 -2
- package/src/controllers/LLMController.ts +15 -0
- package/src/errors/ErrorCodes.ts +54 -0
- package/src/errors/errorUtils.ts +37 -17
- package/src/hooks/computer_vision/useClassification.ts +15 -7
- package/src/hooks/computer_vision/useImageEmbeddings.ts +15 -7
- package/src/hooks/computer_vision/useImageSegmentation.ts +15 -7
- package/src/hooks/computer_vision/useOCR.ts +9 -21
- package/src/hooks/computer_vision/useObjectDetection.ts +15 -7
- package/src/hooks/computer_vision/useStyleTransfer.ts +15 -7
- package/src/hooks/computer_vision/useTextToImage.ts +9 -26
- package/src/hooks/computer_vision/useVerticalOCR.ts +9 -19
- package/src/hooks/general/useExecutorchModule.ts +12 -7
- package/src/hooks/natural_language_processing/useLLM.ts +24 -28
- package/src/hooks/natural_language_processing/useSpeechToText.ts +13 -5
- package/src/hooks/natural_language_processing/useTextEmbeddings.ts +15 -10
- package/src/hooks/natural_language_processing/useTextToSpeech.ts +10 -6
- package/src/hooks/natural_language_processing/useTokenizer.ts +10 -6
- package/src/hooks/natural_language_processing/useVAD.ts +9 -7
- package/src/hooks/useModule.ts +15 -0
- package/src/index.ts +10 -5
- package/src/modules/BaseModule.ts +20 -0
- package/src/modules/computer_vision/ClassificationModule.ts +19 -1
- package/src/modules/computer_vision/ImageEmbeddingsModule.ts +17 -0
- package/src/modules/computer_vision/ImageSegmentationModule.ts +21 -1
- package/src/modules/computer_vision/OCRModule.ts +25 -2
- package/src/modules/computer_vision/ObjectDetectionModule.ts +20 -0
- package/src/modules/computer_vision/StyleTransferModule.ts +18 -0
- package/src/modules/computer_vision/TextToImageModule.ts +29 -0
- package/src/modules/computer_vision/VerticalOCRModule.ts +26 -2
- package/src/modules/general/ExecutorchModule.ts +19 -0
- package/src/modules/natural_language_processing/LLMModule.ts +104 -18
- package/src/modules/natural_language_processing/SpeechToTextModule.ts +63 -39
- package/src/modules/natural_language_processing/TextEmbeddingsModule.ts +19 -0
- package/src/modules/natural_language_processing/TextToSpeechModule.ts +43 -2
- package/src/modules/natural_language_processing/TokenizerModule.ts +51 -3
- package/src/modules/natural_language_processing/VADModule.ts +18 -0
- package/src/types/classification.ts +51 -0
- package/src/types/common.ts +93 -0
- package/src/types/executorchModule.ts +50 -0
- package/src/types/imageEmbeddings.ts +51 -0
- package/src/types/imageSegmentation.ts +64 -1
- package/src/types/llm.ts +208 -11
- package/src/types/objectDetection.ts +79 -1
- package/src/types/ocr.ts +107 -2
- package/src/types/stt.ts +136 -1
- package/src/types/styleTransfer.ts +51 -0
- package/src/types/textEmbeddings.ts +58 -0
- package/src/types/tokenizer.ts +86 -0
- package/src/types/tti.ts +87 -0
- package/src/types/tts.ts +85 -2
- package/src/types/vad.ts +58 -0
- package/src/utils/ResourceFetcher.ts +55 -0
- package/src/utils/llm.ts +22 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { KokoroVoiceExtras, VoiceConfig } from '../../types/tts';
|
|
2
|
-
import { URL_PREFIX,
|
|
2
|
+
import { URL_PREFIX, VERSION_TAG } from '../versions';
|
|
3
3
|
|
|
4
4
|
// Kokoro voices - phonemizers
|
|
5
|
-
const KOKORO_PHONEMIZER_PREFIX = `${URL_PREFIX}-kokoro/${
|
|
5
|
+
const KOKORO_PHONEMIZER_PREFIX = `${URL_PREFIX}-kokoro/${VERSION_TAG}/phonemizer`;
|
|
6
6
|
const KOKORO_PHONEMIZER_TAGGER_DATA = `${KOKORO_PHONEMIZER_PREFIX}/tags.json`;
|
|
7
7
|
const KOKORO_PHONEMIZER_LEXICON_EN_US_DATA = `${KOKORO_PHONEMIZER_PREFIX}/us_merged.json`;
|
|
8
8
|
const KOKORO_PHONEMIZER_LEXICON_EN_GB_DATA = `${KOKORO_PHONEMIZER_PREFIX}/gb_merged.json`;
|
|
@@ -17,42 +17,66 @@ const EN_GB_RESOURCES = {
|
|
|
17
17
|
} as KokoroVoiceExtras;
|
|
18
18
|
|
|
19
19
|
// Kokoro voices
|
|
20
|
-
const KOKORO_VOICE_PREFIX = `${URL_PREFIX}-kokoro/${
|
|
20
|
+
const KOKORO_VOICE_PREFIX = `${URL_PREFIX}-kokoro/${VERSION_TAG}/voices`;
|
|
21
|
+
/**
|
|
22
|
+
* @category TTS Supported Voices
|
|
23
|
+
*/
|
|
21
24
|
export const KOKORO_VOICE_AF_HEART = {
|
|
22
25
|
lang: 'en-us' as const,
|
|
23
26
|
voiceSource: `${KOKORO_VOICE_PREFIX}/af_heart.bin`,
|
|
24
27
|
extra: EN_US_RESOURCES,
|
|
25
28
|
} as VoiceConfig;
|
|
29
|
+
/**
|
|
30
|
+
* @category TTS Supported Voices
|
|
31
|
+
*/
|
|
26
32
|
export const KOKORO_VOICE_AF_RIVER = {
|
|
27
33
|
lang: 'en-us' as const,
|
|
28
34
|
voiceSource: `${KOKORO_VOICE_PREFIX}/af_river.bin`,
|
|
29
35
|
extra: EN_US_RESOURCES,
|
|
30
36
|
} as VoiceConfig;
|
|
37
|
+
/**
|
|
38
|
+
* @category TTS Supported Voices
|
|
39
|
+
*/
|
|
31
40
|
export const KOKORO_VOICE_AF_SARAH = {
|
|
32
41
|
lang: 'en-us' as const,
|
|
33
42
|
voiceSource: `${KOKORO_VOICE_PREFIX}/af_sarah.bin`,
|
|
34
43
|
extra: EN_US_RESOURCES,
|
|
35
44
|
} as VoiceConfig;
|
|
45
|
+
/**
|
|
46
|
+
* @category TTS Supported Voices
|
|
47
|
+
*/
|
|
36
48
|
export const KOKORO_VOICE_AM_ADAM = {
|
|
37
49
|
lang: 'en-us' as const,
|
|
38
50
|
voiceSource: `${KOKORO_VOICE_PREFIX}/am_adam.bin`,
|
|
39
51
|
extra: EN_US_RESOURCES,
|
|
40
52
|
} as VoiceConfig;
|
|
53
|
+
/**
|
|
54
|
+
* @category TTS Supported Voices
|
|
55
|
+
*/
|
|
41
56
|
export const KOKORO_VOICE_AM_MICHAEL = {
|
|
42
57
|
lang: 'en-us' as const,
|
|
43
58
|
voiceSource: `${KOKORO_VOICE_PREFIX}/am_michael.bin`,
|
|
44
59
|
extra: EN_US_RESOURCES,
|
|
45
60
|
} as VoiceConfig;
|
|
61
|
+
/**
|
|
62
|
+
* @category TTS Supported Voices
|
|
63
|
+
*/
|
|
46
64
|
export const KOKORO_VOICE_AM_SANTA = {
|
|
47
65
|
lang: 'en-us' as const,
|
|
48
66
|
voiceSource: `${KOKORO_VOICE_PREFIX}/am_santa.bin`,
|
|
49
67
|
extra: EN_US_RESOURCES,
|
|
50
68
|
} as VoiceConfig;
|
|
69
|
+
/**
|
|
70
|
+
* @category TTS Supported Voices
|
|
71
|
+
*/
|
|
51
72
|
export const KOKORO_VOICE_BF_EMMA = {
|
|
52
73
|
lang: 'en-gb' as const,
|
|
53
74
|
voiceSource: `${KOKORO_VOICE_PREFIX}/bf_emma.bin`,
|
|
54
75
|
extra: EN_GB_RESOURCES,
|
|
55
76
|
} as VoiceConfig;
|
|
77
|
+
/**
|
|
78
|
+
* @category TTS Supported Voices
|
|
79
|
+
*/
|
|
56
80
|
export const KOKORO_VOICE_BM_DANIEL = {
|
|
57
81
|
lang: 'en-gb' as const,
|
|
58
82
|
voiceSource: `${KOKORO_VOICE_PREFIX}/bm_daniel.bin`,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export const URL_PREFIX =
|
|
2
2
|
'https://huggingface.co/software-mansion/react-native-executorch';
|
|
3
|
-
export const VERSION_TAG = 'resolve/v0.
|
|
4
|
-
export const NEXT_VERSION_TAG = 'resolve/v0.
|
|
3
|
+
export const VERSION_TAG = 'resolve/v0.7.0';
|
|
4
|
+
export const NEXT_VERSION_TAG = 'resolve/v0.8.0';
|
|
@@ -203,6 +203,7 @@ export class LLMController {
|
|
|
203
203
|
'You cannot delete the model now. You need ot interrupt it first.'
|
|
204
204
|
);
|
|
205
205
|
}
|
|
206
|
+
|
|
206
207
|
this.onToken = () => {};
|
|
207
208
|
if (this.nativeModule) {
|
|
208
209
|
this.nativeModule.unload();
|
|
@@ -255,6 +256,20 @@ export class LLMController {
|
|
|
255
256
|
return this.nativeModule.getGeneratedTokenCount();
|
|
256
257
|
}
|
|
257
258
|
|
|
259
|
+
public getPromptTokenCount(): number {
|
|
260
|
+
if (!this.nativeModule) {
|
|
261
|
+
throw new RnExecutorchError(
|
|
262
|
+
RnExecutorchErrorCode.ModuleNotLoaded,
|
|
263
|
+
"Cannot get prompt token count for a model that's not loaded."
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
return this.nativeModule.getPromptTokenCount();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
public getTotalTokenCount(): number {
|
|
270
|
+
return this.getGeneratedTokenCount() + this.getPromptTokenCount();
|
|
271
|
+
}
|
|
272
|
+
|
|
258
273
|
public async generate(
|
|
259
274
|
messages: Message[],
|
|
260
275
|
tools?: LLMTool[]
|
package/src/errors/ErrorCodes.ts
CHANGED
|
@@ -102,22 +102,76 @@ export enum RnExecutorchErrorCode {
|
|
|
102
102
|
* Thrown when required URI information is missing for a download operation.
|
|
103
103
|
*/
|
|
104
104
|
ResourceFetcherMissingUri = 185,
|
|
105
|
+
/**
|
|
106
|
+
* Status indicating a successful operation.
|
|
107
|
+
*/
|
|
105
108
|
Ok = 0,
|
|
109
|
+
/**
|
|
110
|
+
* An internal error occurred.
|
|
111
|
+
*/
|
|
106
112
|
Internal = 1,
|
|
113
|
+
/**
|
|
114
|
+
* Status indicating the executor is in an invalid state for a targeted operation.
|
|
115
|
+
*/
|
|
107
116
|
InvalidState = 2,
|
|
117
|
+
/**
|
|
118
|
+
* Status indicating there are no more steps of execution to run
|
|
119
|
+
*/
|
|
108
120
|
EndOfMethod = 3,
|
|
121
|
+
/**
|
|
122
|
+
* Operation is not supported in the current context.
|
|
123
|
+
*/
|
|
109
124
|
NotSupported = 16,
|
|
125
|
+
/**
|
|
126
|
+
* Operation is not yet implemented.
|
|
127
|
+
*/
|
|
110
128
|
NotImplemented = 17,
|
|
129
|
+
/**
|
|
130
|
+
* User provided an invalid argument.
|
|
131
|
+
*/
|
|
111
132
|
InvalidArgument = 18,
|
|
133
|
+
/**
|
|
134
|
+
* Object is an invalid type for the operation.
|
|
135
|
+
*/
|
|
112
136
|
InvalidType = 19,
|
|
137
|
+
/**
|
|
138
|
+
* Operator(s) missing in the operator registry.
|
|
139
|
+
*/
|
|
113
140
|
OperatorMissing = 20,
|
|
141
|
+
/**
|
|
142
|
+
* Requested resource could not be found.
|
|
143
|
+
*/
|
|
114
144
|
NotFound = 32,
|
|
145
|
+
/**
|
|
146
|
+
* Could not allocate the requested memory.
|
|
147
|
+
*/
|
|
115
148
|
MemoryAllocationFailed = 33,
|
|
149
|
+
/**
|
|
150
|
+
* Could not access a resource.
|
|
151
|
+
*/
|
|
116
152
|
AccessFailed = 34,
|
|
153
|
+
/**
|
|
154
|
+
* Error caused by the contents of a program.
|
|
155
|
+
*/
|
|
117
156
|
InvalidProgram = 35,
|
|
157
|
+
/**
|
|
158
|
+
* Error caused by the contents of external data.
|
|
159
|
+
*/
|
|
118
160
|
InvalidExternalData = 36,
|
|
161
|
+
/**
|
|
162
|
+
* Does not have enough resources to perform the requested operation.
|
|
163
|
+
*/
|
|
119
164
|
OutOfResources = 37,
|
|
165
|
+
/**
|
|
166
|
+
* Init stage: Backend receives an incompatible delegate version.
|
|
167
|
+
*/
|
|
120
168
|
DelegateInvalidCompatibility = 48,
|
|
169
|
+
/**
|
|
170
|
+
* Init stage: Backend fails to allocate memory.
|
|
171
|
+
*/
|
|
121
172
|
DelegateMemoryAllocationFailed = 49,
|
|
173
|
+
/**
|
|
174
|
+
* Execute stage: The handle is invalid.
|
|
175
|
+
*/
|
|
122
176
|
DelegateInvalidHandle = 50,
|
|
123
177
|
}
|
package/src/errors/errorUtils.ts
CHANGED
|
@@ -1,38 +1,58 @@
|
|
|
1
1
|
import { RnExecutorchErrorCode } from './ErrorCodes';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return (
|
|
7
|
-
typeof e === 'object' &&
|
|
8
|
-
e !== null &&
|
|
9
|
-
'code' in e &&
|
|
10
|
-
'message' in e &&
|
|
11
|
-
typeof (e as RnExecutorchError).code === 'number' &&
|
|
12
|
-
typeof (e as RnExecutorchError).message === 'string'
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Custom error class for React Native ExecuTorch errors.
|
|
5
|
+
*/
|
|
16
6
|
export class RnExecutorchError extends Error {
|
|
7
|
+
/**
|
|
8
|
+
* The error code representing the type of error.
|
|
9
|
+
*/
|
|
17
10
|
public code: RnExecutorchErrorCode;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The original cause of the error, if any.
|
|
14
|
+
*/
|
|
18
15
|
public cause?: unknown;
|
|
19
16
|
|
|
20
17
|
constructor(code: number, message: string, cause?: unknown) {
|
|
21
18
|
super(message);
|
|
19
|
+
/**
|
|
20
|
+
* The error code representing the type of error.
|
|
21
|
+
*/
|
|
22
22
|
this.code = code;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The message describing the error.
|
|
26
|
+
*/
|
|
23
27
|
this.message = message;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The original cause of the error, if any.
|
|
31
|
+
*/
|
|
24
32
|
this.cause = cause;
|
|
25
33
|
}
|
|
26
34
|
}
|
|
27
35
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
function isRnExecutorchErrorLike(
|
|
37
|
+
e: unknown
|
|
38
|
+
): e is { code: number; message: string } {
|
|
39
|
+
const candidate = e as Record<string, unknown>;
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
typeof e === 'object' &&
|
|
43
|
+
e !== null &&
|
|
44
|
+
typeof candidate.code === 'number' &&
|
|
45
|
+
typeof candidate.message === 'string'
|
|
46
|
+
);
|
|
47
|
+
}
|
|
32
48
|
|
|
49
|
+
export function parseUnknownError(e: unknown): RnExecutorchError {
|
|
33
50
|
if (e instanceof RnExecutorchError) {
|
|
34
51
|
return e;
|
|
35
52
|
}
|
|
53
|
+
if (isRnExecutorchErrorLike(e)) {
|
|
54
|
+
return new RnExecutorchError(e.code, e.message);
|
|
55
|
+
}
|
|
36
56
|
|
|
37
57
|
if (e instanceof Error) {
|
|
38
58
|
return new RnExecutorchError(RnExecutorchErrorCode.Internal, e.message, e);
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
import { ResourceSource } from '../../types/common';
|
|
2
1
|
import { useModule } from '../useModule';
|
|
3
2
|
import { ClassificationModule } from '../../modules/computer_vision/ClassificationModule';
|
|
3
|
+
import {
|
|
4
|
+
ClassificationProps,
|
|
5
|
+
ClassificationType,
|
|
6
|
+
} from '../../types/classification';
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
/**
|
|
9
|
+
* React hook for managing a Classification model instance.
|
|
10
|
+
*
|
|
11
|
+
* @category Hooks
|
|
12
|
+
* @param ClassificationProps - Configuration object containing `model` source and optional `preventLoad` flag.
|
|
13
|
+
* @returns Ready to use Classification model.
|
|
14
|
+
*/
|
|
15
|
+
export const useClassification = ({
|
|
16
|
+
model,
|
|
17
|
+
preventLoad = false,
|
|
18
|
+
}: ClassificationProps): ClassificationType =>
|
|
11
19
|
useModule({
|
|
12
20
|
module: ClassificationModule,
|
|
13
21
|
model,
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import { ImageEmbeddingsModule } from '../../modules/computer_vision/ImageEmbeddingsModule';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ImageEmbeddingsProps,
|
|
4
|
+
ImageEmbeddingsType,
|
|
5
|
+
} from '../../types/imageEmbeddings';
|
|
3
6
|
import { useModule } from '../useModule';
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
/**
|
|
9
|
+
* React hook for managing an Image Embeddings model instance.
|
|
10
|
+
*
|
|
11
|
+
* @category Hooks
|
|
12
|
+
* @param ImageEmbeddingsProps - Configuration object containing `model` source and optional `preventLoad` flag.
|
|
13
|
+
* @returns Ready to use Image Embeddings model.
|
|
14
|
+
*/
|
|
15
|
+
export const useImageEmbeddings = ({
|
|
16
|
+
model,
|
|
17
|
+
preventLoad = false,
|
|
18
|
+
}: ImageEmbeddingsProps): ImageEmbeddingsType =>
|
|
11
19
|
useModule({
|
|
12
20
|
module: ImageEmbeddingsModule,
|
|
13
21
|
model,
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import { useModule } from '../useModule';
|
|
2
2
|
import { ImageSegmentationModule } from '../../modules/computer_vision/ImageSegmentationModule';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
ImageSegmentationProps,
|
|
5
|
+
ImageSegmentationType,
|
|
6
|
+
} from '../../types/imageSegmentation';
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
/**
|
|
9
|
+
* React hook for managing an Image Segmentation model instance.
|
|
10
|
+
*
|
|
11
|
+
* @category Hooks
|
|
12
|
+
* @param ImageSegmentationProps - Configuration object containing `model` source and optional `preventLoad` flag.
|
|
13
|
+
* @returns Ready to use Image Segmentation model.
|
|
14
|
+
*/
|
|
15
|
+
export const useImageSegmentation = ({
|
|
16
|
+
model,
|
|
17
|
+
preventLoad = false,
|
|
18
|
+
}: ImageSegmentationProps): ImageSegmentationType =>
|
|
11
19
|
useModule({
|
|
12
20
|
module: ImageSegmentationModule,
|
|
13
21
|
model,
|
|
@@ -1,28 +1,16 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import { OCRDetection, OCRLanguage } from '../../types/ocr';
|
|
2
|
+
import { OCRProps, OCRType } from '../../types/ocr';
|
|
4
3
|
import { OCRController } from '../../controllers/OCRController';
|
|
5
4
|
import { RnExecutorchError } from '../../errors/errorUtils';
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export const useOCR = ({
|
|
16
|
-
model,
|
|
17
|
-
preventLoad = false,
|
|
18
|
-
}: {
|
|
19
|
-
model: {
|
|
20
|
-
detectorSource: ResourceSource;
|
|
21
|
-
recognizerSource: ResourceSource;
|
|
22
|
-
language: OCRLanguage;
|
|
23
|
-
};
|
|
24
|
-
preventLoad?: boolean;
|
|
25
|
-
}): OCRModule => {
|
|
6
|
+
/**
|
|
7
|
+
* React hook for managing an OCR instance.
|
|
8
|
+
*
|
|
9
|
+
* @category Hooks
|
|
10
|
+
* @param OCRProps - Configuration object containing `model` sources and optional `preventLoad` flag.
|
|
11
|
+
* @returns Ready to use OCR model.
|
|
12
|
+
*/
|
|
13
|
+
export const useOCR = ({ model, preventLoad = false }: OCRProps): OCRType => {
|
|
26
14
|
const [error, setError] = useState<RnExecutorchError | null>(null);
|
|
27
15
|
const [isReady, setIsReady] = useState(false);
|
|
28
16
|
const [isGenerating, setIsGenerating] = useState(false);
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
import { ResourceSource } from '../../types/common';
|
|
2
1
|
import { useModule } from '../useModule';
|
|
3
2
|
import { ObjectDetectionModule } from '../../modules/computer_vision/ObjectDetectionModule';
|
|
3
|
+
import {
|
|
4
|
+
ObjectDetectionProps,
|
|
5
|
+
ObjectDetectionType,
|
|
6
|
+
} from '../../types/objectDetection';
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
/**
|
|
9
|
+
* React hook for managing an Object Detection model instance.
|
|
10
|
+
*
|
|
11
|
+
* @category Hooks
|
|
12
|
+
* @param ObjectDetectionProps - Configuration object containing `model` source and optional `preventLoad` flag.
|
|
13
|
+
* @returns Ready to use Object Detection model.
|
|
14
|
+
*/
|
|
15
|
+
export const useObjectDetection = ({
|
|
16
|
+
model,
|
|
17
|
+
preventLoad = false,
|
|
18
|
+
}: ObjectDetectionProps): ObjectDetectionType =>
|
|
11
19
|
useModule({
|
|
12
20
|
module: ObjectDetectionModule,
|
|
13
21
|
model,
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
import { ResourceSource } from '../../types/common';
|
|
2
1
|
import { useModule } from '../useModule';
|
|
3
2
|
import { StyleTransferModule } from '../../modules/computer_vision/StyleTransferModule';
|
|
3
|
+
import {
|
|
4
|
+
StyleTransferProps,
|
|
5
|
+
StyleTransferType,
|
|
6
|
+
} from '../../types/styleTransfer';
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
/**
|
|
9
|
+
* React hook for managing a Style Transfer model instance.
|
|
10
|
+
*
|
|
11
|
+
* @category Hooks
|
|
12
|
+
* @param StyleTransferProps - Configuration object containing `model` source and optional `preventLoad` flag.
|
|
13
|
+
* @returns Ready to use Style Transfer model.
|
|
14
|
+
*/
|
|
15
|
+
export const useStyleTransfer = ({
|
|
16
|
+
model,
|
|
17
|
+
preventLoad = false,
|
|
18
|
+
}: StyleTransferProps): StyleTransferType =>
|
|
11
19
|
useModule({
|
|
12
20
|
module: StyleTransferModule,
|
|
13
21
|
model,
|
|
@@ -1,38 +1,21 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState } from 'react';
|
|
2
2
|
import { RnExecutorchError, parseUnknownError } from '../../errors/errorUtils';
|
|
3
3
|
import { RnExecutorchErrorCode } from '../../errors/ErrorCodes';
|
|
4
|
-
import { ResourceSource } from '../../types/common';
|
|
5
4
|
import { TextToImageModule } from '../../modules/computer_vision/TextToImageModule';
|
|
5
|
+
import { TextToImageProps, TextToImageType } from '../../types/tti';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
imageSize?: number,
|
|
15
|
-
numSteps?: number,
|
|
16
|
-
seed?: number
|
|
17
|
-
) => Promise<string>;
|
|
18
|
-
interrupt: () => void;
|
|
19
|
-
}
|
|
20
|
-
|
|
7
|
+
/**
|
|
8
|
+
* React hook for managing a Text to Image instance.
|
|
9
|
+
*
|
|
10
|
+
* @category Hooks
|
|
11
|
+
* @param TextToImageProps - Configuration object containing `model` source, `inferenceCallback`, and optional `preventLoad` flag.
|
|
12
|
+
* @returns Ready to use Text to Image model.
|
|
13
|
+
*/
|
|
21
14
|
export const useTextToImage = ({
|
|
22
15
|
model,
|
|
23
16
|
inferenceCallback,
|
|
24
17
|
preventLoad = false,
|
|
25
|
-
}: {
|
|
26
|
-
model: {
|
|
27
|
-
tokenizerSource: ResourceSource;
|
|
28
|
-
schedulerSource: ResourceSource;
|
|
29
|
-
encoderSource: ResourceSource;
|
|
30
|
-
unetSource: ResourceSource;
|
|
31
|
-
decoderSource: ResourceSource;
|
|
32
|
-
};
|
|
33
|
-
inferenceCallback?: (stepIdx: number) => void;
|
|
34
|
-
preventLoad?: boolean;
|
|
35
|
-
}): TextToImageType => {
|
|
18
|
+
}: TextToImageProps): TextToImageType => {
|
|
36
19
|
const [isReady, setIsReady] = useState(false);
|
|
37
20
|
const [isGenerating, setIsGenerating] = useState(false);
|
|
38
21
|
const [downloadProgress, setDownloadProgress] = useState(0);
|
|
@@ -1,30 +1,20 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import { OCRDetection, OCRLanguage } from '../../types/ocr';
|
|
2
|
+
import { OCRType, VerticalOCRProps } from '../../types/ocr';
|
|
4
3
|
import { VerticalOCRController } from '../../controllers/VerticalOCRController';
|
|
5
4
|
import { RnExecutorchError } from '../../errors/errorUtils';
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
/**
|
|
7
|
+
* React hook for managing a Vertical OCR instance.
|
|
8
|
+
*
|
|
9
|
+
* @category Hooks
|
|
10
|
+
* @param VerticalOCRProps - Configuration object containing `model` sources, optional `independentCharacters` and `preventLoad` flag.
|
|
11
|
+
* @returns Ready to use Vertical OCR model.
|
|
12
|
+
*/
|
|
15
13
|
export const useVerticalOCR = ({
|
|
16
14
|
model,
|
|
17
15
|
independentCharacters = false,
|
|
18
16
|
preventLoad = false,
|
|
19
|
-
}: {
|
|
20
|
-
model: {
|
|
21
|
-
detectorSource: ResourceSource;
|
|
22
|
-
recognizerSource: ResourceSource;
|
|
23
|
-
language: OCRLanguage;
|
|
24
|
-
};
|
|
25
|
-
independentCharacters?: boolean;
|
|
26
|
-
preventLoad?: boolean;
|
|
27
|
-
}): OCRModule => {
|
|
17
|
+
}: VerticalOCRProps): OCRType => {
|
|
28
18
|
const [error, setError] = useState<RnExecutorchError | null>(null);
|
|
29
19
|
const [isReady, setIsReady] = useState(false);
|
|
30
20
|
const [isGenerating, setIsGenerating] = useState(false);
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import { ExecutorchModule } from '../../modules/general/ExecutorchModule';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ExecutorchModuleProps,
|
|
4
|
+
ExecutorchModuleType,
|
|
5
|
+
} from '../../types/executorchModule';
|
|
3
6
|
import { useModule } from '../useModule';
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* React hook for managing an arbitrary Executorch module instance.
|
|
10
|
+
*
|
|
11
|
+
* @category Hooks
|
|
12
|
+
* @param executorchModuleProps - Configuration object containing `modelSource` and optional `preventLoad` flag.
|
|
13
|
+
* @returns Ready to use Executorch module.
|
|
14
|
+
*/
|
|
10
15
|
export const useExecutorchModule = ({
|
|
11
16
|
modelSource,
|
|
12
17
|
preventLoad = false,
|
|
13
|
-
}:
|
|
18
|
+
}: ExecutorchModuleProps): ExecutorchModuleType =>
|
|
14
19
|
useModule({
|
|
15
20
|
module: ExecutorchModule,
|
|
16
21
|
model: modelSource,
|
|
@@ -1,30 +1,22 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
-
import { ResourceSource } from '../../types/common';
|
|
3
2
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
LLMConfig,
|
|
4
|
+
LLMProps,
|
|
6
5
|
LLMTool,
|
|
7
6
|
LLMType,
|
|
8
7
|
Message,
|
|
9
|
-
ToolsConfig,
|
|
10
8
|
} from '../../types/llm';
|
|
11
9
|
import { LLMController } from '../../controllers/LLMController';
|
|
12
10
|
import { RnExecutorchError, parseUnknownError } from '../../errors/errorUtils';
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
modelSource: ResourceSource;
|
|
23
|
-
tokenizerSource: ResourceSource;
|
|
24
|
-
tokenizerConfigSource: ResourceSource;
|
|
25
|
-
};
|
|
26
|
-
preventLoad?: boolean;
|
|
27
|
-
}): LLMType => {
|
|
12
|
+
/**
|
|
13
|
+
* React hook for managing a Large Language Model (LLM) instance.
|
|
14
|
+
*
|
|
15
|
+
* @category Hooks
|
|
16
|
+
* @param model - Object containing model, tokenizer, and tokenizer config sources.
|
|
17
|
+
* @returns An object implementing the `LLMType` interface for interacting with the LLM.
|
|
18
|
+
*/
|
|
19
|
+
export const useLLM = ({ model, preventLoad = false }: LLMProps): LLMType => {
|
|
28
20
|
const [token, setToken] = useState<string>('');
|
|
29
21
|
const [response, setResponse] = useState<string>('');
|
|
30
22
|
const [messageHistory, setMessageHistory] = useState<Message[]>([]);
|
|
@@ -59,7 +51,7 @@ export const useLLM = ({
|
|
|
59
51
|
await controllerInstance.load({
|
|
60
52
|
modelSource: model.modelSource,
|
|
61
53
|
tokenizerSource: model.tokenizerSource,
|
|
62
|
-
tokenizerConfigSource: model.tokenizerConfigSource
|
|
54
|
+
tokenizerConfigSource: model.tokenizerConfigSource!,
|
|
63
55
|
onDownloadProgressCallback: setDownloadProgress,
|
|
64
56
|
});
|
|
65
57
|
} catch (e) {
|
|
@@ -82,15 +74,7 @@ export const useLLM = ({
|
|
|
82
74
|
|
|
83
75
|
// memoization of returned functions
|
|
84
76
|
const configure = useCallback(
|
|
85
|
-
({
|
|
86
|
-
chatConfig,
|
|
87
|
-
toolsConfig,
|
|
88
|
-
generationConfig,
|
|
89
|
-
}: {
|
|
90
|
-
chatConfig?: Partial<ChatConfig>;
|
|
91
|
-
toolsConfig?: ToolsConfig;
|
|
92
|
-
generationConfig?: GenerationConfig;
|
|
93
|
-
}) =>
|
|
77
|
+
({ chatConfig, toolsConfig, generationConfig }: LLMConfig) =>
|
|
94
78
|
controllerInstance.configure({
|
|
95
79
|
chatConfig,
|
|
96
80
|
toolsConfig,
|
|
@@ -130,6 +114,16 @@ export const useLLM = ({
|
|
|
130
114
|
[controllerInstance]
|
|
131
115
|
);
|
|
132
116
|
|
|
117
|
+
const getPromptTokenCount = useCallback(
|
|
118
|
+
() => controllerInstance.getPromptTokenCount(),
|
|
119
|
+
[controllerInstance]
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
const getTotalTokenCount = useCallback(
|
|
123
|
+
() => controllerInstance.getTotalTokenCount(),
|
|
124
|
+
[controllerInstance]
|
|
125
|
+
);
|
|
126
|
+
|
|
133
127
|
return {
|
|
134
128
|
messageHistory,
|
|
135
129
|
response,
|
|
@@ -139,6 +133,8 @@ export const useLLM = ({
|
|
|
139
133
|
downloadProgress,
|
|
140
134
|
error,
|
|
141
135
|
getGeneratedTokenCount: getGeneratedTokenCount,
|
|
136
|
+
getPromptTokenCount: getPromptTokenCount,
|
|
137
|
+
getTotalTokenCount: getTotalTokenCount,
|
|
142
138
|
configure: configure,
|
|
143
139
|
generate: generate,
|
|
144
140
|
sendMessage: sendMessage,
|