Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,3 @@ jobs:

- name: Build package
run: yarn prepare

build-web:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup
uses: ./.github/actions/setup

- name: Build example for Web
run: |
yarn example expo export --platform web
44 changes: 22 additions & 22 deletions example/App.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React from "react";
import React from 'react';
import {
StyleSheet,
Text,
Button,
TextInput,
SafeAreaView,
} from "react-native";
import * as FileSystem from "expo-file-system";
import { Pipeline } from "react-native-transformers";
import presets from "./presets.json";
} from 'react-native';
import * as FileSystem from 'expo-file-system';
import { Pipeline } from 'react-native-transformers';
import presets from './presets.json';

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

const loadModel = async (preset: {
Expand All @@ -21,23 +21,23 @@ export default function App() {
onnx_path: string;
options?: any;
}) => {
console.log("loading");
console.log('loading');
await Pipeline.TextGeneration.init(preset.model, preset.onnx_path, {
verbose: true,
fetch: async (url) => {
try {
console.log("Checking file... " + url);
const fileName = url.split("/").pop()!;
console.log('Checking file... ' + url);
const fileName = url.split('/').pop()!;
const localPath = FileSystem.documentDirectory + fileName;

// Check if the file already exists
const fileInfo = await FileSystem.getInfoAsync(localPath);
if (fileInfo.exists) {
console.log("File already exists: " + localPath);
console.log('File already exists: ' + localPath);
return localPath;
}
console.log("Downloading... " + url);

console.log('Downloading... ' + url);
const downloadResumable = FileSystem.createDownloadResumable(
url,
localPath,
Expand All @@ -46,22 +46,22 @@ export default function App() {
setProgress(totalBytesWritten / totalBytesExpectedToWrite);
}
);

const result = await downloadResumable.downloadAsync();
if (!result) {
throw new Error("Download failed.");
throw new Error('Download failed.');
}
console.log("Downloaded to: " + result.uri);

console.log('Downloaded to: ' + result.uri);
return result.uri;
} catch (error) {
console.error("Download error:", error);
console.error('Download error:', error);
return null;
}
},
...preset.options,
});
console.log("loaded");
console.log('loaded');
};

const AutoComplete = () => {
Expand Down Expand Up @@ -92,11 +92,11 @@ export default function App() {
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
justifyContent: "center",
alignItems: 'center',
justifyContent: 'center',
},
input: {
borderWidth: 1,
borderColor: "black",
borderColor: 'black',
},
});
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module.exports = {
preset: 'react-native',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
modulePathIgnorePatterns: [
'<rootDir>/example/node_modules',
'<rootDir>/lib/',
],
transformIgnorePatterns: [
'node_modules/(?!(' +
'react-native|' +
Expand Down
13 changes: 5 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"clean": "del-cli lib",
"prepare": "bob build",
"release": "release-it --only-version",
"postinstall": "patch-package"
"postinstall": "patch-package",
"docs": "typedoc src/index.tsx --out docs --exclude '**/*.test.*' --exclude '**/__tests__/**' --skipErrorChecking"
},
"keywords": [
"react-native",
Expand Down Expand Up @@ -74,13 +75,15 @@
"del-cli": "^5.1.0",
"eslint": "^9.22.0",
"eslint-config-prettier": "^10.1.1",
"eslint-plugin-ft-flow": "^3.0.11",
"eslint-plugin-prettier": "^5.2.3",
"jest": "^29.7.0",
"prettier": "^3.0.3",
"react": "19.0.0",
"react-native": "0.79.2",
"react-native-builder-bob": "^0.40.8",
"release-it": "^17.10.0",
"typedoc": "^0.28.5",
"typescript": "^5.8.3"
},
"peerDependencies": {
Expand All @@ -91,13 +94,6 @@
"example"
],
"packageManager": "yarn@3.6.1",
"jest": {
"preset": "react-native",
"modulePathIgnorePatterns": [
"<rootDir>/example/node_modules",
"<rootDir>/lib/"
]
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
Expand Down Expand Up @@ -154,6 +150,7 @@
},
"dependencies": {
"@huggingface/transformers": "github:mybigday/transformers.js-rn#merge",
"onnxruntime-react-native": "^1.21.0",
"patch-package": "^8.0.0",
"postinstall-postinstall": "^2.1.0",
"text-encoding-polyfill": "^0.6.7"
Expand Down
15 changes: 15 additions & 0 deletions src/__tests__/__mocks__/@huggingface/transformers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
env: { allowRemoteModels: true, allowLocalModels: false },
AutoTokenizer: {
from_pretrained: jest.fn().mockResolvedValue(
Object.assign(
jest.fn((_text, _options) => ({ input_ids: [1, 2, 3, 4] })),
{
decode: jest.fn((_tokens, _options) => 'decoded text'),
encode: jest.fn((_text, _options) => ({ input_ids: [1, 2, 3, 4] })),
call: jest.fn((_text, _options) => ({ input_ids: [1, 2, 3, 4] })),
}
)
),
},
};
Loading