react-native-executorch 0.5.8 → 0.5.9
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/lib/module/hooks/general/useExecutorchModule.js +1 -3
- package/lib/module/hooks/general/useExecutorchModule.js.map +1 -1
- package/package.json +1 -1
- package/src/hooks/general/useExecutorchModule.ts +1 -1
- package/lib/Error.js +0 -53
- package/lib/ThreadPool.d.ts +0 -10
- package/lib/ThreadPool.js +0 -28
- package/lib/common/Logger.d.ts +0 -8
- package/lib/common/Logger.js +0 -19
- package/lib/constants/directories.js +0 -2
- package/lib/constants/llmDefaults.d.ts +0 -6
- package/lib/constants/llmDefaults.js +0 -16
- package/lib/constants/modelUrls.d.ts +0 -223
- package/lib/constants/modelUrls.js +0 -322
- package/lib/constants/ocr/models.d.ts +0 -882
- package/lib/constants/ocr/models.js +0 -182
- package/lib/constants/ocr/symbols.js +0 -139
- package/lib/constants/sttDefaults.d.ts +0 -28
- package/lib/constants/sttDefaults.js +0 -68
- package/lib/controllers/LLMController.d.ts +0 -47
- package/lib/controllers/LLMController.js +0 -213
- package/lib/controllers/OCRController.js +0 -67
- package/lib/controllers/SpeechToTextController.d.ts +0 -56
- package/lib/controllers/SpeechToTextController.js +0 -349
- package/lib/controllers/VerticalOCRController.js +0 -70
- package/lib/hooks/computer_vision/useClassification.d.ts +0 -15
- package/lib/hooks/computer_vision/useClassification.js +0 -7
- package/lib/hooks/computer_vision/useImageEmbeddings.d.ts +0 -15
- package/lib/hooks/computer_vision/useImageEmbeddings.js +0 -7
- package/lib/hooks/computer_vision/useImageSegmentation.d.ts +0 -38
- package/lib/hooks/computer_vision/useImageSegmentation.js +0 -7
- package/lib/hooks/computer_vision/useOCR.d.ts +0 -20
- package/lib/hooks/computer_vision/useOCR.js +0 -41
- package/lib/hooks/computer_vision/useObjectDetection.d.ts +0 -15
- package/lib/hooks/computer_vision/useObjectDetection.js +0 -7
- package/lib/hooks/computer_vision/useStyleTransfer.d.ts +0 -15
- package/lib/hooks/computer_vision/useStyleTransfer.js +0 -7
- package/lib/hooks/computer_vision/useVerticalOCR.d.ts +0 -21
- package/lib/hooks/computer_vision/useVerticalOCR.js +0 -43
- package/lib/hooks/general/useExecutorchModule.d.ts +0 -13
- package/lib/hooks/general/useExecutorchModule.js +0 -7
- package/lib/hooks/natural_language_processing/useLLM.d.ts +0 -10
- package/lib/hooks/natural_language_processing/useLLM.js +0 -78
- package/lib/hooks/natural_language_processing/useSpeechToText.d.ts +0 -27
- package/lib/hooks/natural_language_processing/useSpeechToText.js +0 -49
- package/lib/hooks/natural_language_processing/useTextEmbeddings.d.ts +0 -16
- package/lib/hooks/natural_language_processing/useTextEmbeddings.js +0 -7
- package/lib/hooks/natural_language_processing/useTokenizer.d.ts +0 -17
- package/lib/hooks/natural_language_processing/useTokenizer.js +0 -52
- package/lib/hooks/useModule.js +0 -45
- package/lib/hooks/useNonStaticModule.d.ts +0 -20
- package/lib/hooks/useNonStaticModule.js +0 -49
- package/lib/index.d.ts +0 -48
- package/lib/index.js +0 -58
- package/lib/modules/BaseModule.js +0 -25
- package/lib/modules/BaseNonStaticModule.js +0 -14
- package/lib/modules/computer_vision/ClassificationModule.d.ts +0 -8
- package/lib/modules/computer_vision/ClassificationModule.js +0 -17
- package/lib/modules/computer_vision/ImageEmbeddingsModule.d.ts +0 -8
- package/lib/modules/computer_vision/ImageEmbeddingsModule.js +0 -17
- package/lib/modules/computer_vision/ImageSegmentationModule.d.ts +0 -11
- package/lib/modules/computer_vision/ImageSegmentationModule.js +0 -27
- package/lib/modules/computer_vision/OCRModule.d.ts +0 -14
- package/lib/modules/computer_vision/OCRModule.js +0 -17
- package/lib/modules/computer_vision/ObjectDetectionModule.d.ts +0 -9
- package/lib/modules/computer_vision/ObjectDetectionModule.js +0 -17
- package/lib/modules/computer_vision/StyleTransferModule.d.ts +0 -8
- package/lib/modules/computer_vision/StyleTransferModule.js +0 -17
- package/lib/modules/computer_vision/VerticalOCRModule.d.ts +0 -14
- package/lib/modules/computer_vision/VerticalOCRModule.js +0 -19
- package/lib/modules/general/ExecutorchModule.d.ts +0 -7
- package/lib/modules/general/ExecutorchModule.js +0 -14
- package/lib/modules/natural_language_processing/LLMModule.d.ts +0 -28
- package/lib/modules/natural_language_processing/LLMModule.js +0 -45
- package/lib/modules/natural_language_processing/SpeechToTextModule.d.ts +0 -24
- package/lib/modules/natural_language_processing/SpeechToTextModule.js +0 -36
- package/lib/modules/natural_language_processing/TextEmbeddingsModule.d.ts +0 -9
- package/lib/modules/natural_language_processing/TextEmbeddingsModule.js +0 -21
- package/lib/modules/natural_language_processing/TokenizerModule.d.ts +0 -12
- package/lib/modules/natural_language_processing/TokenizerModule.js +0 -30
- package/lib/native/NativeETInstaller.js +0 -2
- package/lib/native/NativeOCR.js +0 -2
- package/lib/native/NativeVerticalOCR.js +0 -2
- package/lib/native/RnExecutorchModules.d.ts +0 -7
- package/lib/native/RnExecutorchModules.js +0 -18
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/lib/types/common.d.ts +0 -32
- package/lib/types/common.js +0 -25
- package/lib/types/imageSegmentation.js +0 -26
- package/lib/types/llm.d.ts +0 -46
- package/lib/types/llm.js +0 -9
- package/lib/types/objectDetection.js +0 -94
- package/lib/types/ocr.js +0 -1
- package/lib/types/stt.d.ts +0 -94
- package/lib/types/stt.js +0 -85
- package/lib/utils/ResourceFetcher.d.ts +0 -24
- package/lib/utils/ResourceFetcher.js +0 -305
- package/lib/utils/ResourceFetcherUtils.d.ts +0 -54
- package/lib/utils/ResourceFetcherUtils.js +0 -127
- package/lib/utils/llm.d.ts +0 -6
- package/lib/utils/llm.js +0 -72
- package/lib/utils/stt.js +0 -21
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @internal
|
|
3
|
-
*/
|
|
4
|
-
import { getInfoAsync, makeDirectoryAsync, } from 'expo-file-system';
|
|
5
|
-
import { RNEDirectory } from '../constants/directories';
|
|
6
|
-
import { Asset } from 'expo-asset';
|
|
7
|
-
import { Logger } from '../common/Logger';
|
|
8
|
-
export var ResourceFetcherUtils;
|
|
9
|
-
(function (ResourceFetcherUtils) {
|
|
10
|
-
function getType(source) {
|
|
11
|
-
if (typeof source === 'object') {
|
|
12
|
-
return 0 /* SourceType.OBJECT */;
|
|
13
|
-
}
|
|
14
|
-
else if (typeof source === 'number') {
|
|
15
|
-
const uri = Asset.fromModule(source).uri;
|
|
16
|
-
if (!uri.includes('://')) {
|
|
17
|
-
return 2 /* SourceType.RELEASE_MODE_FILE */;
|
|
18
|
-
}
|
|
19
|
-
return 3 /* SourceType.DEV_MODE_FILE */;
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
// typeof source == 'string'
|
|
23
|
-
if (source.startsWith('file://')) {
|
|
24
|
-
return 1 /* SourceType.LOCAL_FILE */;
|
|
25
|
-
}
|
|
26
|
-
return 4 /* SourceType.REMOTE_FILE */;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
ResourceFetcherUtils.getType = getType;
|
|
30
|
-
async function getFilesSizes(sources) {
|
|
31
|
-
const results = [];
|
|
32
|
-
let totalLength = 0;
|
|
33
|
-
let previousFilesTotalLength = 0;
|
|
34
|
-
for (const source of sources) {
|
|
35
|
-
const type = await ResourceFetcherUtils.getType(source);
|
|
36
|
-
let length = 0;
|
|
37
|
-
if (type === 4 /* SourceType.REMOTE_FILE */ && typeof source === 'string') {
|
|
38
|
-
try {
|
|
39
|
-
const response = await fetch(source, { method: 'HEAD' });
|
|
40
|
-
if (!response.ok) {
|
|
41
|
-
Logger.warn(`Failed to fetch HEAD for ${source}: ${response.status}`);
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
const contentLength = response.headers.get('content-length');
|
|
45
|
-
if (!contentLength) {
|
|
46
|
-
Logger.warn(`No content-length header for ${source}`);
|
|
47
|
-
}
|
|
48
|
-
length = contentLength ? parseInt(contentLength, 10) : 0;
|
|
49
|
-
previousFilesTotalLength = totalLength;
|
|
50
|
-
totalLength += length;
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
Logger.warn(`Error fetching HEAD for ${source}:`, error);
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
results.push({ source, type, length, previousFilesTotalLength });
|
|
58
|
-
}
|
|
59
|
-
return { results, totalLength };
|
|
60
|
-
}
|
|
61
|
-
ResourceFetcherUtils.getFilesSizes = getFilesSizes;
|
|
62
|
-
function removeFilePrefix(uri) {
|
|
63
|
-
return uri.startsWith('file://') ? uri.slice(7) : uri;
|
|
64
|
-
}
|
|
65
|
-
ResourceFetcherUtils.removeFilePrefix = removeFilePrefix;
|
|
66
|
-
function hashObject(jsonString) {
|
|
67
|
-
let hash = 0;
|
|
68
|
-
for (let i = 0; i < jsonString.length; i++) {
|
|
69
|
-
// eslint-disable-next-line no-bitwise
|
|
70
|
-
hash = (hash << 5) - hash + jsonString.charCodeAt(i);
|
|
71
|
-
// eslint-disable-next-line no-bitwise
|
|
72
|
-
hash |= 0;
|
|
73
|
-
}
|
|
74
|
-
// eslint-disable-next-line no-bitwise
|
|
75
|
-
return (hash >>> 0).toString();
|
|
76
|
-
}
|
|
77
|
-
ResourceFetcherUtils.hashObject = hashObject;
|
|
78
|
-
function calculateDownloadProgress(totalLength, previousFilesTotalLength, currentFileLength, setProgress) {
|
|
79
|
-
return (progress) => {
|
|
80
|
-
if (progress === 1 &&
|
|
81
|
-
previousFilesTotalLength === totalLength - currentFileLength) {
|
|
82
|
-
setProgress(1);
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
// Avoid division by zero
|
|
86
|
-
if (totalLength === 0) {
|
|
87
|
-
setProgress(0);
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
const baseProgress = previousFilesTotalLength / totalLength;
|
|
91
|
-
const scaledProgress = progress * (currentFileLength / totalLength);
|
|
92
|
-
const updatedProgress = baseProgress + scaledProgress;
|
|
93
|
-
setProgress(updatedProgress);
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
ResourceFetcherUtils.calculateDownloadProgress = calculateDownloadProgress;
|
|
97
|
-
/*
|
|
98
|
-
* Increments the Hugging Face download counter if the URI points to a Software Mansion Hugging Face repo.
|
|
99
|
-
* More information: https://huggingface.co/docs/hub/models-download-stats
|
|
100
|
-
*/
|
|
101
|
-
async function triggerHuggingFaceDownloadCounter(uri) {
|
|
102
|
-
const url = new URL(uri);
|
|
103
|
-
if (url.host === 'huggingface.co' &&
|
|
104
|
-
url.pathname.startsWith('/software-mansion/')) {
|
|
105
|
-
const baseUrl = `${url.protocol}//${url.host}${url.pathname.split('resolve')[0]}`;
|
|
106
|
-
fetch(`${baseUrl}resolve/main/config.json`, { method: 'HEAD' });
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
ResourceFetcherUtils.triggerHuggingFaceDownloadCounter = triggerHuggingFaceDownloadCounter;
|
|
110
|
-
async function createDirectoryIfNoExists() {
|
|
111
|
-
if (!(await checkFileExists(RNEDirectory))) {
|
|
112
|
-
await makeDirectoryAsync(RNEDirectory, { intermediates: true });
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
ResourceFetcherUtils.createDirectoryIfNoExists = createDirectoryIfNoExists;
|
|
116
|
-
async function checkFileExists(fileUri) {
|
|
117
|
-
const fileInfo = await getInfoAsync(fileUri);
|
|
118
|
-
return fileInfo.exists;
|
|
119
|
-
}
|
|
120
|
-
ResourceFetcherUtils.checkFileExists = checkFileExists;
|
|
121
|
-
function getFilenameFromUri(uri) {
|
|
122
|
-
let cleanUri = uri.replace(/^https?:\/\//, '');
|
|
123
|
-
cleanUri = cleanUri.split('#')?.[0] ?? cleanUri;
|
|
124
|
-
return cleanUri.replace(/[^a-zA-Z0-9._-]/g, '_');
|
|
125
|
-
}
|
|
126
|
-
ResourceFetcherUtils.getFilenameFromUri = getFilenameFromUri;
|
|
127
|
-
})(ResourceFetcherUtils || (ResourceFetcherUtils = {}));
|
package/lib/utils/llm.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { ToolCall } from '../types/llm';
|
|
2
|
-
import { Schema } from 'jsonschema';
|
|
3
|
-
import * as zCore from 'zod/v4/core';
|
|
4
|
-
export declare const parseToolCall: (message: string) => ToolCall[];
|
|
5
|
-
export declare const getStructuredOutputPrompt: <T extends zCore.$ZodType>(responseSchema: T | Schema) => string;
|
|
6
|
-
export declare const fixAndValidateStructuredOutput: <T extends zCore.$ZodType>(output: string, responseSchema: T | Schema) => zCore.output<T>;
|
package/lib/utils/llm.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import * as z from 'zod/v4';
|
|
2
|
-
import { Validator } from 'jsonschema';
|
|
3
|
-
import { jsonrepair } from 'jsonrepair';
|
|
4
|
-
import { DEFAULT_STRUCTURED_OUTPUT_PROMPT } from '../constants/llmDefaults';
|
|
5
|
-
import * as zCore from 'zod/v4/core';
|
|
6
|
-
import { Logger } from '../common/Logger';
|
|
7
|
-
export const parseToolCall = (message) => {
|
|
8
|
-
try {
|
|
9
|
-
const unparsedToolCalls = message.match('\\[(.|\\s)*\\]');
|
|
10
|
-
if (!unparsedToolCalls) {
|
|
11
|
-
throw Error('Regex did not match array.');
|
|
12
|
-
}
|
|
13
|
-
const parsedMessage = JSON.parse(unparsedToolCalls[0]);
|
|
14
|
-
const results = [];
|
|
15
|
-
for (const tool of parsedMessage) {
|
|
16
|
-
if ('name' in tool &&
|
|
17
|
-
typeof tool.name === 'string' &&
|
|
18
|
-
'arguments' in tool &&
|
|
19
|
-
tool.arguments !== null &&
|
|
20
|
-
typeof tool.arguments === 'object') {
|
|
21
|
-
results.push({
|
|
22
|
-
toolName: tool.name,
|
|
23
|
-
arguments: tool.arguments,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return results;
|
|
28
|
-
}
|
|
29
|
-
catch (e) {
|
|
30
|
-
Logger.error(e);
|
|
31
|
-
return [];
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
const filterObjectKeys = (obj, keysToRemove) => {
|
|
35
|
-
const entries = Object.entries(obj);
|
|
36
|
-
const filteredEntries = entries.filter(([key, _]) => !keysToRemove.includes(key));
|
|
37
|
-
return Object.fromEntries(filteredEntries);
|
|
38
|
-
};
|
|
39
|
-
export const getStructuredOutputPrompt = (responseSchema) => {
|
|
40
|
-
const schemaObject = responseSchema instanceof zCore.$ZodType
|
|
41
|
-
? filterObjectKeys(z.toJSONSchema(responseSchema), [
|
|
42
|
-
'$schema',
|
|
43
|
-
'additionalProperties',
|
|
44
|
-
])
|
|
45
|
-
: responseSchema;
|
|
46
|
-
const schemaString = JSON.stringify(schemaObject);
|
|
47
|
-
return DEFAULT_STRUCTURED_OUTPUT_PROMPT(schemaString);
|
|
48
|
-
};
|
|
49
|
-
const extractBetweenBrackets = (text) => {
|
|
50
|
-
const startIndex = text.search(/[\\{\\[]/); // First occurrence of either { or [
|
|
51
|
-
const openingBracket = text[startIndex];
|
|
52
|
-
const closingBracket = openingBracket === '{' ? '}' : ']';
|
|
53
|
-
if (!openingBracket)
|
|
54
|
-
throw Error("Couldn't find JSON in text");
|
|
55
|
-
return text.slice(text.indexOf(openingBracket), text.lastIndexOf(closingBracket) + 1);
|
|
56
|
-
};
|
|
57
|
-
// this is a bit hacky typing
|
|
58
|
-
export const fixAndValidateStructuredOutput = (output, responseSchema) => {
|
|
59
|
-
const extractedOutput = extractBetweenBrackets(output);
|
|
60
|
-
const repairedOutput = jsonrepair(extractedOutput);
|
|
61
|
-
const outputJSON = JSON.parse(repairedOutput);
|
|
62
|
-
if (responseSchema instanceof zCore.$ZodType) {
|
|
63
|
-
return z.parse(responseSchema, outputJSON);
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
const validator = new Validator();
|
|
67
|
-
validator.validate(outputJSON, responseSchema, {
|
|
68
|
-
throwAll: true,
|
|
69
|
-
});
|
|
70
|
-
return outputJSON;
|
|
71
|
-
}
|
|
72
|
-
};
|
package/lib/utils/stt.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export const longCommonInfPref = (seq1, seq2, hammingDistThreshold) => {
|
|
2
|
-
let maxInd = 0;
|
|
3
|
-
let maxLength = 0;
|
|
4
|
-
for (let i = 0; i < seq1.length; i++) {
|
|
5
|
-
let j = 0;
|
|
6
|
-
let hammingDist = 0;
|
|
7
|
-
while (j < seq2.length &&
|
|
8
|
-
i + j < seq1.length &&
|
|
9
|
-
(seq1[i + j] === seq2[j] || hammingDist < hammingDistThreshold)) {
|
|
10
|
-
if (seq1[i + j] !== seq2[j]) {
|
|
11
|
-
hammingDist++;
|
|
12
|
-
}
|
|
13
|
-
j++;
|
|
14
|
-
}
|
|
15
|
-
if (j >= maxLength) {
|
|
16
|
-
maxLength = j;
|
|
17
|
-
maxInd = i;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return maxInd;
|
|
21
|
-
};
|