diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..dc82d4a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,68 @@ +name: 🐛 Bug report +description: Report a reproducible bug or regression in this library. +labels: [bug] +body: + - type: markdown + attributes: + value: | + # Bug report + + 👋 Hi! + + **Please fill the following carefully before opening a new issue ❗** + *(Your issue may be closed if it doesn't provide the required pieces of information)* + - type: checkboxes + attributes: + label: Before submitting a new issue + description: Please perform simple checks first. + options: + - label: I tested using the latest version of the library, as the bug might be already fixed. + required: true + - label: I tested using a [supported version](https://github.com/reactwg/react-native-releases/blob/main/docs/support.md) of react native. + required: true + - label: I checked for possible duplicate issues, with possible answers. + required: true + - type: textarea + id: summary + attributes: + label: Bug summary + description: | + Provide a clear and concise description of what the bug is. + If needed, you can also provide other samples: error messages / stack traces, screenshots, gifs, etc. + validations: + required: true + - type: input + id: library-version + attributes: + label: Library version + description: What version of the library are you using? + placeholder: "x.x.x" + validations: + required: true + - type: textarea + id: react-native-info + attributes: + label: Environment info + description: Run `react-native info` in your terminal and paste the results here. + render: shell + validations: + required: true + - type: textarea + id: steps-to-reproduce + attributes: + label: Steps to reproduce + description: | + You must provide a clear list of steps and code to reproduce the problem. + value: | + 1. … + 2. … + validations: + required: true + - type: input + id: reproducible-example + attributes: + label: Reproducible example repository + description: Please provide a link to a repository on GitHub with a reproducible example. + render: js + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..d233965 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,8 @@ +blank_issues_enabled: false +contact_links: + - name: Feature Request 💡 + url: https://github.com/daviddaytw/react-native-transformers/discussions/new?category=ideas + about: If you have a feature request, please create a new discussion on GitHub. + - name: Discussions on GitHub 💬 + url: https://github.com/daviddaytw/react-native-transformers/discussions + about: If this library works as promised but you need help, please ask questions there. diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml new file mode 100644 index 0000000..066f4f5 --- /dev/null +++ b/.github/actions/setup/action.yml @@ -0,0 +1,36 @@ +name: Setup +description: Setup Node.js and install dependencies + +runs: + using: composite + steps: + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + + - name: Restore dependencies + id: yarn-cache + uses: actions/cache/restore@v4 + with: + path: | + **/node_modules + .yarn/install-state.gz + key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}-${{ hashFiles('**/package.json', '!node_modules/**') }} + restore-keys: | + ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} + ${{ runner.os }}-yarn- + + - name: Install dependencies + if: steps.yarn-cache.outputs.cache-hit != 'true' + run: yarn install --immutable + shell: bash + + - name: Cache dependencies + if: steps.yarn-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: | + **/node_modules + .yarn/install-state.gz + key: ${{ steps.yarn-cache.outputs.cache-primary-key }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..f89b2ef --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,64 @@ +name: CI +on: + push: + branches: + - main + pull_request: + branches: + - main + merge_group: + types: + - checks_requested + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup + uses: ./.github/actions/setup + + - name: Lint files + run: yarn lint + + - name: Typecheck files + run: yarn typecheck + + test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup + uses: ./.github/actions/setup + + - name: Run unit tests + run: yarn test --maxWorkers=2 --coverage + + build-library: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup + uses: ./.github/actions/setup + + - 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 diff --git a/.gitignore b/.gitignore index 8bf7580..67f3212 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ DerivedData *.ipa *.xcuserstate project.xcworkspace +**/.xcode.env.local # Android/IJ # @@ -74,11 +75,12 @@ android/keystores/debug.keystore # Turborepo .turbo/ -# generated by typescript +# generated by bob lib/ -# jest -coverage/ +# React Native Codegen +ios/generated +android/generated -# TypeDoc -docs/ +# React Native Nitro Modules +nitrogen/ diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..5f53e87 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +v20.19.0 diff --git a/.watchmanconfig b/.watchmanconfig new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/.watchmanconfig @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9c9f8cf..31b2186 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -43,6 +43,14 @@ To run the example app on iOS: yarn example ios ``` +To confirm that the app is running with the new architecture, you can check the Metro logs for a message like this: + +```sh +Running "TransformersExample" with {"fabric":true,"initialProps":{"concurrentRoot":true},"rootTag":1} +``` + +Note the `"fabric":true` and `"concurrentRoot":true` properties. + To run the example app on Web: ```sh diff --git a/LICENSE b/LICENSE index cde94f6..3452c55 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024 David Day +Copyright (c) 2025 David Day Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights diff --git a/README.md b/README.md index 0262398..7c8525b 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ Link the `onnxruntime-react-native` library: ```sh npx react-native link onnxruntime-react-native ``` +
@@ -56,14 +57,9 @@ npx react-native link onnxruntime-react-native Add the Expo plugin configuration in `app.json` or `app.config.js`: ```json -{ - "expo": { - "plugins": [ - "onnxruntime-react-native" - ] - } -} +{ "expo": { "plugins": ["onnxruntime-react-native"] } } ``` +
### 4. Babel Configuration @@ -76,8 +72,8 @@ module.exports = { // ... your existing config plugins: [ // ... your existing plugins - "babel-plugin-transform-import-meta" - ] + 'babel-plugin-transform-import-meta', + ], }; ``` @@ -92,18 +88,17 @@ You can set up a development client using one of these methods: - **[EAS Development Build](https://docs.expo.dev/develop/development-builds/introduction/)**: Create a custom development client using EAS Build - **[Expo Prebuild](https://docs.expo.dev/workflow/prebuild/)**: Eject to a bare workflow to access native code - ## Usage ### Text Generation ```javascript -import React, { useState, useEffect } from "react"; -import { View, Text, Button } from "react-native"; -import { Pipeline } from "react-native-transformers"; +import React, { useState, useEffect } from 'react'; +import { View, Text, Button } from 'react-native'; +import { Pipeline } from 'react-native-transformers'; export default function App() { - const [output, setOutput] = useState(""); + const [output, setOutput] = useState(''); const [isLoading, setIsLoading] = useState(false); const [isModelReady, setIsModelReady] = useState(false); @@ -117,31 +112,31 @@ export default function App() { try { // Load a small Llama model await Pipeline.TextGeneration.init( - "Felladrin/onnx-Llama-160M-Chat-v1", - "onnx/decoder_model_merged.onnx", + 'Felladrin/onnx-Llama-160M-Chat-v1', + 'onnx/decoder_model_merged.onnx', { // The fetch function is required to download model files fetch: async (url) => { // In a real app, you might want to cache the downloaded files const response = await fetch(url); return response.url; - } + }, } ); setIsModelReady(true); } catch (error) { - console.error("Error loading model:", error); - alert("Failed to load model: " + error.message); + console.error('Error loading model:', error); + alert('Failed to load model: ' + error.message); } finally { setIsLoading(false); } }; const generateText = () => { - setOutput(""); + setOutput(''); // Generate text from the prompt and update the UI as tokens are generated Pipeline.TextGeneration.generate( - "Write a short poem about programming:", + 'Write a short poem about programming:', (text) => setOutput(text) ); }; @@ -149,12 +144,12 @@ export default function App() { return (