@capgo/capacitor-llm 8.0.19 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapgoCapacitorLlm.podspec +1 -9
- package/Package.swift +21 -3
- package/README.md +137 -163
- package/android/build.gradle +3 -2
- package/android/src/main/java/ee/forgr/capgo_llm/LLM.java +605 -283
- package/android/src/main/java/ee/forgr/capgo_llm/LLMPlugin.java +36 -63
- package/dist/docs.json +66 -35
- package/dist/esm/definitions.d.ts +28 -20
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +6 -0
- package/dist/esm/web.js +68 -39
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +68 -39
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +68 -39
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/LLMPlugin/LLMPlugin.swift +384 -613
- package/ios/Sources/LiteRTLM/Benchmark.swift +83 -0
- package/ios/Sources/LiteRTLM/Capabilities.swift +41 -0
- package/ios/Sources/LiteRTLM/Config.swift +172 -0
- package/ios/Sources/LiteRTLM/Conversation.swift +472 -0
- package/ios/Sources/LiteRTLM/Engine.swift +208 -0
- package/ios/Sources/LiteRTLM/ExperimentalFlags.swift +142 -0
- package/ios/Sources/LiteRTLM/LiteRTLMError.swift +156 -0
- package/ios/Sources/LiteRTLM/Message.swift +225 -0
- package/ios/Sources/LiteRTLM/Tool.swift +291 -0
- package/ios/Sources/LiteRTLM/ToolManager.swift +152 -0
- package/package.json +6 -5
|
@@ -11,17 +11,9 @@ Pod::Spec.new do |s|
|
|
|
11
11
|
s.author = package['author']
|
|
12
12
|
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
13
|
s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
-
s.platform = :ios, '15.0'
|
|
15
14
|
s.ios.deployment_target = '15.0'
|
|
16
|
-
s.pod_target_xcconfig = {
|
|
17
|
-
'SUPPORTS_MACCATALYST' => 'NO',
|
|
18
|
-
'EXCLUDED_ARCHS[sdk=macosx*]' => 'arm64 x86_64'
|
|
19
|
-
}
|
|
20
|
-
s.user_target_xcconfig = {
|
|
21
|
-
'EXCLUDED_ARCHS[sdk=macosx*]' => 'arm64 x86_64'
|
|
22
|
-
}
|
|
23
15
|
s.dependency 'Capacitor'
|
|
24
16
|
s.dependency 'MediaPipeTasksGenAI'
|
|
25
17
|
s.dependency 'MediaPipeTasksGenAIC'
|
|
26
|
-
s.swift_version = '
|
|
18
|
+
s.swift_version = '6.0'
|
|
27
19
|
end
|
package/Package.swift
CHANGED
|
@@ -13,16 +13,34 @@ let package = Package(
|
|
|
13
13
|
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
|
|
14
14
|
],
|
|
15
15
|
targets: [
|
|
16
|
+
// Vendor the official Swift wrapper locally and fetch only the iOS xcframework.
|
|
17
|
+
// The upstream repo checkout currently pulls non-iOS LFS blobs that break SwiftPM resolution here.
|
|
18
|
+
.binaryTarget(
|
|
19
|
+
name: "CLiteRTLM",
|
|
20
|
+
url: "https://github.com/google-ai-edge/LiteRT-LM/releases/download/v0.13.0/CLiteRTLM.xcframework.zip",
|
|
21
|
+
checksum: "af23c77b8eae3f1888fc0348c133af8a13f1e8a89f5788de7e38457f512e768a"
|
|
22
|
+
),
|
|
23
|
+
.target(
|
|
24
|
+
name: "LiteRTLM",
|
|
25
|
+
dependencies: ["CLiteRTLM"],
|
|
26
|
+
path: "ios/Sources/LiteRTLM",
|
|
27
|
+
linkerSettings: [
|
|
28
|
+
.unsafeFlags(["-Xlinker", "-all_load"])
|
|
29
|
+
]
|
|
30
|
+
),
|
|
16
31
|
.target(
|
|
17
32
|
name: "LLMPlugin",
|
|
18
33
|
dependencies: [
|
|
19
34
|
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
-
.product(name: "Cordova", package: "capacitor-swift-pm")
|
|
35
|
+
.product(name: "Cordova", package: "capacitor-swift-pm"),
|
|
36
|
+
"LiteRTLM"
|
|
21
37
|
],
|
|
22
|
-
path: "ios/Sources/LLMPlugin"
|
|
38
|
+
path: "ios/Sources/LLMPlugin"
|
|
39
|
+
),
|
|
23
40
|
.testTarget(
|
|
24
41
|
name: "LLMPluginTests",
|
|
25
42
|
dependencies: ["LLMPlugin"],
|
|
26
|
-
path: "ios/Tests/LLMPluginTests"
|
|
43
|
+
path: "ios/Tests/LLMPluginTests"
|
|
44
|
+
)
|
|
27
45
|
]
|
|
28
46
|
)
|
package/README.md
CHANGED
|
@@ -1,208 +1,171 @@
|
|
|
1
1
|
# @capgo/capacitor-llm
|
|
2
2
|
|
|
3
|
-
<a href="https://capgo.app/"><img src=
|
|
3
|
+
<a href="https://capgo.app/"><img src='https://raw.githubusercontent.com/Cap-go/capgo/main/assets/capgo_banner.png' alt='Capgo - Instant updates for capacitor'/></a>
|
|
4
4
|
|
|
5
5
|
<div align="center">
|
|
6
6
|
<h2><a href="https://capgo.app/?ref=plugin_llm"> ➡️ Get Instant updates for your App with Capgo 🚀</a></h2>
|
|
7
7
|
<h2><a href="https://capgo.app/consulting/?ref=plugin_llm"> Fix your annoying bug now, Hire a Capacitor expert 💪</a></h2>
|
|
8
8
|
</div>
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
On-device LLM support for Capacitor.
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
Current platform strategy:
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
- iOS: Apple Intelligence by default, plus LiteRT-LM `.litertlm` custom models when the plugin is integrated through Swift Package Manager
|
|
15
|
+
- Android: Gemini Nano system model on supported devices where it is already available, LiteRT-LM for `.litertlm` bundles, and a compatibility fallback for legacy MediaPipe `.task` models
|
|
16
|
+
- Web: Gemma 4 web models through `@mediapipe/tasks-genai`
|
|
15
17
|
|
|
16
18
|
## Documentation
|
|
17
19
|
|
|
18
|
-
The most complete
|
|
20
|
+
The most complete plugin docs are available at [capgo.app/docs/plugins/llm](https://capgo.app/docs/plugins/llm/).
|
|
19
21
|
|
|
20
22
|
## Compatibility
|
|
21
23
|
|
|
22
24
|
| Plugin version | Capacitor compatibility | Maintained |
|
|
23
25
|
| -------------- | ----------------------- | ---------- |
|
|
24
|
-
| v8
|
|
25
|
-
| v7
|
|
26
|
-
| v6
|
|
27
|
-
| v5
|
|
26
|
+
| v8.*.* | v8.*.* | ✅ |
|
|
27
|
+
| v7.*.* | v7.*.* | On demand |
|
|
28
|
+
| v6.*.* | v6.*.* | ❌ |
|
|
29
|
+
| v5.*.* | v5.*.* | ❌ |
|
|
28
30
|
|
|
29
|
-
> **Note:** The major version
|
|
31
|
+
> **Note:** The plugin major version follows the Capacitor major version. Use the version that matches your Capacitor installation.
|
|
30
32
|
|
|
31
33
|
## Installation
|
|
32
34
|
|
|
33
|
-
You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:
|
|
34
|
-
|
|
35
35
|
```bash
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
Then use the following prompt:
|
|
40
|
-
|
|
41
|
-
```text
|
|
42
|
-
Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-llm` plugin in my project.
|
|
36
|
+
npm install @capgo/capacitor-llm
|
|
37
|
+
npx cap sync
|
|
43
38
|
```
|
|
44
39
|
|
|
45
|
-
If you
|
|
40
|
+
If you use the web implementation, also install the MediaPipe peer dependency:
|
|
46
41
|
|
|
47
42
|
```bash
|
|
48
|
-
|
|
49
|
-
bunx cap sync
|
|
43
|
+
npm install @mediapipe/tasks-genai
|
|
50
44
|
```
|
|
51
45
|
|
|
52
|
-
|
|
46
|
+
## Model Setup
|
|
53
47
|
|
|
54
|
-
|
|
48
|
+
### iOS
|
|
55
49
|
|
|
56
|
-
|
|
57
|
-
The MediaPipe dependencies are already configured in the podspec. Make sure to run `pod install` after adding the plugin.
|
|
50
|
+
Recommended path:
|
|
58
51
|
|
|
59
|
-
|
|
52
|
+
- Use Apple Intelligence with `path: 'Apple Intelligence'`
|
|
53
|
+
- Requires iOS 26.0+
|
|
60
54
|
|
|
61
|
-
|
|
62
|
-
When running `pod install`, you may see a warning about transitive dependencies with statically linked binaries. To fix this, update your Podfile:
|
|
55
|
+
Custom iOS LiteRT-LM path:
|
|
63
56
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
57
|
+
- Available only when the plugin is integrated into the iOS app through Swift Package Manager
|
|
58
|
+
- Uses the official LiteRT-LM Swift API and prebuilt iOS xcframework for `.litertlm` models
|
|
59
|
+
- CocoaPods builds keep Apple Intelligence and the legacy MediaPipe `.task` compatibility path
|
|
67
60
|
|
|
68
|
-
|
|
69
|
-
use_frameworks! :linkage => :static
|
|
61
|
+
Example:
|
|
70
62
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
assertDeploymentTarget(installer)
|
|
74
|
-
|
|
75
|
-
# Fix for static framework dependencies
|
|
76
|
-
installer.pods_project.targets.each do |target|
|
|
77
|
-
target.build_configurations.each do |config|
|
|
78
|
-
config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
|
|
79
|
-
end
|
|
63
|
+
```ts
|
|
64
|
+
import { CapgoLLM } from '@capgo/capacitor-llm';
|
|
80
65
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
target.build_configurations.each do |config|
|
|
84
|
-
config.build_settings['ENABLE_BITCODE'] = 'NO'
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
end
|
|
66
|
+
await CapgoLLM.setModel({ path: 'Apple Intelligence' });
|
|
67
|
+
const chat = await CapgoLLM.createChat();
|
|
89
68
|
```
|
|
90
69
|
|
|
91
|
-
|
|
92
|
-
The plugin's `Package.swift` does not link ExecuTorch directly because that would force every Swift Package Manager user onto iOS 17 or newer, even when they only use Apple Intelligence or MediaPipe.
|
|
93
|
-
|
|
94
|
-
To use ExecuTorch on iOS, add it to your app target:
|
|
70
|
+
### Android
|
|
95
71
|
|
|
96
|
-
|
|
97
|
-
2. In Xcode, open the app project, select **Package Dependencies**, and add `https://github.com/pytorch/executorch.git`.
|
|
98
|
-
3. Use the `swiftpm-1.2.0` branch, or the ExecuTorch branch that matches the runtime version you want.
|
|
99
|
-
4. Add these products to the app target: `executorch_llm`, `backend_xnnpack`, `kernels_llm`, `kernels_optimized`, `kernels_quantized`, and `kernels_torchao`.
|
|
100
|
-
5. Add the `.pte` model and tokenizer file to the app target's Copy Bundle Resources, or download them at runtime.
|
|
72
|
+
Recommended path:
|
|
101
73
|
|
|
102
|
-
|
|
74
|
+
- Use Gemini Nano with `path: 'Gemini Nano'` when the Android device already has it available through AICore
|
|
75
|
+
- Use LiteRT-LM `.litertlm` bundles
|
|
76
|
+
- Gemma 4 E2B and E4B are good default examples
|
|
77
|
+
- Models are available from the public [`litert-community`](https://huggingface.co/litert-community) Hugging Face repos
|
|
103
78
|
|
|
104
|
-
|
|
79
|
+
Gemini Nano system model example:
|
|
105
80
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
iOS uses ExecuTorch only when the host app links the ExecuTorch Swift Package products. It is not included by CocoaPods or by the plugin's `Package.swift`, so an app without those products can use Apple Intelligence or MediaPipe but will refuse `engine: 'executorch'`. Android uses the ExecuTorch Maven package.
|
|
111
|
-
|
|
112
|
-
Bundle the model files:
|
|
81
|
+
```ts
|
|
82
|
+
await CapgoLLM.setModel({ path: 'Gemini Nano' });
|
|
83
|
+
const chat = await CapgoLLM.createChat();
|
|
84
|
+
```
|
|
113
85
|
|
|
114
|
-
|
|
115
|
-
- Android: place the `.pte` model and tokenizer file under `android/app/src/main/assets/`, then reference them with `/android_asset/...`.
|
|
86
|
+
Quickstart with a downloaded Gemma 4 model:
|
|
116
87
|
|
|
117
|
-
```
|
|
118
|
-
import { Capacitor } from '@capacitor/core';
|
|
88
|
+
```ts
|
|
119
89
|
import { CapgoLLM } from '@capgo/capacitor-llm';
|
|
120
90
|
|
|
121
|
-
const
|
|
91
|
+
const result = await CapgoLLM.downloadModel({
|
|
92
|
+
url: 'https://huggingface.co/litert-community/gemma-4-E2B-it-litert-lm/resolve/main/gemma-4-E2B-it.litertlm?download=true',
|
|
93
|
+
filename: 'gemma-4-E2B-it.litertlm',
|
|
94
|
+
});
|
|
122
95
|
|
|
123
96
|
await CapgoLLM.setModel({
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
sequenceLength: 2048,
|
|
97
|
+
path: result.path,
|
|
98
|
+
modelType: 'litertlm',
|
|
99
|
+
maxTokens: 4096,
|
|
100
|
+
topk: 40,
|
|
129
101
|
temperature: 0.8,
|
|
130
102
|
});
|
|
131
103
|
|
|
132
|
-
const
|
|
104
|
+
const chat = await CapgoLLM.createChat();
|
|
133
105
|
```
|
|
134
106
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
### MediaPipe Models
|
|
138
|
-
|
|
139
|
-
MediaPipe remains available for existing `.task` models. Android models usually need both `.task` and `.litertlm` files. iOS MediaPipe support is available through CocoaPods and remains experimental for some `.task` files.
|
|
107
|
+
Bundled asset example:
|
|
140
108
|
|
|
141
|
-
```
|
|
109
|
+
```ts
|
|
142
110
|
await CapgoLLM.setModel({
|
|
143
|
-
path: '/android_asset/gemma-
|
|
144
|
-
modelType: '
|
|
145
|
-
maxTokens:
|
|
146
|
-
topk: 40,
|
|
147
|
-
temperature: 0.8,
|
|
111
|
+
path: '/android_asset/gemma-4-E2B-it.litertlm',
|
|
112
|
+
modelType: 'litertlm',
|
|
113
|
+
maxTokens: 4096,
|
|
148
114
|
});
|
|
149
115
|
```
|
|
150
116
|
|
|
151
|
-
|
|
117
|
+
Legacy compatibility:
|
|
152
118
|
|
|
153
|
-
|
|
119
|
+
- Existing Android `.task` models still load through the compatibility path
|
|
120
|
+
- New integrations should prefer `.litertlm`
|
|
154
121
|
|
|
155
|
-
|
|
156
|
-
await CapgoLLM.setModel({
|
|
157
|
-
path: 'Apple Intelligence',
|
|
158
|
-
engine: 'apple',
|
|
159
|
-
});
|
|
160
|
-
```
|
|
122
|
+
### Web
|
|
161
123
|
|
|
162
|
-
|
|
124
|
+
The web implementation uses `@mediapipe/tasks-genai` with web-ready model artifacts.
|
|
163
125
|
|
|
164
|
-
|
|
126
|
+
Gemma 4 web models are published next to the mobile LiteRT-LM bundles and use `*-web.task`.
|
|
165
127
|
|
|
166
|
-
|
|
167
|
-
const result = await CapgoLLM.downloadModel({
|
|
168
|
-
url: 'https://your-server.com/models/model.pte',
|
|
169
|
-
companionUrl: 'https://your-server.com/models/tokenizer.model',
|
|
170
|
-
filename: 'model.pte',
|
|
171
|
-
});
|
|
128
|
+
Example:
|
|
172
129
|
|
|
130
|
+
```ts
|
|
173
131
|
await CapgoLLM.setModel({
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
sequenceLength: 2048,
|
|
132
|
+
path: 'https://huggingface.co/litert-community/gemma-4-E2B-it-litert-lm/resolve/main/gemma-4-E2B-it-web.task?download=true',
|
|
133
|
+
modelType: 'task',
|
|
134
|
+
maxTokens: 4096,
|
|
178
135
|
});
|
|
179
136
|
```
|
|
180
137
|
|
|
181
|
-
## Usage
|
|
138
|
+
## Usage
|
|
182
139
|
|
|
183
|
-
```
|
|
140
|
+
```ts
|
|
184
141
|
import { CapgoLLM } from '@capgo/capacitor-llm';
|
|
185
142
|
|
|
186
143
|
const { readiness } = await CapgoLLM.getReadiness();
|
|
187
144
|
console.log('LLM readiness:', readiness);
|
|
188
145
|
|
|
189
|
-
const { id
|
|
146
|
+
const { id } = await CapgoLLM.createChat();
|
|
190
147
|
|
|
191
|
-
CapgoLLM.addListener('textFromAi', (event) => {
|
|
192
|
-
console.log('
|
|
148
|
+
await CapgoLLM.addListener('textFromAi', (event) => {
|
|
149
|
+
console.log('chunk', event.text);
|
|
193
150
|
});
|
|
194
151
|
|
|
195
|
-
CapgoLLM.addListener('aiFinished', (
|
|
196
|
-
console.log('
|
|
152
|
+
await CapgoLLM.addListener('aiFinished', ({ chatId }) => {
|
|
153
|
+
console.log('finished', chatId);
|
|
197
154
|
});
|
|
198
155
|
|
|
199
156
|
await CapgoLLM.sendMessage({
|
|
200
|
-
chatId,
|
|
201
|
-
message: '
|
|
157
|
+
chatId: id,
|
|
158
|
+
message: 'Explain why local inference is useful on mobile.',
|
|
202
159
|
});
|
|
203
160
|
```
|
|
204
161
|
|
|
205
|
-
##
|
|
162
|
+
## Notes
|
|
163
|
+
|
|
164
|
+
- Android now prefers LiteRT-LM and Gemma 4 style `.litertlm` bundles.
|
|
165
|
+
- iOS LiteRT-LM custom-model support now uses the official LiteRT-LM Swift API and prebuilt iOS binaries, and is available only in SwiftPM integrations of this plugin.
|
|
166
|
+
- CocoaPods builds on iOS should use Apple Intelligence or the legacy MediaPipe `.task` compatibility path.
|
|
167
|
+
- Web uses Gemma 4 `*-web.task` artifacts through `@mediapipe/tasks-genai`.
|
|
168
|
+
- Apple Intelligence remains the preferred default on iOS where available.
|
|
206
169
|
|
|
207
170
|
<docgen-index>
|
|
208
171
|
|
|
@@ -213,6 +176,7 @@ await CapgoLLM.sendMessage({
|
|
|
213
176
|
* [`downloadModel(...)`](#downloadmodel)
|
|
214
177
|
* [`addListener('textFromAi', ...)`](#addlistenertextfromai-)
|
|
215
178
|
* [`addListener('aiFinished', ...)`](#addlisteneraifinished-)
|
|
179
|
+
* [`addListener('generationError', ...)`](#addlistenergenerationerror-)
|
|
216
180
|
* [`addListener('downloadProgress', ...)`](#addlistenerdownloadprogress-)
|
|
217
181
|
* [`addListener('readinessChange', ...)`](#addlistenerreadinesschange-)
|
|
218
182
|
* [`getPluginVersion()`](#getpluginversion)
|
|
@@ -273,8 +237,9 @@ setModel(options: ModelOptions) => Promise<void>
|
|
|
273
237
|
```
|
|
274
238
|
|
|
275
239
|
Sets the model configuration
|
|
276
|
-
- iOS: Use "Apple Intelligence" as path for system model
|
|
277
|
-
- Android:
|
|
240
|
+
- iOS: Use "Apple Intelligence" as path for the system model. Custom LiteRT-LM `.litertlm` models are supported on iOS only when this plugin is integrated through Swift Package Manager.
|
|
241
|
+
- Android: Use "Gemini Nano" for the AICore system model on supported devices where it is already available. Prefer LiteRT-LM `.litertlm` bundles for custom models; legacy MediaPipe `.task` models are still supported
|
|
242
|
+
- Web: Provide a web-ready model asset for `@mediapipe/tasks-genai` such as Gemma 4 `*-web.task`
|
|
278
243
|
|
|
279
244
|
| Param | Type | Description |
|
|
280
245
|
| ------------- | ----------------------------------------------------- | ------------------------- |
|
|
@@ -338,6 +303,24 @@ Adds a listener for AI completion events
|
|
|
338
303
|
--------------------
|
|
339
304
|
|
|
340
305
|
|
|
306
|
+
### addListener('generationError', ...)
|
|
307
|
+
|
|
308
|
+
```typescript
|
|
309
|
+
addListener(eventName: 'generationError', listenerFunc: (event: GenerationErrorEvent) => void) => Promise<{ remove: () => Promise<void>; }>
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
Adds a listener for generation failures that happen after streaming starts
|
|
313
|
+
|
|
314
|
+
| Param | Type | Description |
|
|
315
|
+
| ------------------ | ----------------------------------------------------------------------------------------- | ----------------------------------------- |
|
|
316
|
+
| **`eventName`** | <code>'generationError'</code> | - Event name 'generationError' |
|
|
317
|
+
| **`listenerFunc`** | <code>(event: <a href="#generationerrorevent">GenerationErrorEvent</a>) => void</code> | - Callback function for generation errors |
|
|
318
|
+
|
|
319
|
+
**Returns:** <code>Promise<{ remove: () => Promise<void>; }></code>
|
|
320
|
+
|
|
321
|
+
--------------------
|
|
322
|
+
|
|
323
|
+
|
|
341
324
|
### addListener('downloadProgress', ...)
|
|
342
325
|
|
|
343
326
|
```typescript
|
|
@@ -395,19 +378,16 @@ Get the native Capacitor plugin version.
|
|
|
395
378
|
#### ModelOptions
|
|
396
379
|
|
|
397
380
|
Model configuration options
|
|
381
|
+
Only `path` is required. All other properties are optional overrides.
|
|
398
382
|
|
|
399
|
-
| Prop
|
|
400
|
-
|
|
|
401
|
-
| **`path`**
|
|
402
|
-
| **`
|
|
403
|
-
| **`
|
|
404
|
-
| **`
|
|
405
|
-
| **`
|
|
406
|
-
| **`
|
|
407
|
-
| **`sequenceLength`** | <code>number</code> | Sequence length for ExecuTorch generation. Defaults to maxTokens when omitted. |
|
|
408
|
-
| **`topk`** | <code>number</code> | Number of tokens the model considers at each step |
|
|
409
|
-
| **`temperature`** | <code>number</code> | Amount of randomness in generation (0.0-1.0) |
|
|
410
|
-
| **`randomSeed`** | <code>number</code> | Random seed for generation |
|
|
383
|
+
| Prop | Type | Description |
|
|
384
|
+
| ----------------- | ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
385
|
+
| **`path`** | <code>string</code> | Model path, "Apple Intelligence" for the Apple system model on iOS, or "Gemini Nano" for the Android AICore system model when already available on the device. On iOS, custom `.litertlm` models require the plugin to be integrated through Swift Package Manager. Gemma 4 examples use `.litertlm` on mobile and `*-web.task` on web. |
|
|
386
|
+
| **`modelType`** | <code>string</code> | Optional. Model file type/extension (for example `task`, `bin`, `litertlm`, or `gemini-nano`). If not provided, it is extracted from the path. Use `litertlm` on iOS only in SwiftPM integrations. |
|
|
387
|
+
| **`maxTokens`** | <code>number</code> | Maximum number of tokens the model handles |
|
|
388
|
+
| **`topk`** | <code>number</code> | Number of tokens the model considers at each step |
|
|
389
|
+
| **`temperature`** | <code>number</code> | Amount of randomness in generation (0.0-1.0) |
|
|
390
|
+
| **`randomSeed`** | <code>number</code> | Optional. Random seed for generation. |
|
|
411
391
|
|
|
412
392
|
|
|
413
393
|
#### DownloadModelResult
|
|
@@ -423,12 +403,13 @@ Result of model download
|
|
|
423
403
|
#### DownloadModelOptions
|
|
424
404
|
|
|
425
405
|
Options for downloading a model
|
|
406
|
+
Only `url` is required. `companionUrl` and `filename` are optional.
|
|
426
407
|
|
|
427
|
-
| Prop | Type | Description
|
|
428
|
-
| ------------------ | ------------------- |
|
|
429
|
-
| **`url`** | <code>string</code> | URL of the model file to download
|
|
430
|
-
| **`companionUrl`** | <code>string</code> | Optional: URL of companion file
|
|
431
|
-
| **`filename`** | <code>string</code> | Optional: Custom filename (defaults to filename from URL)
|
|
408
|
+
| Prop | Type | Description |
|
|
409
|
+
| ------------------ | ------------------- | ---------------------------------------------------------- |
|
|
410
|
+
| **`url`** | <code>string</code> | URL of the model file to download |
|
|
411
|
+
| **`companionUrl`** | <code>string</code> | Optional: URL of a companion file for legacy model formats |
|
|
412
|
+
| **`filename`** | <code>string</code> | Optional: Custom filename (defaults to filename from URL) |
|
|
432
413
|
|
|
433
414
|
|
|
434
415
|
#### TextFromAiEvent
|
|
@@ -451,6 +432,17 @@ Event data for AI completion
|
|
|
451
432
|
| **`chatId`** | <code>string</code> | The chat session ID that finished |
|
|
452
433
|
|
|
453
434
|
|
|
435
|
+
#### GenerationErrorEvent
|
|
436
|
+
|
|
437
|
+
Event data for generation failures
|
|
438
|
+
`chatId` is optional and may be omitted when the failure is not tied to a specific chat.
|
|
439
|
+
|
|
440
|
+
| Prop | Type | Description |
|
|
441
|
+
| ------------ | ------------------- | ---------------------------------------------------------- |
|
|
442
|
+
| **`chatId`** | <code>string</code> | Optional. The chat session ID that failed, when available. |
|
|
443
|
+
| **`error`** | <code>string</code> | Error message describing the failure |
|
|
444
|
+
|
|
445
|
+
|
|
454
446
|
#### DownloadProgressEvent
|
|
455
447
|
|
|
456
448
|
Event data for download progress
|
|
@@ -472,29 +464,11 @@ Event data for readiness status changes
|
|
|
472
464
|
|
|
473
465
|
</docgen-api>
|
|
474
466
|
|
|
475
|
-
## Example App
|
|
476
|
-
|
|
477
|
-
The example app can use either the older MediaPipe assets or the new ExecuTorch assets.
|
|
478
|
-
|
|
479
|
-
### Recommended Custom Path: ExecuTorch
|
|
480
|
-
|
|
481
|
-
1. Export or download an ExecuTorch `.pte` model and matching tokenizer file.
|
|
482
|
-
2. Add both files to the iOS app bundle, or place both files in `example-app/android/app/src/main/assets/` for Android.
|
|
483
|
-
3. Call `setModel` with `engine: 'executorch'`, `path`, and `tokenizerPath`.
|
|
484
|
-
|
|
485
|
-
### Legacy MediaPipe Path
|
|
486
|
-
|
|
487
|
-
Android still supports Gemma 3 LiteRT assets from Kaggle. Download both files and place them in `example-app/android/app/src/main/assets/`:
|
|
488
|
-
|
|
489
|
-
- `gemma-3-270m-it-int8.task`
|
|
490
|
-
- `gemma-3-270m-it-int8.litertlm`
|
|
467
|
+
## Example App
|
|
491
468
|
|
|
492
|
-
|
|
469
|
+
The repo includes an `example-app/` that demonstrates:
|
|
493
470
|
|
|
494
|
-
|
|
471
|
+
- Apple Intelligence on iOS
|
|
472
|
+
- Gemma 4 LiteRT-LM model downloads on Android
|
|
495
473
|
|
|
496
|
-
|
|
497
|
-
- iOS ExecuTorch requires linking the ExecuTorch SwiftPM products in the app target, and that app target must support iOS 17 or newer.
|
|
498
|
-
- Apple Intelligence requires iOS 26.0 or later and a supported device.
|
|
499
|
-
- Android requires minSdkVersion 24 or higher.
|
|
500
|
-
- Model files are large, so production apps should usually download them after install.
|
|
474
|
+
See [example-app/README.md](./example-app/README.md) for local setup instructions.
|
package/android/build.gradle
CHANGED
|
@@ -52,8 +52,9 @@ dependencies {
|
|
|
52
52
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
53
|
implementation project(':capacitor-android')
|
|
54
54
|
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
-
implementation 'com.google.
|
|
56
|
-
implementation '
|
|
55
|
+
implementation 'com.google.ai.edge.litertlm:litertlm-android:0.10.0'
|
|
56
|
+
implementation 'com.google.mediapipe:tasks-genai:0.10.24'
|
|
57
|
+
implementation 'com.google.mlkit:genai-prompt:1.0.0-beta2'
|
|
57
58
|
testImplementation "junit:junit:$junitVersion"
|
|
58
59
|
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
59
60
|
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|