Skip to content

Commit db6a07e

Browse files
authored
Merge pull request #12 from daviddaytw/develop
Fix CI
2 parents f7f758a + 3a99feb commit db6a07e

19 files changed

+874
-212
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,3 @@ jobs:
4949

5050
- name: Build package
5151
run: yarn prepare
52-
53-
build-web:
54-
runs-on: ubuntu-latest
55-
steps:
56-
- name: Checkout
57-
uses: actions/checkout@v4
58-
59-
- name: Setup
60-
uses: ./.github/actions/setup
61-
62-
- name: Build example for Web
63-
run: |
64-
yarn example expo export --platform web

example/App.tsx

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import React from "react";
1+
import React from 'react';
22
import {
33
StyleSheet,
44
Text,
55
Button,
66
TextInput,
77
SafeAreaView,
8-
} from "react-native";
9-
import * as FileSystem from "expo-file-system";
10-
import { Pipeline } from "react-native-transformers";
11-
import presets from "./presets.json";
8+
} from 'react-native';
9+
import * as FileSystem from 'expo-file-system';
10+
import { Pipeline } from 'react-native-transformers';
11+
import presets from './presets.json';
1212

1313
export default function App() {
1414
const [progress, setProgress] = React.useState<number>();
15-
const [input, setInput] = React.useState<string>("We love local LLM");
15+
const [input, setInput] = React.useState<string>('We love local LLM');
1616
const [output, setOutput] = React.useState<string>();
1717

1818
const loadModel = async (preset: {
@@ -21,23 +21,23 @@ export default function App() {
2121
onnx_path: string;
2222
options?: any;
2323
}) => {
24-
console.log("loading");
24+
console.log('loading');
2525
await Pipeline.TextGeneration.init(preset.model, preset.onnx_path, {
2626
verbose: true,
2727
fetch: async (url) => {
2828
try {
29-
console.log("Checking file... " + url);
30-
const fileName = url.split("/").pop()!;
29+
console.log('Checking file... ' + url);
30+
const fileName = url.split('/').pop()!;
3131
const localPath = FileSystem.documentDirectory + fileName;
32-
32+
3333
// Check if the file already exists
3434
const fileInfo = await FileSystem.getInfoAsync(localPath);
3535
if (fileInfo.exists) {
36-
console.log("File already exists: " + localPath);
36+
console.log('File already exists: ' + localPath);
3737
return localPath;
3838
}
39-
40-
console.log("Downloading... " + url);
39+
40+
console.log('Downloading... ' + url);
4141
const downloadResumable = FileSystem.createDownloadResumable(
4242
url,
4343
localPath,
@@ -46,22 +46,22 @@ export default function App() {
4646
setProgress(totalBytesWritten / totalBytesExpectedToWrite);
4747
}
4848
);
49-
49+
5050
const result = await downloadResumable.downloadAsync();
5151
if (!result) {
52-
throw new Error("Download failed.");
52+
throw new Error('Download failed.');
5353
}
54-
55-
console.log("Downloaded to: " + result.uri);
54+
55+
console.log('Downloaded to: ' + result.uri);
5656
return result.uri;
5757
} catch (error) {
58-
console.error("Download error:", error);
58+
console.error('Download error:', error);
5959
return null;
6060
}
6161
},
6262
...preset.options,
6363
});
64-
console.log("loaded");
64+
console.log('loaded');
6565
};
6666

6767
const AutoComplete = () => {
@@ -92,11 +92,11 @@ export default function App() {
9292
const styles = StyleSheet.create({
9393
container: {
9494
flex: 1,
95-
alignItems: "center",
96-
justifyContent: "center",
95+
alignItems: 'center',
96+
justifyContent: 'center',
9797
},
9898
input: {
9999
borderWidth: 1,
100-
borderColor: "black",
100+
borderColor: 'black',
101101
},
102102
});

jest.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
module.exports = {
22
preset: 'react-native',
33
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
4+
modulePathIgnorePatterns: [
5+
'<rootDir>/example/node_modules',
6+
'<rootDir>/lib/',
7+
],
48
transformIgnorePatterns: [
59
'node_modules/(?!(' +
610
'react-native|' +

package.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"clean": "del-cli lib",
4040
"prepare": "bob build",
4141
"release": "release-it --only-version",
42-
"postinstall": "patch-package"
42+
"postinstall": "patch-package",
43+
"docs": "typedoc src/index.tsx --out docs --exclude '**/*.test.*' --exclude '**/__tests__/**' --skipErrorChecking"
4344
},
4445
"keywords": [
4546
"react-native",
@@ -74,13 +75,15 @@
7475
"del-cli": "^5.1.0",
7576
"eslint": "^9.22.0",
7677
"eslint-config-prettier": "^10.1.1",
78+
"eslint-plugin-ft-flow": "^3.0.11",
7779
"eslint-plugin-prettier": "^5.2.3",
7880
"jest": "^29.7.0",
7981
"prettier": "^3.0.3",
8082
"react": "19.0.0",
8183
"react-native": "0.79.2",
8284
"react-native-builder-bob": "^0.40.8",
8385
"release-it": "^17.10.0",
86+
"typedoc": "^0.28.5",
8487
"typescript": "^5.8.3"
8588
},
8689
"peerDependencies": {
@@ -91,13 +94,6 @@
9194
"example"
9295
],
9396
"packageManager": "[email protected]",
94-
"jest": {
95-
"preset": "react-native",
96-
"modulePathIgnorePatterns": [
97-
"<rootDir>/example/node_modules",
98-
"<rootDir>/lib/"
99-
]
100-
},
10197
"commitlint": {
10298
"extends": [
10399
"@commitlint/config-conventional"
@@ -154,6 +150,7 @@
154150
},
155151
"dependencies": {
156152
"@huggingface/transformers": "github:mybigday/transformers.js-rn#merge",
153+
"onnxruntime-react-native": "^1.21.0",
157154
"patch-package": "^8.0.0",
158155
"postinstall-postinstall": "^2.1.0",
159156
"text-encoding-polyfill": "^0.6.7"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
env: { allowRemoteModels: true, allowLocalModels: false },
3+
AutoTokenizer: {
4+
from_pretrained: jest.fn().mockResolvedValue(
5+
Object.assign(
6+
jest.fn((_text, _options) => ({ input_ids: [1, 2, 3, 4] })),
7+
{
8+
decode: jest.fn((_tokens, _options) => 'decoded text'),
9+
encode: jest.fn((_text, _options) => ({ input_ids: [1, 2, 3, 4] })),
10+
call: jest.fn((_text, _options) => ({ input_ids: [1, 2, 3, 4] })),
11+
}
12+
)
13+
),
14+
},
15+
};

0 commit comments

Comments
 (0)