feat: add bare React Native LLM chat example app#763
feat: add bare React Native LLM chat example app#763msluszniak merged 39 commits intosoftware-mansion:mainfrom
Conversation
c27a355 to
bb65951
Compare
|
This PR is ready for review, but I’d prefer to proceed after #759 is merged, since this PR includes changes from #759, which makes the diff quite large. Alternatively, you can review this commit bb65951, which contains the changes after initializing the bare React Native app using |
…Native (#759) ## Description This PR introduces modular resource fetcher adapters to support both Expo and bare React Native environments, replacing the previous monolithic approach with a flexible, platform-specific architecture. **Key Changes** New Adapter Packages: - @rn-executorch/expo-adapter: Resource fetcher for Expo projects using expo-file-system and expo-asset - @rn-executorch/bare-adapter: Resource fetcher for bare React Native projects using @dr.pogodin/react-native-fs and @kesha-antonov/react-native-background-downloader **Initialization Changes:** - Added initExecutorch() function that requires explicit adapter selection - Users must now choose and configure the appropriate adapter for their project type - Provides better separation of concerns and platform-specific optimizations **Documentation Updates:** - Created individual README.md files for each adapter package ### Introduces a breaking change? - [x] Yes - [ ] No **Migration Required:** Users must now explicitly initialize the library with a resource fetcher adapter: ```typescript // Before (no initialization needed) import { useLLM } from 'react-native-executorch'; // After (required initialization) import { initExecutorch, useLLM } from 'react-native-executorch'; import { ExpoResourceFetcher } from '@rn-executorch/expo-adapter'; // or BareResourceFetcher initExecutorch({ resourceFetcher: ExpoResourceFetcher, }); ``` ### Type of change - [ ] Bug fix (change which fixes an issue) - [x] New feature (change which adds functionality) - [x] Documentation update (improves or adds clarity to existing documentation) - [ ] Other (chores, tests, code style improvements etc.) ### Tested on - [x] iOS - [x] Android ### Testing instructions **For Expo projects:** - Install dependencies: `yarn add @rn-executorch/expo-adapter expo-file-system expo-asset` - Initialize: `initExecutorch({ resourceFetcher: ExpoResourceFetcher })` - Run existing LLM example app to verify model downloads work correctly **For bare React Native projects:** - Install dependencies: `yarn add @rn-executorch/bare-adapter @dr.pogodin/react-native-fs @kesha-antonov/react-native-background-downloader` - Initialize: `initExecutorch({ resourceFetcher: BareResourceFetcher })` - Run the bare React Native example app in PR #763 > Note: A separate PR will add a dedicated bare React Native example app to make this PR easier to review. The Expo example apps can be used to verify the Expo adapter functionality. ### Screenshots <!-- Add screenshots here, if applicable --> ### Related issues Closes #549 ### Checklist - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have updated the documentation accordingly - [x] My changes generate no new warnings ### Additional notes **Why This Change:** - Different React Native environments have different filesystem APIs and c - apabilities - Expo projects benefit from using Expo's managed filesystem APIs - Bare React Native projects can leverage native libraries with background download support - Modular architecture allows for better platform-specific optimizations - Enables future extensibility for other environments (e.g., React Native Windows, macOS) **Split Into Multiple PRs:** To make review easier, this work has been split: - This PR: Core adapter infrastructure and Expo adapter implementation - Follow-up PR: Bare React Native example app demonstrating the bare adapter usage BREAKING CHANGE: `initExecutorch()` with explicit adapter selection is now required before using any react-native-executorch hooks. Users must install and configure either `@rn-executorch/expo-adapter` or `@rn-executorch/bare-adapter` depending on their project type. --------- Co-authored-by: Mateusz Słuszniak <mateusz.sluszniak@swmansion.com> Co-authored-by: Mateusz Sluszniak <56299341+msluszniak@users.noreply.github.com> Co-authored-by: Jakub Chmura <92989966+chmjkb@users.noreply.github.com>
|
Hi @rizalibnu, we have successfully merged your changes with adapters 🚀 . Do you want to proceed with this PR or do you want to pass it for us? |
bb65951 to
8816fbc
Compare
|
Hi @msluszniak, sorry for the slow response — I’ve been AFK from OSS for the past two weeks. I see there has already been good progress on this PR, so feel free to proceed and pass it from your side if that’s easier. Thanks again for the work on merging the adapters 🚀
|
|
No worries @rizalibnu. I'll progress with the PR and let you know once it will be finished so you can add some suggestions. |
b4e11d3 to
295701d
Compare
|
@rizalibnu can you check if this works for you? Specifically, I had a problem with building Android on my mac, and I think that can be due to macOS 26. |
Add modular resource fetcher adapters to support both Expo and bare React Native environments. - Expo-based resource fetcher using expo-file-system - Supports asset bundles, local files, and remote downloads - Download management with pause/resume/cancel capabilities - Bare React Native resource fetcher using RNFS and background downloader - Supports all platform-specific file operations - Background download support with proper lifecycle management - Refactor ResourceFetcher to use adapter pattern - Add initExecutorch() and cleanupExecutorch() for adapter management - Export adapter interfaces and utilities - Update LLM controller to support new resource fetching - Update computer-vision, llm, speech-to-text, text-embeddings apps - Add adapter initialization to each app - Update dependencies to use workspace packages
Add a complete bare React Native example app demonstrating LLM integration with react-native-executorch. - Simple chat UI for LLM interactions - Model loading with progress indicator - Real-time streaming responses - Send/stop generation controls - Auto-scrolling message history - **Framework**: React Native 0.81.5 (bare/CLI) - **LLM**: Uses LLAMA3_2_1B_SPINQUANT model - **Adapter**: @rn-executorch/bare-adapter - **Dependencies**: Minimal deps, only essential packages - Bridging header for RNBackgroundDownloader - Background URL session handling in AppDelegate - Background modes (fetch, processing) - Xcode project configuration - Required permissions for background downloads - Foreground service configuration - Network state access - Proper manifest configuration - Babel configuration for export namespace transform This serves as a reference implementation for using react-native-executorch in bare React Native environments (non-Expo).
…package.json for bare and expo adapters
…r for better error handling
9f75c02 to
fe18a04
Compare
|
I figured out how to handle android correctly so now it works, but needed to change resource fetcher for bare react native a bit, cc: @NorbertKlockiewicz |
…egration/assets/models/.gitignore
This comment was marked as resolved.
This comment was marked as resolved.
Keep rocket emoji in the description and 1️⃣/2️⃣/3️⃣ in the quickstart section. Also remove bold from quickstart headings. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Align ES, FR, CN, IN, PT readmes with the English README layout: remove emoji prefixes from headings and table of contents, keep :one:/:two:/:three: in quickstart steps, remove bold from step titles. Also add --no-must-find-files to cspell hook so it doesn't fail when all staged .md files are excluded by ignorePaths. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| task: { | ||
| stop: () => RNFS.stopDownload(rnfsDownload.jobId), | ||
| pause: () => {}, | ||
| resume: () => {}, |
There was a problem hiding this comment.
Please don't silently fail pause / resume. This is very confusing. If RNFS doesn't support this, throw an error saying that the operation is not supported.
There was a problem hiding this comment.
Also I think there is a cache file leak on cancel when RNFS.stopDownload is called, the partial file at cacheFileUri is never deleted.
|
@chmjkb I cannot reproduce this issue neither on my physical device nor android emulator. I added better error and I also added command that will run yarn prepare on packages so there is no need to manually call yarn prepare in packages. |
chmjkb
left a comment
There was a problem hiding this comment.
Just make sure to update the error handling page in docs with the new error code


Description
Adds a new bare React Native example application demonstrating LLM chat functionality using Executorch. This example provides a complete reference implementation for running local LLM inference on mobile devices through a simple chat interface.
Key features:
Introduces a breaking change?
Type of change
Tested on
Testing instructions
cd apps/bare_rnyarn installnpx pod-installyarn iosOr run on Android:
yarn androidVerify the app launches and displays the chat interface
Test message sending and model inference (requires model file setup)
Screenshots
Related issues
This PR provides an example app for PR #759
Checklist
Additional notes
This example app was generated using
npx @react-native-community/cli@latest init bare_rn --version 0.81.5 --pm yarnand follows bare React Native project structure (not Expo). It serves as a foundational example for developers to understand how to integrate Executorch for on-device LLM inference in their React Native applications.Why this example is not included in the yarn workspace:
The bare React Native example is maintained outside the yarn workspace structure due to fundamental architectural differences and specific technical issues:
Native Module Resolution Issues with Background Downloader:
Using the workspace monorepo breaks the Android app's integration with
@kesha-antonov/react-native-background-downloader. The monorepo's package hoisting and workspace resolution interferes with the native module's ability to properly register and resolve its native components. This causes runtime failures when attempting to download AI models in the background, which is a critical feature for this LLM chat example.Dependency Isolation: Bare React Native projects have distinct native dependency chains (iOS Pods, Android Gradle) that conflict with the monorepo's package management. The monorepo uses workspaces and hoisting strategies optimized for JavaScript/TypeScript packages, which can interfere with native module resolution.