-
Notifications
You must be signed in to change notification settings - Fork 74
docs: make resource fetcher documentation coherent with current code #1001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
76ec2e1
docs: add a warning on getting started page, fix the link in resource…
chmjkb 2e4cd5b
docs: add a separate section for resource fetcher
chmjkb dfde74a
docs: add a proper link to the custom resource fetcher impl
chmjkb ded61e5
docs: make the default example an Expo one
chmjkb 06a44b9
chore: remove redundant exmplea
chmjkb 541e1e1
chore: add a note about unsupported feats on Android
chmjkb 01a52b1
docs: review changes
chmjkb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -180,3 +180,4 @@ nˈɛvəɹ | |
| ˈɛniwˌʌn | ||
| ˈɛls | ||
| Synchronizable | ||
| stringifying | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| --- | ||
| title: Custom Adapter | ||
| --- | ||
|
|
||
| If the built-in `BareResourceFetcher` and `ExpoResourceFetcher` don't fit your needs, for example, you want to use a different download library, or fetch from a private server you can implement your own adapter and plug it into React Native ExecuTorch. | ||
|
chmjkb marked this conversation as resolved.
Outdated
|
||
|
|
||
| ## The ResourceFetcherAdapter interface | ||
|
|
||
| Your adapter must implement the `ResourceFetcherAdapter` interface exported from `react-native-executorch`. This interface defines every method which is used under the hood by React Native ExecuTorch: | ||
|
|
||
| ```typescript | ||
| import { | ||
| ResourceFetcherAdapter, | ||
| ResourceSource, | ||
| } from 'react-native-executorch'; | ||
|
|
||
| interface ResourceFetcherAdapter { | ||
| fetch( | ||
| callback: (downloadProgress: number) => void, | ||
| ...sources: ResourceSource[] | ||
| ): Promise<string[] | null>; | ||
|
|
||
| readAsString(path: string): Promise<string>; | ||
| } | ||
| ``` | ||
|
|
||
| ### `fetch` | ||
|
|
||
| This is the core method called by every model hook and module whenever it needs to resolve a model or resource to a local file path. | ||
|
|
||
| - `callback` — called with a progress value between `0` and `1` as downloads proceed. Called with `1` when complete. | ||
| - `...sources` — one or more `ResourceSource` values: | ||
| - `string` — a remote URL or an absolute local file path. | ||
| - `number` — a bundled asset reference from `require('./model.pte')`. | ||
| - `object` — an inline JS object (e.g. a tokenizer config) that should be JSON-serialized and written to disk. Your adapter is responsible for stringifying it and saving it as a file, then returning the local path. This allows callers to pass configs inline instead of hosting them at a URL. | ||
| - **Returns** an array of absolute local file paths (without `file://` prefix), one per source, in the same order. Return `null` if the fetch was intentionally interrupted (e.g. cancelled by the user). | ||
|
|
||
| ### `readAsString` | ||
|
|
||
| Called internally to read configuration files (e.g. tokenizer configs) that were previously downloaded via `fetch`. | ||
|
|
||
| - `path` — absolute path to the file on disk. | ||
| - **Returns** the file contents as a UTF-8 string. | ||
|
|
||
| ## Registering your adapter | ||
|
|
||
| Pass your adapter to `initExecutorch` at the entry point of your app, before any other library API is called: | ||
|
|
||
| ```typescript | ||
| import { initExecutorch } from 'react-native-executorch'; | ||
| import { MyCustomFetcher } from './MyCustomFetcher'; | ||
|
|
||
| initExecutorch({ resourceFetcher: MyCustomFetcher }); | ||
| ``` | ||
|
|
||
| Any model hook or module used after this point will route all resource fetching through your adapter. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "label": "Resource Fetcher", | ||
| "link": { | ||
| "type": "generated-index" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.