react-native-executorch 0.3.2 → 0.4.1
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 +30 -13
- package/android/build.gradle +1 -1
- package/android/libs/executorch.aar +0 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/ETModule.kt +1 -2
- package/android/src/main/java/com/swmansion/rnexecutorch/ImageSegmentation.kt +58 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/LLM.kt +13 -49
- package/android/src/main/java/com/swmansion/rnexecutorch/RnExecutorchPackage.kt +37 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/StyleTransfer.kt +1 -1
- package/android/src/main/java/com/swmansion/rnexecutorch/TextEmbeddings.kt +51 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/Tokenizer.kt +86 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/models/BaseModel.kt +3 -4
- package/android/src/main/java/com/swmansion/rnexecutorch/models/TextEmbeddings/TextEmbeddingsModel.kt +48 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/models/TextEmbeddings/TextEmbeddingsUtils.kt +37 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/models/classification/ClassificationModel.kt +1 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/models/imageSegmentation/Constants.kt +26 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/models/imageSegmentation/ImageSegmentationModel.kt +142 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/models/ocr/utils/RecognizerUtils.kt +3 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/models/{StyleTransferModel.kt → styleTransfer/StyleTransferModel.kt} +2 -1
- package/android/src/main/java/com/swmansion/rnexecutorch/utils/ArrayUtils.kt +0 -8
- package/android/src/main/java/com/swmansion/rnexecutorch/{models/classification/Utils.kt → utils/Numerical.kt} +1 -1
- package/ios/ExecutorchLib.xcframework/Info.plist +4 -4
- package/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/ExecutorchLib +0 -0
- package/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Headers/HuggingFaceTokenizer.h +14 -0
- package/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Headers/LLaMARunner.h +1 -23
- package/ios/ExecutorchLib.xcframework/ios-arm64/ExecutorchLib.framework/Info.plist +0 -0
- package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/ExecutorchLib +0 -0
- package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Headers/HuggingFaceTokenizer.h +14 -0
- package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Headers/LLaMARunner.h +1 -23
- package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/Info.plist +0 -0
- package/ios/RnExecutorch/Classification.mm +15 -18
- package/ios/RnExecutorch/ETModule.mm +6 -5
- package/ios/RnExecutorch/ImageSegmentation.h +5 -0
- package/ios/RnExecutorch/ImageSegmentation.mm +60 -0
- package/ios/RnExecutorch/LLM.mm +12 -53
- package/ios/RnExecutorch/OCR.mm +39 -43
- package/ios/RnExecutorch/ObjectDetection.mm +20 -20
- package/ios/RnExecutorch/SpeechToText.mm +6 -7
- package/ios/RnExecutorch/StyleTransfer.mm +16 -19
- package/ios/RnExecutorch/TextEmbeddings.h +5 -0
- package/ios/RnExecutorch/TextEmbeddings.mm +62 -0
- package/ios/RnExecutorch/Tokenizer.h +5 -0
- package/ios/RnExecutorch/Tokenizer.mm +83 -0
- package/ios/RnExecutorch/VerticalOCR.mm +36 -36
- package/ios/RnExecutorch/models/BaseModel.h +2 -5
- package/ios/RnExecutorch/models/BaseModel.mm +5 -15
- package/ios/RnExecutorch/models/classification/ClassificationModel.mm +2 -3
- package/ios/RnExecutorch/models/classification/Constants.mm +0 -1
- package/ios/RnExecutorch/models/image_segmentation/Constants.h +4 -0
- package/ios/RnExecutorch/models/image_segmentation/Constants.mm +8 -0
- package/ios/RnExecutorch/models/image_segmentation/ImageSegmentationModel.h +10 -0
- package/ios/RnExecutorch/models/image_segmentation/ImageSegmentationModel.mm +146 -0
- package/ios/RnExecutorch/models/object_detection/SSDLiteLargeModel.mm +1 -2
- package/ios/RnExecutorch/models/ocr/Detector.h +0 -2
- package/ios/RnExecutorch/models/ocr/Detector.mm +2 -1
- package/ios/RnExecutorch/models/ocr/RecognitionHandler.h +5 -4
- package/ios/RnExecutorch/models/ocr/RecognitionHandler.mm +9 -26
- package/ios/RnExecutorch/models/ocr/Recognizer.mm +1 -2
- package/ios/RnExecutorch/models/ocr/VerticalDetector.h +0 -2
- package/ios/RnExecutorch/models/ocr/VerticalDetector.mm +2 -1
- package/ios/RnExecutorch/models/ocr/utils/OCRUtils.mm +0 -1
- package/ios/RnExecutorch/models/stt/Moonshine.mm +1 -6
- package/ios/RnExecutorch/models/stt/SpeechToTextBaseModel.mm +7 -11
- package/ios/RnExecutorch/models/stt/Whisper.mm +0 -5
- package/ios/RnExecutorch/models/{StyleTransferModel.h → style_transfer/StyleTransferModel.h} +1 -1
- package/ios/RnExecutorch/models/{StyleTransferModel.mm → style_transfer/StyleTransferModel.mm} +2 -3
- package/ios/RnExecutorch/models/text_embeddings/TextEmbeddingsModel.h +15 -0
- package/ios/RnExecutorch/models/text_embeddings/TextEmbeddingsModel.mm +45 -0
- package/ios/RnExecutorch/models/text_embeddings/TextEmbeddingsUtils.h +8 -0
- package/ios/RnExecutorch/models/text_embeddings/TextEmbeddingsUtils.mm +49 -0
- package/ios/RnExecutorch/utils/Conversions.h +15 -0
- package/ios/RnExecutorch/utils/ImageProcessor.h +0 -1
- package/ios/RnExecutorch/{models/classification/Utils.h → utils/Numerical.h} +0 -2
- package/ios/RnExecutorch/{models/classification/Utils.mm → utils/Numerical.mm} +0 -2
- package/ios/RnExecutorch/utils/ObjectDetectionUtils.mm +0 -2
- package/ios/RnExecutorch/utils/SFFT.mm +1 -1
- package/ios/RnExecutorch/utils/ScalarType.h +0 -2
- package/lib/module/Error.js +16 -2
- package/lib/module/Error.js.map +1 -1
- package/lib/module/constants/{llamaDefaults.js → llmDefaults.js} +7 -3
- package/lib/module/constants/llmDefaults.js.map +1 -0
- package/lib/module/constants/modelUrls.js +88 -27
- package/lib/module/constants/modelUrls.js.map +1 -1
- package/lib/module/constants/ocr/models.js +290 -0
- package/lib/module/constants/ocr/models.js.map +1 -0
- package/lib/module/constants/ocr/symbols.js +137 -2
- package/lib/module/constants/ocr/symbols.js.map +1 -1
- package/lib/module/constants/sttDefaults.js +50 -25
- package/lib/module/constants/sttDefaults.js.map +1 -1
- package/lib/module/controllers/LLMController.js +205 -0
- package/lib/module/controllers/LLMController.js.map +1 -0
- package/lib/module/controllers/OCRController.js +5 -10
- package/lib/module/controllers/OCRController.js.map +1 -1
- package/lib/module/controllers/SpeechToTextController.js +225 -122
- package/lib/module/controllers/SpeechToTextController.js.map +1 -1
- package/lib/module/controllers/VerticalOCRController.js +6 -10
- package/lib/module/controllers/VerticalOCRController.js.map +1 -1
- package/lib/module/hooks/computer_vision/useClassification.js +8 -23
- package/lib/module/hooks/computer_vision/useClassification.js.map +1 -1
- package/lib/module/hooks/computer_vision/useImageSegmentation.js +13 -0
- package/lib/module/hooks/computer_vision/useImageSegmentation.js.map +1 -0
- package/lib/module/hooks/computer_vision/useOCR.js +11 -6
- package/lib/module/hooks/computer_vision/useOCR.js.map +1 -1
- package/lib/module/hooks/computer_vision/useObjectDetection.js +8 -23
- package/lib/module/hooks/computer_vision/useObjectDetection.js.map +1 -1
- package/lib/module/hooks/computer_vision/useStyleTransfer.js +8 -23
- package/lib/module/hooks/computer_vision/useStyleTransfer.js.map +1 -1
- package/lib/module/hooks/computer_vision/useVerticalOCR.js +10 -7
- package/lib/module/hooks/computer_vision/useVerticalOCR.js.map +1 -1
- package/lib/module/hooks/general/useExecutorchModule.js +8 -36
- package/lib/module/hooks/general/useExecutorchModule.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useLLM.js +54 -63
- package/lib/module/hooks/natural_language_processing/useLLM.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useSpeechToText.js +15 -11
- package/lib/module/hooks/natural_language_processing/useSpeechToText.js.map +1 -1
- package/lib/module/hooks/natural_language_processing/useTextEmbeddings.js +14 -0
- package/lib/module/hooks/natural_language_processing/useTextEmbeddings.js.map +1 -0
- package/lib/module/hooks/natural_language_processing/useTokenizer.js +54 -0
- package/lib/module/hooks/natural_language_processing/useTokenizer.js.map +1 -0
- package/lib/module/hooks/useModule.js +18 -62
- package/lib/module/hooks/useModule.js.map +1 -1
- package/lib/module/index.js +16 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/modules/BaseModule.js +9 -10
- package/lib/module/modules/BaseModule.js.map +1 -1
- package/lib/module/modules/computer_vision/ClassificationModule.js +8 -5
- package/lib/module/modules/computer_vision/ClassificationModule.js.map +1 -1
- package/lib/module/modules/computer_vision/ImageSegmentationModule.js +28 -0
- package/lib/module/modules/computer_vision/ImageSegmentationModule.js.map +1 -0
- package/lib/module/modules/computer_vision/ObjectDetectionModule.js +8 -5
- package/lib/module/modules/computer_vision/ObjectDetectionModule.js.map +1 -1
- package/lib/module/modules/computer_vision/StyleTransferModule.js +8 -5
- package/lib/module/modules/computer_vision/StyleTransferModule.js.map +1 -1
- package/lib/module/modules/general/ExecutorchModule.js +8 -5
- package/lib/module/modules/general/ExecutorchModule.js.map +1 -1
- package/lib/module/modules/natural_language_processing/LLMModule.js +46 -27
- package/lib/module/modules/natural_language_processing/LLMModule.js.map +1 -1
- package/lib/module/modules/natural_language_processing/SpeechToTextModule.js +8 -5
- package/lib/module/modules/natural_language_processing/SpeechToTextModule.js.map +1 -1
- package/lib/module/modules/natural_language_processing/TextEmbeddingsModule.js +14 -0
- package/lib/module/modules/natural_language_processing/TextEmbeddingsModule.js.map +1 -0
- package/lib/module/modules/natural_language_processing/TokenizerModule.js +26 -0
- package/lib/module/modules/natural_language_processing/TokenizerModule.js.map +1 -0
- package/lib/module/native/NativeClassification.js.map +1 -1
- package/lib/module/native/NativeImageSegmentation.js +5 -0
- package/lib/module/native/NativeImageSegmentation.js.map +1 -0
- package/lib/module/native/NativeLLM.js.map +1 -1
- package/lib/module/native/NativeTextEmbeddings.js +5 -0
- package/lib/module/native/NativeTextEmbeddings.js.map +1 -0
- package/lib/module/native/NativeTokenizer.js +5 -0
- package/lib/module/native/NativeTokenizer.js.map +1 -0
- package/lib/module/native/RnExecutorchModules.js +18 -113
- package/lib/module/native/RnExecutorchModules.js.map +1 -1
- package/lib/module/types/common.js.map +1 -1
- package/lib/module/types/imageSegmentation.js +29 -0
- package/lib/module/types/imageSegmentation.js.map +1 -0
- package/lib/module/types/llm.js +7 -0
- package/lib/module/types/llm.js.map +1 -0
- package/lib/module/types/{object_detection.js → objectDetection.js} +1 -1
- package/lib/module/types/objectDetection.js.map +1 -0
- package/lib/module/types/ocr.js +2 -0
- package/lib/module/types/stt.js +82 -0
- package/lib/module/types/stt.js.map +1 -0
- package/lib/module/utils/ResourceFetcher.js +156 -0
- package/lib/module/utils/ResourceFetcher.js.map +1 -0
- package/lib/module/utils/llm.js +25 -0
- package/lib/module/utils/llm.js.map +1 -0
- package/lib/module/utils/stt.js +22 -0
- package/lib/module/utils/stt.js.map +1 -0
- package/lib/typescript/Error.d.ts +4 -1
- package/lib/typescript/Error.d.ts.map +1 -1
- package/lib/typescript/constants/{llamaDefaults.d.ts → llmDefaults.d.ts} +5 -5
- package/lib/typescript/constants/llmDefaults.d.ts.map +1 -0
- package/lib/typescript/constants/modelUrls.d.ts +74 -28
- package/lib/typescript/constants/modelUrls.d.ts.map +1 -1
- package/lib/typescript/constants/ocr/models.d.ts +285 -0
- package/lib/typescript/constants/ocr/models.d.ts.map +1 -0
- package/lib/typescript/constants/ocr/symbols.d.ts +73 -1
- package/lib/typescript/constants/ocr/symbols.d.ts.map +1 -1
- package/lib/typescript/constants/sttDefaults.d.ts +8 -13
- package/lib/typescript/constants/sttDefaults.d.ts.map +1 -1
- package/lib/typescript/controllers/LLMController.d.ts +46 -0
- package/lib/typescript/controllers/LLMController.d.ts.map +1 -0
- package/lib/typescript/controllers/OCRController.d.ts.map +1 -1
- package/lib/typescript/controllers/SpeechToTextController.d.ts +30 -16
- package/lib/typescript/controllers/SpeechToTextController.d.ts.map +1 -1
- package/lib/typescript/controllers/VerticalOCRController.d.ts +1 -1
- package/lib/typescript/controllers/VerticalOCRController.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useClassification.d.ts +5 -5
- package/lib/typescript/hooks/computer_vision/useClassification.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useImageSegmentation.d.ts +37 -0
- package/lib/typescript/hooks/computer_vision/useImageSegmentation.d.ts.map +1 -0
- package/lib/typescript/hooks/computer_vision/useOCR.d.ts +2 -1
- package/lib/typescript/hooks/computer_vision/useOCR.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useObjectDetection.d.ts +5 -4
- package/lib/typescript/hooks/computer_vision/useObjectDetection.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useStyleTransfer.d.ts +4 -2
- package/lib/typescript/hooks/computer_vision/useStyleTransfer.d.ts.map +1 -1
- package/lib/typescript/hooks/computer_vision/useVerticalOCR.d.ts +2 -1
- package/lib/typescript/hooks/computer_vision/useVerticalOCR.d.ts.map +1 -1
- package/lib/typescript/hooks/general/useExecutorchModule.d.ts +5 -6
- package/lib/typescript/hooks/general/useExecutorchModule.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts +6 -6
- package/lib/typescript/hooks/natural_language_processing/useLLM.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts +7 -3
- package/lib/typescript/hooks/natural_language_processing/useSpeechToText.d.ts.map +1 -1
- package/lib/typescript/hooks/natural_language_processing/useTextEmbeddings.d.ts +13 -0
- package/lib/typescript/hooks/natural_language_processing/useTextEmbeddings.d.ts.map +1 -0
- package/lib/typescript/hooks/natural_language_processing/useTokenizer.d.ts +16 -0
- package/lib/typescript/hooks/natural_language_processing/useTokenizer.d.ts.map +1 -0
- package/lib/typescript/hooks/useModule.d.ts +11 -10
- package/lib/typescript/hooks/useModule.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +15 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/modules/BaseModule.d.ts +4 -5
- package/lib/typescript/modules/BaseModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/ClassificationModule.d.ts +7 -7
- package/lib/typescript/modules/computer_vision/ClassificationModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/ImageSegmentationModule.d.ts +32 -0
- package/lib/typescript/modules/computer_vision/ImageSegmentationModule.d.ts.map +1 -0
- package/lib/typescript/modules/computer_vision/OCRModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/ObjectDetectionModule.d.ts +6 -5
- package/lib/typescript/modules/computer_vision/ObjectDetectionModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/StyleTransferModule.d.ts +6 -5
- package/lib/typescript/modules/computer_vision/StyleTransferModule.d.ts.map +1 -1
- package/lib/typescript/modules/computer_vision/VerticalOCRModule.d.ts.map +1 -1
- package/lib/typescript/modules/general/ExecutorchModule.d.ts +4 -3
- package/lib/typescript/modules/general/ExecutorchModule.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts +19 -5
- package/lib/typescript/modules/natural_language_processing/LLMModule.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts +7 -4
- package/lib/typescript/modules/natural_language_processing/SpeechToTextModule.d.ts.map +1 -1
- package/lib/typescript/modules/natural_language_processing/TextEmbeddingsModule.d.ts +8 -0
- package/lib/typescript/modules/natural_language_processing/TextEmbeddingsModule.d.ts.map +1 -0
- package/lib/typescript/modules/natural_language_processing/TokenizerModule.d.ts +12 -0
- package/lib/typescript/modules/natural_language_processing/TokenizerModule.d.ts.map +1 -0
- package/lib/typescript/native/NativeClassification.d.ts.map +1 -1
- package/lib/typescript/native/NativeImageSegmentation.d.ts +10 -0
- package/lib/typescript/native/NativeImageSegmentation.d.ts.map +1 -0
- package/lib/typescript/native/NativeLLM.d.ts +3 -4
- package/lib/typescript/native/NativeLLM.d.ts.map +1 -1
- package/lib/typescript/native/NativeObjectDetection.d.ts +1 -1
- package/lib/typescript/native/NativeObjectDetection.d.ts.map +1 -1
- package/lib/typescript/native/NativeSpeechToText.d.ts +2 -2
- package/lib/typescript/native/NativeSpeechToText.d.ts.map +1 -1
- package/lib/typescript/native/NativeTextEmbeddings.d.ts +8 -0
- package/lib/typescript/native/NativeTextEmbeddings.d.ts.map +1 -0
- package/lib/typescript/native/NativeTokenizer.d.ts +12 -0
- package/lib/typescript/native/NativeTokenizer.d.ts.map +1 -0
- package/lib/typescript/native/RnExecutorchModules.d.ts +18 -41
- package/lib/typescript/native/RnExecutorchModules.d.ts.map +1 -1
- package/lib/typescript/types/common.d.ts +1 -26
- package/lib/typescript/types/common.d.ts.map +1 -1
- package/lib/typescript/types/imageSegmentation.d.ts +25 -0
- package/lib/typescript/types/imageSegmentation.d.ts.map +1 -0
- package/lib/typescript/types/llm.d.ts +38 -0
- package/lib/typescript/types/llm.d.ts.map +1 -0
- package/lib/typescript/types/{object_detection.d.ts → objectDetection.d.ts} +1 -1
- package/lib/typescript/types/objectDetection.d.ts.map +1 -0
- package/lib/typescript/types/ocr.d.ts +2 -1
- package/lib/typescript/types/ocr.d.ts.map +1 -1
- package/lib/typescript/types/stt.d.ts +91 -0
- package/lib/typescript/types/stt.d.ts.map +1 -0
- package/lib/typescript/utils/ResourceFetcher.d.ts +17 -0
- package/lib/typescript/utils/ResourceFetcher.d.ts.map +1 -0
- package/lib/typescript/utils/llm.d.ts +3 -0
- package/lib/typescript/utils/llm.d.ts.map +1 -0
- package/lib/typescript/utils/stt.d.ts +2 -0
- package/lib/typescript/utils/stt.d.ts.map +1 -0
- package/package.json +12 -48
- package/react-native-executorch.podspec +1 -1
- package/src/Error.ts +16 -3
- package/src/constants/llmDefaults.ts +14 -0
- package/src/constants/modelUrls.ts +146 -39
- package/src/constants/ocr/models.ts +453 -0
- package/src/constants/ocr/symbols.ts +147 -3
- package/src/constants/sttDefaults.ts +55 -37
- package/src/controllers/LLMController.ts +286 -0
- package/src/controllers/OCRController.ts +14 -28
- package/src/controllers/SpeechToTextController.ts +318 -180
- package/src/controllers/VerticalOCRController.ts +17 -32
- package/src/hooks/computer_vision/useClassification.ts +11 -26
- package/src/hooks/computer_vision/useImageSegmentation.ts +18 -0
- package/src/hooks/computer_vision/useOCR.ts +17 -5
- package/src/hooks/computer_vision/useObjectDetection.ts +10 -24
- package/src/hooks/computer_vision/useStyleTransfer.ts +9 -25
- package/src/hooks/computer_vision/useVerticalOCR.ts +11 -4
- package/src/hooks/general/useExecutorchModule.ts +10 -50
- package/src/hooks/natural_language_processing/useLLM.ts +80 -97
- package/src/hooks/natural_language_processing/useSpeechToText.ts +39 -12
- package/src/hooks/natural_language_processing/useTextEmbeddings.ts +18 -0
- package/src/hooks/natural_language_processing/useTokenizer.ts +61 -0
- package/src/hooks/useModule.ts +32 -92
- package/src/index.tsx +16 -2
- package/src/modules/BaseModule.ts +16 -26
- package/src/modules/computer_vision/ClassificationModule.ts +13 -8
- package/src/modules/computer_vision/ImageSegmentationModule.ts +39 -0
- package/src/modules/computer_vision/ObjectDetectionModule.ts +13 -8
- package/src/modules/computer_vision/StyleTransferModule.ts +13 -8
- package/src/modules/general/ExecutorchModule.ts +11 -6
- package/src/modules/natural_language_processing/LLMModule.ts +64 -51
- package/src/modules/natural_language_processing/SpeechToTextModule.ts +25 -10
- package/src/modules/natural_language_processing/TextEmbeddingsModule.ts +18 -0
- package/src/modules/natural_language_processing/TokenizerModule.ts +34 -0
- package/src/native/NativeClassification.ts +0 -1
- package/src/native/NativeImageSegmentation.ts +14 -0
- package/src/native/NativeLLM.ts +3 -10
- package/src/native/NativeObjectDetection.ts +1 -1
- package/src/native/NativeSpeechToText.ts +2 -2
- package/src/native/NativeTextEmbeddings.ts +9 -0
- package/src/native/NativeTokenizer.ts +13 -0
- package/src/native/RnExecutorchModules.ts +54 -234
- package/src/types/common.ts +1 -44
- package/src/types/imageSegmentation.ts +25 -0
- package/src/types/llm.ts +57 -0
- package/src/types/ocr.ts +3 -1
- package/src/types/stt.ts +93 -0
- package/src/utils/ResourceFetcher.ts +196 -0
- package/src/utils/llm.ts +34 -0
- package/src/utils/stt.ts +28 -0
- package/android/src/main/java/com/swmansion/rnexecutorch/utils/llms/ConversationManager.kt +0 -68
- package/ios/ExecutorchLib.xcframework/ios-arm64-simulator/ExecutorchLib.framework/_CodeSignature/CodeResources +0 -124
- package/ios/RnExecutorch/utils/llms/Constants.h +0 -6
- package/ios/RnExecutorch/utils/llms/Constants.mm +0 -23
- package/ios/RnExecutorch/utils/llms/ConversationManager.h +0 -26
- package/ios/RnExecutorch/utils/llms/ConversationManager.mm +0 -71
- package/lib/module/constants/llamaDefaults.js.map +0 -1
- package/lib/module/modules/computer_vision/BaseCVModule.js +0 -14
- package/lib/module/modules/computer_vision/BaseCVModule.js.map +0 -1
- package/lib/module/types/object_detection.js.map +0 -1
- package/lib/module/utils/fetchResource.js +0 -93
- package/lib/module/utils/fetchResource.js.map +0 -1
- package/lib/module/utils/listDownloadedResources.js +0 -13
- package/lib/module/utils/listDownloadedResources.js.map +0 -1
- package/lib/typescript/constants/llamaDefaults.d.ts.map +0 -1
- package/lib/typescript/modules/computer_vision/BaseCVModule.d.ts +0 -9
- package/lib/typescript/modules/computer_vision/BaseCVModule.d.ts.map +0 -1
- package/lib/typescript/types/object_detection.d.ts.map +0 -1
- package/lib/typescript/utils/fetchResource.d.ts +0 -3
- package/lib/typescript/utils/fetchResource.d.ts.map +0 -1
- package/lib/typescript/utils/listDownloadedResources.d.ts +0 -3
- package/lib/typescript/utils/listDownloadedResources.d.ts.map +0 -1
- package/src/constants/llamaDefaults.ts +0 -9
- package/src/modules/computer_vision/BaseCVModule.ts +0 -22
- package/src/utils/fetchResource.ts +0 -106
- package/src/utils/listDownloadedResources.ts +0 -12
- /package/src/types/{object_detection.ts → objectDetection.ts} +0 -0
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { symbols } from '../constants/ocr/symbols';
|
|
2
2
|
import { ETError, getError } from '../Error';
|
|
3
|
-
import {
|
|
3
|
+
import { VerticalOCRNativeModule } from '../native/RnExecutorchModules';
|
|
4
4
|
import { ResourceSource } from '../types/common';
|
|
5
5
|
import { OCRLanguage } from '../types/ocr';
|
|
6
|
-
import {
|
|
7
|
-
fetchResource,
|
|
8
|
-
calculateDownloadProgres,
|
|
9
|
-
} from '../utils/fetchResource';
|
|
6
|
+
import { ResourceFetcher } from '../utils/ResourceFetcher';
|
|
10
7
|
|
|
11
8
|
export class VerticalOCRController {
|
|
12
|
-
private
|
|
9
|
+
private ocrNativeModule: typeof VerticalOCRNativeModule;
|
|
13
10
|
public isReady: boolean = false;
|
|
14
11
|
public isGenerating: boolean = false;
|
|
15
12
|
public error: string | null = null;
|
|
@@ -24,7 +21,7 @@ export class VerticalOCRController {
|
|
|
24
21
|
isGeneratingCallback = (_isGenerating: boolean) => {},
|
|
25
22
|
errorCallback = (_error: string) => {},
|
|
26
23
|
}) {
|
|
27
|
-
this.
|
|
24
|
+
this.ocrNativeModule = VerticalOCRNativeModule;
|
|
28
25
|
this.modelDownloadProgressCallback = modelDownloadProgressCallback;
|
|
29
26
|
this.isReadyCallback = isReadyCallback;
|
|
30
27
|
this.isGeneratingCallback = isGeneratingCallback;
|
|
@@ -57,31 +54,19 @@ export class VerticalOCRController {
|
|
|
57
54
|
this.isReady = false;
|
|
58
55
|
this.isReadyCallback(this.isReady);
|
|
59
56
|
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
const detectorPaths = {
|
|
71
|
-
detectorLarge: await fetchResource(
|
|
72
|
-
detectorSources.detectorLarge,
|
|
73
|
-
calculateDownloadProgres(3, 1, this.modelDownloadProgressCallback)
|
|
74
|
-
),
|
|
75
|
-
detectorNarrow: await fetchResource(
|
|
76
|
-
detectorSources.detectorNarrow,
|
|
77
|
-
calculateDownloadProgres(3, 2, this.modelDownloadProgressCallback)
|
|
78
|
-
),
|
|
79
|
-
};
|
|
57
|
+
const paths = await ResourceFetcher.fetchMultipleResources(
|
|
58
|
+
this.modelDownloadProgressCallback,
|
|
59
|
+
detectorSources.detectorLarge,
|
|
60
|
+
detectorSources.detectorNarrow,
|
|
61
|
+
independentCharacters
|
|
62
|
+
? recognizerSources.recognizerSmall
|
|
63
|
+
: recognizerSources.recognizerLarge
|
|
64
|
+
);
|
|
80
65
|
|
|
81
|
-
await this.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
66
|
+
await this.ocrNativeModule.loadModule(
|
|
67
|
+
paths[0]!,
|
|
68
|
+
paths[1]!,
|
|
69
|
+
paths[2]!,
|
|
85
70
|
symbols[language],
|
|
86
71
|
independentCharacters
|
|
87
72
|
);
|
|
@@ -108,7 +93,7 @@ export class VerticalOCRController {
|
|
|
108
93
|
try {
|
|
109
94
|
this.isGenerating = true;
|
|
110
95
|
this.isGeneratingCallback(this.isGenerating);
|
|
111
|
-
return await this.
|
|
96
|
+
return await this.ocrNativeModule.forward(input);
|
|
112
97
|
} catch (e) {
|
|
113
98
|
throw new Error(getError(e));
|
|
114
99
|
} finally {
|
|
@@ -1,31 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ClassificationModule } from '../../modules/computer_vision/ClassificationModule';
|
|
2
|
+
import { ResourceSource } from '../../types/common';
|
|
3
3
|
import { useModule } from '../useModule';
|
|
4
4
|
|
|
5
|
-
interface Props {
|
|
6
|
-
modelSource: string | number;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
5
|
export const useClassification = ({
|
|
10
6
|
modelSource,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
error,
|
|
21
|
-
isReady,
|
|
22
|
-
isGenerating,
|
|
23
|
-
downloadProgress,
|
|
24
|
-
forwardImage: forward,
|
|
25
|
-
} = useModule({
|
|
26
|
-
modelSource,
|
|
27
|
-
module,
|
|
7
|
+
preventLoad = false,
|
|
8
|
+
}: {
|
|
9
|
+
modelSource: ResourceSource;
|
|
10
|
+
preventLoad?: boolean;
|
|
11
|
+
}) =>
|
|
12
|
+
useModule({
|
|
13
|
+
module: ClassificationModule,
|
|
14
|
+
loadArgs: [modelSource],
|
|
15
|
+
preventLoad,
|
|
28
16
|
});
|
|
29
|
-
|
|
30
|
-
return { error, isReady, isGenerating, downloadProgress, forward };
|
|
31
|
-
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useModule } from '../useModule';
|
|
2
|
+
import { ImageSegmentationModule } from '../../modules/computer_vision/ImageSegmentationModule';
|
|
3
|
+
import { ResourceSource } from '../../types/common';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
modelSource: ResourceSource;
|
|
7
|
+
preventLoad?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const useImageSegmentation = ({
|
|
11
|
+
modelSource,
|
|
12
|
+
preventLoad = false,
|
|
13
|
+
}: Props) =>
|
|
14
|
+
useModule({
|
|
15
|
+
module: ImageSegmentationModule,
|
|
16
|
+
loadArgs: [modelSource],
|
|
17
|
+
preventLoad,
|
|
18
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import { ResourceSource } from '../../types/common';
|
|
3
3
|
import { OCRDetection, OCRLanguage } from '../../types/ocr';
|
|
4
4
|
import { OCRController } from '../../controllers/OCRController';
|
|
@@ -15,6 +15,7 @@ export const useOCR = ({
|
|
|
15
15
|
detectorSource,
|
|
16
16
|
recognizerSources,
|
|
17
17
|
language = 'en',
|
|
18
|
+
preventLoad = false,
|
|
18
19
|
}: {
|
|
19
20
|
detectorSource: ResourceSource;
|
|
20
21
|
recognizerSources: {
|
|
@@ -23,20 +24,22 @@ export const useOCR = ({
|
|
|
23
24
|
recognizerSmall: ResourceSource;
|
|
24
25
|
};
|
|
25
26
|
language?: OCRLanguage;
|
|
27
|
+
preventLoad?: boolean;
|
|
26
28
|
}): OCRModule => {
|
|
27
29
|
const [error, setError] = useState<string | null>(null);
|
|
28
30
|
const [isReady, setIsReady] = useState(false);
|
|
29
31
|
const [isGenerating, setIsGenerating] = useState(false);
|
|
30
32
|
const [downloadProgress, setDownloadProgress] = useState(0);
|
|
31
33
|
|
|
32
|
-
const
|
|
34
|
+
const model = useMemo(
|
|
33
35
|
() =>
|
|
34
36
|
new OCRController({
|
|
35
37
|
modelDownloadProgressCallback: setDownloadProgress,
|
|
36
38
|
isReadyCallback: setIsReady,
|
|
37
39
|
isGeneratingCallback: setIsGenerating,
|
|
38
40
|
errorCallback: setError,
|
|
39
|
-
})
|
|
41
|
+
}),
|
|
42
|
+
[]
|
|
40
43
|
);
|
|
41
44
|
|
|
42
45
|
useEffect(() => {
|
|
@@ -44,9 +47,18 @@ export const useOCR = ({
|
|
|
44
47
|
await model.loadModel(detectorSource, recognizerSources, language);
|
|
45
48
|
};
|
|
46
49
|
|
|
47
|
-
|
|
50
|
+
if (!preventLoad) {
|
|
51
|
+
loadModel();
|
|
52
|
+
}
|
|
48
53
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
49
|
-
}, [
|
|
54
|
+
}, [
|
|
55
|
+
model,
|
|
56
|
+
detectorSource,
|
|
57
|
+
language,
|
|
58
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
59
|
+
JSON.stringify(recognizerSources),
|
|
60
|
+
preventLoad,
|
|
61
|
+
]);
|
|
50
62
|
|
|
51
63
|
return {
|
|
52
64
|
error,
|
|
@@ -1,32 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { _ObjectDetectionModule } from '../../native/RnExecutorchModules';
|
|
1
|
+
import { ResourceSource } from '../../types/common';
|
|
3
2
|
import { useModule } from '../useModule';
|
|
4
|
-
import {
|
|
3
|
+
import { ObjectDetectionModule } from '../../modules/computer_vision/ObjectDetectionModule';
|
|
5
4
|
|
|
6
5
|
interface Props {
|
|
7
|
-
modelSource:
|
|
6
|
+
modelSource: ResourceSource;
|
|
7
|
+
preventLoad?: boolean;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export const useObjectDetection = ({
|
|
11
11
|
modelSource,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} => {
|
|
19
|
-
const [module, _] = useState(() => new _ObjectDetectionModule());
|
|
20
|
-
const {
|
|
21
|
-
error,
|
|
22
|
-
isReady,
|
|
23
|
-
isGenerating,
|
|
24
|
-
downloadProgress,
|
|
25
|
-
forwardImage: forward,
|
|
26
|
-
} = useModule({
|
|
27
|
-
modelSource,
|
|
28
|
-
module,
|
|
12
|
+
preventLoad = false,
|
|
13
|
+
}: Props) =>
|
|
14
|
+
useModule({
|
|
15
|
+
module: ObjectDetectionModule,
|
|
16
|
+
loadArgs: [modelSource],
|
|
17
|
+
preventLoad,
|
|
29
18
|
});
|
|
30
|
-
|
|
31
|
-
return { error, isReady, isGenerating, downloadProgress, forward };
|
|
32
|
-
};
|
|
@@ -1,31 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { _StyleTransferModule } from '../../native/RnExecutorchModules';
|
|
1
|
+
import { ResourceSource } from '../../types/common';
|
|
3
2
|
import { useModule } from '../useModule';
|
|
3
|
+
import { StyleTransferModule } from '../../modules/computer_vision/StyleTransferModule';
|
|
4
4
|
|
|
5
5
|
interface Props {
|
|
6
|
-
modelSource:
|
|
6
|
+
modelSource: ResourceSource;
|
|
7
|
+
preventLoad?: boolean;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
export const useStyleTransfer = ({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
isGenerating: boolean;
|
|
15
|
-
downloadProgress: number;
|
|
16
|
-
forward: (input: string) => Promise<string>;
|
|
17
|
-
} => {
|
|
18
|
-
const [module, _] = useState(() => new _StyleTransferModule());
|
|
19
|
-
const {
|
|
20
|
-
error,
|
|
21
|
-
isReady,
|
|
22
|
-
isGenerating,
|
|
23
|
-
downloadProgress,
|
|
24
|
-
forwardImage: forward,
|
|
25
|
-
} = useModule({
|
|
26
|
-
modelSource,
|
|
27
|
-
module,
|
|
10
|
+
export const useStyleTransfer = ({ modelSource, preventLoad = false }: Props) =>
|
|
11
|
+
useModule({
|
|
12
|
+
module: StyleTransferModule,
|
|
13
|
+
loadArgs: [modelSource],
|
|
14
|
+
preventLoad,
|
|
28
15
|
});
|
|
29
|
-
|
|
30
|
-
return { error, isReady, isGenerating, downloadProgress, forward };
|
|
31
|
-
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import { ResourceSource } from '../../types/common';
|
|
3
3
|
import { OCRDetection, OCRLanguage } from '../../types/ocr';
|
|
4
4
|
import { VerticalOCRController } from '../../controllers/VerticalOCRController';
|
|
@@ -16,6 +16,7 @@ export const useVerticalOCR = ({
|
|
|
16
16
|
recognizerSources,
|
|
17
17
|
language = 'en',
|
|
18
18
|
independentCharacters = false,
|
|
19
|
+
preventLoad = false,
|
|
19
20
|
}: {
|
|
20
21
|
detectorSources: {
|
|
21
22
|
detectorLarge: ResourceSource;
|
|
@@ -27,20 +28,22 @@ export const useVerticalOCR = ({
|
|
|
27
28
|
};
|
|
28
29
|
language?: OCRLanguage;
|
|
29
30
|
independentCharacters?: boolean;
|
|
31
|
+
preventLoad?: boolean;
|
|
30
32
|
}): OCRModule => {
|
|
31
33
|
const [error, setError] = useState<string | null>(null);
|
|
32
34
|
const [isReady, setIsReady] = useState(false);
|
|
33
35
|
const [isGenerating, setIsGenerating] = useState(false);
|
|
34
36
|
const [downloadProgress, setDownloadProgress] = useState(0);
|
|
35
37
|
|
|
36
|
-
const
|
|
38
|
+
const model = useMemo(
|
|
37
39
|
() =>
|
|
38
40
|
new VerticalOCRController({
|
|
39
41
|
modelDownloadProgressCallback: setDownloadProgress,
|
|
40
42
|
isReadyCallback: setIsReady,
|
|
41
43
|
isGeneratingCallback: setIsGenerating,
|
|
42
44
|
errorCallback: setError,
|
|
43
|
-
})
|
|
45
|
+
}),
|
|
46
|
+
[]
|
|
44
47
|
);
|
|
45
48
|
|
|
46
49
|
useEffect(() => {
|
|
@@ -53,15 +56,19 @@ export const useVerticalOCR = ({
|
|
|
53
56
|
);
|
|
54
57
|
};
|
|
55
58
|
|
|
56
|
-
|
|
59
|
+
if (!preventLoad) {
|
|
60
|
+
loadModel();
|
|
61
|
+
}
|
|
57
62
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
58
63
|
}, [
|
|
64
|
+
model,
|
|
59
65
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
60
66
|
JSON.stringify(detectorSources),
|
|
61
67
|
language,
|
|
62
68
|
independentCharacters,
|
|
63
69
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
64
70
|
JSON.stringify(recognizerSources),
|
|
71
|
+
preventLoad,
|
|
65
72
|
]);
|
|
66
73
|
|
|
67
74
|
return {
|
|
@@ -1,58 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ExecutorchModule } from '../../modules/general/ExecutorchModule';
|
|
2
|
+
import { ResourceSource } from '../../types/common';
|
|
3
3
|
import { useModule } from '../useModule';
|
|
4
|
-
import { ETInput } from '../../types/common';
|
|
5
|
-
import { getError } from '../../Error';
|
|
6
4
|
|
|
7
5
|
interface Props {
|
|
8
|
-
modelSource:
|
|
6
|
+
modelSource: ResourceSource;
|
|
7
|
+
preventLoad?: boolean;
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
export const useExecutorchModule = ({
|
|
12
11
|
modelSource,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
input: ETInput | ETInput[],
|
|
20
|
-
shape: number[] | number[][]
|
|
21
|
-
) => Promise<number[][]>;
|
|
22
|
-
loadMethod: (methodName: string) => Promise<void>;
|
|
23
|
-
loadForward: () => Promise<void>;
|
|
24
|
-
} => {
|
|
25
|
-
const [module] = useState(() => new _ETModule());
|
|
26
|
-
const {
|
|
27
|
-
error,
|
|
28
|
-
isReady,
|
|
29
|
-
isGenerating,
|
|
30
|
-
downloadProgress,
|
|
31
|
-
forwardETInput: forward,
|
|
32
|
-
} = useModule({
|
|
33
|
-
modelSource,
|
|
34
|
-
module,
|
|
12
|
+
preventLoad = false,
|
|
13
|
+
}: Props) =>
|
|
14
|
+
useModule({
|
|
15
|
+
module: ExecutorchModule,
|
|
16
|
+
loadArgs: [modelSource],
|
|
17
|
+
preventLoad,
|
|
35
18
|
});
|
|
36
|
-
|
|
37
|
-
const loadMethod = async (methodName: string) => {
|
|
38
|
-
try {
|
|
39
|
-
await module.loadMethod(methodName);
|
|
40
|
-
} catch (e) {
|
|
41
|
-
throw new Error(getError(e));
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const loadForward = async () => {
|
|
46
|
-
await loadMethod('forward');
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
error,
|
|
51
|
-
isReady,
|
|
52
|
-
isGenerating,
|
|
53
|
-
downloadProgress,
|
|
54
|
-
forward,
|
|
55
|
-
loadMethod,
|
|
56
|
-
loadForward,
|
|
57
|
-
};
|
|
58
|
-
};
|
|
@@ -1,126 +1,109 @@
|
|
|
1
|
-
import { useCallback, useEffect,
|
|
2
|
-
import {
|
|
3
|
-
import { LLM } from '../../native/RnExecutorchModules';
|
|
4
|
-
import { fetchResource } from '../../utils/fetchResource';
|
|
5
|
-
import { ResourceSource, Model, MessageType } from '../../types/common';
|
|
1
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { ResourceSource } from '../../types/common';
|
|
6
3
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
LLM.interrupt();
|
|
15
|
-
};
|
|
4
|
+
ChatConfig,
|
|
5
|
+
LLMTool,
|
|
6
|
+
LLMType,
|
|
7
|
+
Message,
|
|
8
|
+
ToolsConfig,
|
|
9
|
+
} from '../../types/llm';
|
|
10
|
+
import { LLMController } from '../../controllers/LLMController';
|
|
16
11
|
|
|
12
|
+
/*
|
|
13
|
+
Hook version of LLMController
|
|
14
|
+
*/
|
|
17
15
|
export const useLLM = ({
|
|
18
16
|
modelSource,
|
|
19
17
|
tokenizerSource,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
contextWindowLength = DEFAULT_CONTEXT_WINDOW_LENGTH,
|
|
18
|
+
tokenizerConfigSource,
|
|
19
|
+
preventLoad = false,
|
|
23
20
|
}: {
|
|
24
21
|
modelSource: ResourceSource;
|
|
25
22
|
tokenizerSource: ResourceSource;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const [
|
|
23
|
+
tokenizerConfigSource: ResourceSource;
|
|
24
|
+
preventLoad?: boolean;
|
|
25
|
+
}): LLMType => {
|
|
26
|
+
const [response, setResponse] = useState('');
|
|
27
|
+
const [messageHistory, setMessageHistory] = useState<Message[]>([]);
|
|
31
28
|
const [isReady, setIsReady] = useState(false);
|
|
32
29
|
const [isGenerating, setIsGenerating] = useState(false);
|
|
33
|
-
const [response, setResponse] = useState('');
|
|
34
30
|
const [downloadProgress, setDownloadProgress] = useState(0);
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
const loadModel = async () => {
|
|
39
|
-
try {
|
|
40
|
-
setIsReady(false);
|
|
31
|
+
const [error, setError] = useState<any>(null);
|
|
41
32
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
contextWindowLength
|
|
54
|
-
);
|
|
33
|
+
const model = useMemo(
|
|
34
|
+
() =>
|
|
35
|
+
new LLMController({
|
|
36
|
+
responseCallback: setResponse,
|
|
37
|
+
messageHistoryCallback: setMessageHistory,
|
|
38
|
+
isReadyCallback: setIsReady,
|
|
39
|
+
isGeneratingCallback: setIsGenerating,
|
|
40
|
+
onDownloadProgressCallback: setDownloadProgress,
|
|
41
|
+
}),
|
|
42
|
+
[]
|
|
43
|
+
);
|
|
55
44
|
|
|
56
|
-
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
setDownloadProgress(0);
|
|
47
|
+
setError(null);
|
|
57
48
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
);
|
|
70
|
-
} catch (err) {
|
|
71
|
-
const message = (err as Error).message;
|
|
72
|
-
setIsReady(false);
|
|
73
|
-
setError(message);
|
|
74
|
-
} finally {
|
|
75
|
-
setDownloadProgress(0);
|
|
49
|
+
if (!preventLoad) {
|
|
50
|
+
try {
|
|
51
|
+
(async () => {
|
|
52
|
+
await model.load({
|
|
53
|
+
modelSource,
|
|
54
|
+
tokenizerSource,
|
|
55
|
+
tokenizerConfigSource,
|
|
56
|
+
});
|
|
57
|
+
})();
|
|
58
|
+
} catch (e) {
|
|
59
|
+
setError(e);
|
|
76
60
|
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
loadModel();
|
|
61
|
+
}
|
|
80
62
|
|
|
81
63
|
return () => {
|
|
82
|
-
|
|
83
|
-
tokenGeneratedListener.current = null;
|
|
84
|
-
LLM.deleteModule();
|
|
64
|
+
model.delete();
|
|
85
65
|
};
|
|
86
|
-
}, [
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
66
|
+
}, [modelSource, tokenizerSource, tokenizerConfigSource, preventLoad, model]);
|
|
67
|
+
|
|
68
|
+
// memoization of returned functions
|
|
69
|
+
const configure = useCallback(
|
|
70
|
+
({
|
|
71
|
+
chatConfig,
|
|
72
|
+
toolsConfig,
|
|
73
|
+
}: {
|
|
74
|
+
chatConfig?: Partial<ChatConfig>;
|
|
75
|
+
toolsConfig?: ToolsConfig;
|
|
76
|
+
}) => model.configure({ chatConfig, toolsConfig }),
|
|
77
|
+
[model]
|
|
78
|
+
);
|
|
93
79
|
|
|
94
80
|
const generate = useCallback(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
if (error) {
|
|
100
|
-
throw new Error(error);
|
|
101
|
-
}
|
|
81
|
+
(messages: Message[], tools?: LLMTool[]) => model.generate(messages, tools),
|
|
82
|
+
[model]
|
|
83
|
+
);
|
|
102
84
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
await LLM.runInference(input);
|
|
107
|
-
} catch (err) {
|
|
108
|
-
setIsGenerating(false);
|
|
109
|
-
throw new Error((err as Error).message);
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
[isReady, error]
|
|
85
|
+
const sendMessage = useCallback(
|
|
86
|
+
(message: string) => model.sendMessage(message),
|
|
87
|
+
[model]
|
|
113
88
|
);
|
|
114
89
|
|
|
90
|
+
const deleteMessage = useCallback(
|
|
91
|
+
(index: number) => model.deleteMessage(index),
|
|
92
|
+
[model]
|
|
93
|
+
);
|
|
94
|
+
const interrupt = useCallback(() => model.interrupt(), [model]);
|
|
95
|
+
|
|
115
96
|
return {
|
|
116
|
-
|
|
117
|
-
|
|
97
|
+
messageHistory,
|
|
98
|
+
response,
|
|
118
99
|
isReady,
|
|
119
100
|
isGenerating,
|
|
120
|
-
isModelReady: isReady,
|
|
121
|
-
isModelGenerating: isGenerating,
|
|
122
|
-
response,
|
|
123
101
|
downloadProgress,
|
|
124
|
-
|
|
102
|
+
error,
|
|
103
|
+
configure: configure,
|
|
104
|
+
generate: generate,
|
|
105
|
+
sendMessage: sendMessage,
|
|
106
|
+
deleteMessage: deleteMessage,
|
|
107
|
+
interrupt: interrupt,
|
|
125
108
|
};
|
|
126
109
|
};
|