@runanywhere/llamacpp 0.18.0 → 0.19.13
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/README.md +85 -413
- package/RunAnywhereLlama.podspec +27 -13
- package/android/CMakeLists.txt +37 -20
- package/android/build.gradle +83 -8
- package/cpp/HybridRunAnywhereLlama.cpp +26 -269
- package/cpp/HybridRunAnywhereLlama.hpp +2 -58
- package/ios/{Frameworks → Binaries}/RABackendLLAMACPP.xcframework/Info.plist +8 -9
- package/ios/{Frameworks/RABackendLLAMACPP.xcframework/ios-arm64/RABackendLLAMACPP.framework/RABackendLLAMACPP → Binaries/RABackendLLAMACPP.xcframework/ios-arm64/librac_backend_llamacpp.a} +0 -0
- package/ios/{Frameworks/RABackendLLAMACPP.xcframework/ios-arm64_x86_64-simulator/RABackendLLAMACPP.framework/RABackendLLAMACPP → Binaries/RABackendLLAMACPP.xcframework/ios-arm64-simulator/librac_backend_llamacpp.a} +0 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/runanywhere/llama/runanywherellamaOnLoad.kt +1 -1
- package/nitrogen/generated/android/runanywherellama+autolinking.cmake +2 -2
- package/nitrogen/generated/android/runanywherellama+autolinking.gradle +1 -1
- package/nitrogen/generated/android/runanywherellamaOnLoad.cpp +23 -18
- package/nitrogen/generated/android/runanywherellamaOnLoad.hpp +14 -5
- package/nitrogen/generated/ios/RunAnywhereLlama+autolinking.rb +4 -2
- package/nitrogen/generated/ios/RunAnywhereLlama-Swift-Cxx-Bridge.cpp +2 -2
- package/nitrogen/generated/ios/RunAnywhereLlama-Swift-Cxx-Bridge.hpp +2 -2
- package/nitrogen/generated/ios/RunAnywhereLlama-Swift-Cxx-Umbrella.hpp +1 -1
- package/nitrogen/generated/ios/RunAnywhereLlamaAutolinking.mm +1 -1
- package/nitrogen/generated/ios/RunAnywhereLlamaAutolinking.swift +6 -2
- package/nitrogen/generated/shared/c++/HybridRunAnywhereLlamaSpec.cpp +1 -11
- package/nitrogen/generated/shared/c++/HybridRunAnywhereLlamaSpec.hpp +2 -15
- package/package.json +13 -10
- package/react-native.config.js +1 -3
- package/src/LlamaCPP.ts +32 -160
- package/src/LlamaCppProvider.ts +32 -36
- package/src/index.ts +18 -23
- package/src/native/NativeRunAnywhereLlama.ts +19 -5
- package/src/specs/RunAnywhereLlama.nitro.ts +17 -126
- package/android/src/main/AndroidManifest.xml +0 -3
- package/android/src/main/cpp/cpp-adapter.cpp +0 -14
- package/android/src/main/include/rac/backends/rac_llm_llamacpp.h +0 -218
- package/android/src/main/include/rac/backends/rac_stt_onnx.h +0 -99
- package/android/src/main/include/rac/backends/rac_stt_whispercpp.h +0 -153
- package/android/src/main/include/rac/backends/rac_tts_onnx.h +0 -71
- package/android/src/main/include/rac/backends/rac_vad_onnx.h +0 -84
- package/android/src/main/include/rac/core/capabilities/rac_lifecycle.h +0 -290
- package/android/src/main/include/rac/core/rac_analytics_events.h +0 -610
- package/android/src/main/include/rac/core/rac_audio_utils.h +0 -88
- package/android/src/main/include/rac/core/rac_component_types.h +0 -160
- package/android/src/main/include/rac/core/rac_core.h +0 -331
- package/android/src/main/include/rac/core/rac_error.h +0 -469
- package/android/src/main/include/rac/core/rac_events.h +0 -334
- package/android/src/main/include/rac/core/rac_logger.h +0 -416
- package/android/src/main/include/rac/core/rac_platform_adapter.h +0 -340
- package/android/src/main/include/rac/core/rac_sdk_state.h +0 -292
- package/android/src/main/include/rac/core/rac_structured_error.h +0 -594
- package/android/src/main/include/rac/core/rac_types.h +0 -264
- package/android/src/main/include/rac/features/llm/rac_llm.h +0 -17
- package/android/src/main/include/rac/features/llm/rac_llm_analytics.h +0 -188
- package/android/src/main/include/rac/features/llm/rac_llm_component.h +0 -228
- package/android/src/main/include/rac/features/llm/rac_llm_events.h +0 -215
- package/android/src/main/include/rac/features/llm/rac_llm_metrics.h +0 -402
- package/android/src/main/include/rac/features/llm/rac_llm_service.h +0 -163
- package/android/src/main/include/rac/features/llm/rac_llm_structured_output.h +0 -141
- package/android/src/main/include/rac/features/llm/rac_llm_types.h +0 -384
- package/android/src/main/include/rac/features/platform/rac_llm_platform.h +0 -204
- package/android/src/main/include/rac/features/platform/rac_tts_platform.h +0 -197
- package/android/src/main/include/rac/features/stt/rac_stt.h +0 -17
- package/android/src/main/include/rac/features/stt/rac_stt_analytics.h +0 -204
- package/android/src/main/include/rac/features/stt/rac_stt_component.h +0 -162
- package/android/src/main/include/rac/features/stt/rac_stt_events.h +0 -62
- package/android/src/main/include/rac/features/stt/rac_stt_service.h +0 -154
- package/android/src/main/include/rac/features/stt/rac_stt_types.h +0 -389
- package/android/src/main/include/rac/features/tts/rac_tts.h +0 -17
- package/android/src/main/include/rac/features/tts/rac_tts_analytics.h +0 -181
- package/android/src/main/include/rac/features/tts/rac_tts_component.h +0 -158
- package/android/src/main/include/rac/features/tts/rac_tts_events.h +0 -54
- package/android/src/main/include/rac/features/tts/rac_tts_service.h +0 -162
- package/android/src/main/include/rac/features/tts/rac_tts_types.h +0 -374
- package/android/src/main/include/rac/features/vad/rac_vad.h +0 -17
- package/android/src/main/include/rac/features/vad/rac_vad_analytics.h +0 -236
- package/android/src/main/include/rac/features/vad/rac_vad_component.h +0 -185
- package/android/src/main/include/rac/features/vad/rac_vad_energy.h +0 -443
- package/android/src/main/include/rac/features/vad/rac_vad_events.h +0 -76
- package/android/src/main/include/rac/features/vad/rac_vad_service.h +0 -167
- package/android/src/main/include/rac/features/vad/rac_vad_types.h +0 -244
- package/android/src/main/include/rac/features/voice_agent/rac_voice_agent.h +0 -612
- package/android/src/main/include/rac/infrastructure/device/rac_device_manager.h +0 -176
- package/android/src/main/include/rac/infrastructure/download/rac_download.h +0 -418
- package/android/src/main/include/rac/infrastructure/events/rac_events.h +0 -177
- package/android/src/main/include/rac/infrastructure/model_management/rac_model_assignment.h +0 -169
- package/android/src/main/include/rac/infrastructure/model_management/rac_model_paths.h +0 -258
- package/android/src/main/include/rac/infrastructure/model_management/rac_model_registry.h +0 -357
- package/android/src/main/include/rac/infrastructure/model_management/rac_model_strategy.h +0 -374
- package/android/src/main/include/rac/infrastructure/model_management/rac_model_types.h +0 -613
- package/android/src/main/include/rac/infrastructure/network/rac_api_types.h +0 -335
- package/android/src/main/include/rac/infrastructure/network/rac_auth_manager.h +0 -252
- package/android/src/main/include/rac/infrastructure/network/rac_dev_config.h +0 -85
- package/android/src/main/include/rac/infrastructure/network/rac_endpoints.h +0 -102
- package/android/src/main/include/rac/infrastructure/network/rac_environment.h +0 -220
- package/android/src/main/include/rac/infrastructure/network/rac_http_client.h +0 -233
- package/android/src/main/include/rac/infrastructure/storage/rac_storage_analyzer.h +0 -286
- package/android/src/main/include/rac/infrastructure/telemetry/rac_telemetry_manager.h +0 -206
- package/android/src/main/include/rac/infrastructure/telemetry/rac_telemetry_types.h +0 -234
- package/android/src/main/java/com/margelo/nitro/runanywhere/llama/RunAnywhereLlamaPackage.kt +0 -35
- package/android/src/main/jniLibs/arm64-v8a/libomp.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/librac_backend_llamacpp.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/librac_backend_llamacpp_jni.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/librac_commons.so +0 -0
- package/android/src/main/jniLibs/x86_64/libomp.so +0 -0
- package/android/src/main/jniLibs/x86_64/librac_backend_llamacpp.so +0 -0
- package/android/src/main/jniLibs/x86_64/librac_backend_llamacpp_jni.so +0 -0
- package/android/src/main/jniLibs/x86_64/librac_commons.so +0 -0
- package/cpp/bridges/LLMBridge.cpp +0 -209
- package/cpp/bridges/LLMBridge.hpp +0 -109
- package/cpp/bridges/StructuredOutputBridge.cpp +0 -151
- package/cpp/bridges/StructuredOutputBridge.hpp +0 -66
- package/cpp/rac_llm_llamacpp.h +0 -34
- package/ios/Frameworks/RABackendLLAMACPP.xcframework/ios-arm64/RABackendLLAMACPP.framework/Headers/RABackendLLAMACPP.h +0 -2
- package/ios/Frameworks/RABackendLLAMACPP.xcframework/ios-arm64/RABackendLLAMACPP.framework/Info.plist +0 -11
- package/ios/Frameworks/RABackendLLAMACPP.xcframework/ios-arm64/RABackendLLAMACPP.framework/Modules/module.modulemap +0 -5
- package/ios/Frameworks/RABackendLLAMACPP.xcframework/ios-arm64_x86_64-simulator/RABackendLLAMACPP.framework/Headers/RABackendLLAMACPP.h +0 -2
- package/ios/Frameworks/RABackendLLAMACPP.xcframework/ios-arm64_x86_64-simulator/RABackendLLAMACPP.framework/Info.plist +0 -11
- package/ios/Frameworks/RABackendLLAMACPP.xcframework/ios-arm64_x86_64-simulator/RABackendLLAMACPP.framework/Modules/module.modulemap +0 -5
- package/ios/LlamaCPPBackend.podspec +0 -127
package/README.md
CHANGED
|
@@ -1,479 +1,151 @@
|
|
|
1
1
|
# @runanywhere/llamacpp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Llama.cpp backend registration package for the RunAnywhere React Native SDK.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
`@runanywhere/llamacpp`
|
|
10
|
-
|
|
11
|
-
- **Text Generation** — Generate text responses from prompts
|
|
12
|
-
- **Streaming** — Real-time token-by-token output
|
|
13
|
-
- **Tool Calling** — Let models invoke registered tools during generation
|
|
14
|
-
- **Structured Output** — Generate type-safe JSON responses
|
|
15
|
-
- **GGUF Support** — Run any GGUF-format model (Llama, Mistral, Qwen, SmolLM, etc.)
|
|
16
|
-
- **Metal GPU Acceleration** — 3-5x faster inference on Apple Silicon (iOS)
|
|
17
|
-
- **CPU Inference** — Works on all devices without GPU requirements
|
|
18
|
-
- **Memory Efficient** — Quantized models (Q4, Q6, Q8) for reduced memory usage
|
|
19
|
-
|
|
20
|
-
---
|
|
5
|
+
This package does not own public model catalog, download, lifecycle,
|
|
6
|
+
generation, VLM, LoRA, tool-calling, or structured-output APIs. Those surfaces
|
|
7
|
+
live in `@runanywhere/core` over the generated proto/Nitro/commons bridge,
|
|
8
|
+
mirroring the Swift architecture source of truth.
|
|
9
|
+
`@runanywhere/llamacpp` only installs or removes the native llama.cpp backend
|
|
10
|
+
providers and ships the `RABackendLLAMACPP` native binary.
|
|
21
11
|
|
|
22
12
|
## Requirements
|
|
23
13
|
|
|
24
|
-
- `@runanywhere/core`
|
|
14
|
+
- `@runanywhere/core` peer dependency
|
|
25
15
|
- React Native 0.74+
|
|
26
|
-
- iOS
|
|
27
|
-
|
|
28
|
-
---
|
|
16
|
+
- iOS 17.0+ / Android API 24+
|
|
29
17
|
|
|
30
18
|
## Installation
|
|
31
19
|
|
|
32
20
|
```bash
|
|
33
21
|
npm install @runanywhere/core @runanywhere/llamacpp
|
|
34
|
-
# or
|
|
35
|
-
yarn add @runanywhere/core @runanywhere/llamacpp
|
|
36
22
|
```
|
|
37
23
|
|
|
38
|
-
|
|
24
|
+
For iOS, run CocoaPods from the app:
|
|
39
25
|
|
|
40
26
|
```bash
|
|
41
27
|
cd ios && pod install && cd ..
|
|
42
28
|
```
|
|
43
29
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
No additional setup required. Native libraries are downloaded automatically.
|
|
47
|
-
|
|
48
|
-
---
|
|
30
|
+
Android native libraries are packaged by the React Native package.
|
|
49
31
|
|
|
50
|
-
##
|
|
51
|
-
|
|
52
|
-
```typescript
|
|
53
|
-
import { RunAnywhere, SDKEnvironment, ModelCategory } from '@runanywhere/core';
|
|
54
|
-
import { LlamaCPP } from '@runanywhere/llamacpp';
|
|
55
|
-
|
|
56
|
-
// 1. Initialize SDK
|
|
57
|
-
await RunAnywhere.initialize({
|
|
58
|
-
environment: SDKEnvironment.Development,
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
// 2. Register LlamaCPP backend
|
|
62
|
-
LlamaCPP.register();
|
|
63
|
-
|
|
64
|
-
// 3. Add a model
|
|
65
|
-
await LlamaCPP.addModel({
|
|
66
|
-
id: 'smollm2-360m-q8_0',
|
|
67
|
-
name: 'SmolLM2 360M Q8_0',
|
|
68
|
-
url: 'https://huggingface.co/prithivMLmods/SmolLM2-360M-GGUF/resolve/main/SmolLM2-360M.Q8_0.gguf',
|
|
69
|
-
memoryRequirement: 500_000_000,
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// 4. Download model
|
|
73
|
-
await RunAnywhere.downloadModel('smollm2-360m-q8_0', (progress) => {
|
|
74
|
-
console.log(`Downloading: ${(progress.progress * 100).toFixed(1)}%`);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// 5. Load model
|
|
78
|
-
const modelInfo = await RunAnywhere.getModelInfo('smollm2-360m-q8_0');
|
|
79
|
-
await RunAnywhere.loadModel(modelInfo.localPath);
|
|
80
|
-
|
|
81
|
-
// 6. Generate text
|
|
82
|
-
const response = await RunAnywhere.chat('What is the capital of France?');
|
|
83
|
-
console.log(response);
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
---
|
|
87
|
-
|
|
88
|
-
## API Reference
|
|
89
|
-
|
|
90
|
-
### LlamaCPP Module
|
|
32
|
+
## Usage
|
|
91
33
|
|
|
92
34
|
```typescript
|
|
35
|
+
import { RunAnywhere } from '@runanywhere/core';
|
|
36
|
+
import {
|
|
37
|
+
InferenceFramework,
|
|
38
|
+
ModelCategory,
|
|
39
|
+
ModelLoadRequest,
|
|
40
|
+
} from '@runanywhere/proto-ts/model_types';
|
|
93
41
|
import { LlamaCPP } from '@runanywhere/llamacpp';
|
|
94
|
-
```
|
|
95
42
|
|
|
96
|
-
|
|
43
|
+
await RunAnywhere.initialize();
|
|
97
44
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
LlamaCPP.register(): void
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
**Example:**
|
|
105
|
-
|
|
106
|
-
```typescript
|
|
107
|
-
await RunAnywhere.initialize({ ... });
|
|
108
|
-
LlamaCPP.register(); // Now LLM features are available
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
---
|
|
112
|
-
|
|
113
|
-
#### `LlamaCPP.addModel(options)`
|
|
114
|
-
|
|
115
|
-
Add a GGUF model to the model registry.
|
|
116
|
-
|
|
117
|
-
```typescript
|
|
118
|
-
await LlamaCPP.addModel(options: LlamaCPPModelOptions): Promise<ModelInfo>
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
**Parameters:**
|
|
122
|
-
|
|
123
|
-
```typescript
|
|
124
|
-
interface LlamaCPPModelOptions {
|
|
125
|
-
/**
|
|
126
|
-
* Unique model ID.
|
|
127
|
-
* If not provided, generated from the URL filename.
|
|
128
|
-
*/
|
|
129
|
-
id?: string;
|
|
130
|
-
|
|
131
|
-
/** Display name for the model */
|
|
132
|
-
name: string;
|
|
133
|
-
|
|
134
|
-
/** Download URL for the model (GGUF format) */
|
|
135
|
-
url: string;
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Model category.
|
|
139
|
-
* Default: ModelCategory.Language
|
|
140
|
-
*/
|
|
141
|
-
modality?: ModelCategory;
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Memory requirement in bytes.
|
|
145
|
-
* Used for device capability checks.
|
|
146
|
-
*/
|
|
147
|
-
memoryRequirement?: number;
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Whether model supports reasoning/thinking tokens.
|
|
151
|
-
* If true, thinking content is extracted from responses.
|
|
152
|
-
*/
|
|
153
|
-
supportsThinking?: boolean;
|
|
45
|
+
const registered = await LlamaCPP.register();
|
|
46
|
+
if (!registered) {
|
|
47
|
+
throw new Error('llama.cpp backend is not available');
|
|
154
48
|
}
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
**Returns:** `Promise<ModelInfo>` — The registered model info
|
|
158
49
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
```typescript
|
|
162
|
-
// Basic model
|
|
163
|
-
await LlamaCPP.addModel({
|
|
50
|
+
await RunAnywhere.registerModel({
|
|
164
51
|
id: 'smollm2-360m-q8_0',
|
|
165
52
|
name: 'SmolLM2 360M Q8_0',
|
|
166
|
-
|
|
167
|
-
|
|
53
|
+
framework: InferenceFramework.INFERENCE_FRAMEWORK_LLAMA_CPP,
|
|
54
|
+
url: 'https://example.invalid/model.gguf',
|
|
168
55
|
});
|
|
169
56
|
|
|
170
|
-
|
|
171
|
-
await
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
});
|
|
57
|
+
const download = RunAnywhere.downloadModel('smollm2-360m-q8_0')[Symbol.asyncIterator]();
|
|
58
|
+
while (!(await download.next()).done) {}
|
|
59
|
+
await RunAnywhere.loadModel(ModelLoadRequest.fromPartial({
|
|
60
|
+
modelId: 'smollm2-360m-q8_0',
|
|
61
|
+
category: ModelCategory.MODEL_CATEGORY_LANGUAGE,
|
|
62
|
+
}));
|
|
177
63
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
id: 'deepseek-r1-distill-qwen-1.5b',
|
|
181
|
-
name: 'DeepSeek R1 Distill Qwen 1.5B',
|
|
182
|
-
url: 'https://huggingface.co/.../deepseek-r1-distill-qwen-1.5b-q8_0.gguf',
|
|
183
|
-
memoryRequirement: 2_000_000_000,
|
|
184
|
-
supportsThinking: true,
|
|
185
|
-
});
|
|
64
|
+
const result = await RunAnywhere.generate('Write one sentence about local AI.');
|
|
65
|
+
console.log(result.text);
|
|
186
66
|
```
|
|
187
67
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
#### Module Properties
|
|
68
|
+
## Public API
|
|
191
69
|
|
|
192
70
|
```typescript
|
|
193
|
-
LlamaCPP
|
|
194
|
-
LlamaCPP.moduleName // 'LlamaCPP'
|
|
195
|
-
LlamaCPP.inferenceFramework // LLMFramework.LlamaCpp
|
|
196
|
-
LlamaCPP.capabilities // ['llm']
|
|
197
|
-
LlamaCPP.defaultPriority // 100
|
|
71
|
+
import { LlamaCPP } from '@runanywhere/llamacpp';
|
|
198
72
|
```
|
|
199
73
|
|
|
200
|
-
|
|
74
|
+
`LlamaCppProvider` remains exported for lower-level compatibility, but app code
|
|
75
|
+
should use `LlamaCPP`. Neither surface owns model lifecycle or inference APIs.
|
|
201
76
|
|
|
202
|
-
###
|
|
77
|
+
### `LlamaCPP.register()`
|
|
203
78
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
#### Simple Chat
|
|
79
|
+
Registers llama.cpp LLM and VLM providers with the native backend registry.
|
|
207
80
|
|
|
208
81
|
```typescript
|
|
209
|
-
|
|
210
|
-
console.log(response);
|
|
82
|
+
LlamaCPP.register(): Promise<boolean>
|
|
211
83
|
```
|
|
212
84
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
```typescript
|
|
216
|
-
const result = await RunAnywhere.generate(
|
|
217
|
-
'Explain machine learning in simple terms',
|
|
218
|
-
{
|
|
219
|
-
maxTokens: 256,
|
|
220
|
-
temperature: 0.7,
|
|
221
|
-
topP: 0.95,
|
|
222
|
-
systemPrompt: 'You are a helpful teacher.',
|
|
223
|
-
stopSequences: ['\n\n'],
|
|
224
|
-
}
|
|
225
|
-
);
|
|
226
|
-
|
|
227
|
-
console.log('Response:', result.text);
|
|
228
|
-
console.log('Tokens:', result.tokensUsed);
|
|
229
|
-
console.log('Speed:', result.performanceMetrics.tokensPerSecond, 'tok/s');
|
|
230
|
-
console.log('TTFT:', result.performanceMetrics.timeToFirstTokenMs, 'ms');
|
|
231
|
-
```
|
|
85
|
+
### `LlamaCPP.unregister()`
|
|
232
86
|
|
|
233
|
-
|
|
87
|
+
Unregisters llama.cpp LLM and VLM providers. Core-owned model lifecycle handles
|
|
88
|
+
remain owned by core.
|
|
234
89
|
|
|
235
90
|
```typescript
|
|
236
|
-
|
|
237
|
-
'Write a story about a robot',
|
|
238
|
-
{ maxTokens: 500 }
|
|
239
|
-
);
|
|
240
|
-
|
|
241
|
-
// Display tokens as they're generated
|
|
242
|
-
for await (const token of streamResult.stream) {
|
|
243
|
-
process.stdout.write(token);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// Get final metrics
|
|
247
|
-
const result = await streamResult.result;
|
|
248
|
-
console.log('\nSpeed:', result.performanceMetrics.tokensPerSecond, 'tok/s');
|
|
91
|
+
LlamaCPP.unregister(): Promise<boolean>
|
|
249
92
|
```
|
|
250
93
|
|
|
251
|
-
|
|
94
|
+
### `LlamaCPP.isRegistered()`
|
|
252
95
|
|
|
253
|
-
|
|
96
|
+
Checks native backend registration state.
|
|
254
97
|
|
|
255
98
|
```typescript
|
|
256
|
-
|
|
257
|
-
import { LlamaCPP } from '@runanywhere/llamacpp';
|
|
258
|
-
|
|
259
|
-
// Register a tool
|
|
260
|
-
RunAnywhere.registerTool(
|
|
261
|
-
{
|
|
262
|
-
name: 'calculate',
|
|
263
|
-
description: 'Perform a math calculation',
|
|
264
|
-
parameters: [
|
|
265
|
-
{ name: 'expression', type: 'string', description: 'Math expression', required: true },
|
|
266
|
-
],
|
|
267
|
-
},
|
|
268
|
-
async (args) => {
|
|
269
|
-
const result = eval(args.expression as string); // simplified example
|
|
270
|
-
return { result };
|
|
271
|
-
}
|
|
272
|
-
);
|
|
273
|
-
|
|
274
|
-
// Generate with tools
|
|
275
|
-
const result = await RunAnywhere.generateWithTools(
|
|
276
|
-
'What is 42 * 17?',
|
|
277
|
-
{
|
|
278
|
-
autoExecute: true,
|
|
279
|
-
maxToolCalls: 3,
|
|
280
|
-
temperature: 0.7,
|
|
281
|
-
format: 'default', // 'default' for most models, 'lfm2' for Liquid AI models
|
|
282
|
-
}
|
|
283
|
-
);
|
|
284
|
-
console.log(result.text); // "42 * 17 = 714"
|
|
99
|
+
LlamaCPP.isRegistered(): Promise<boolean>
|
|
285
100
|
```
|
|
286
101
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
| Format | Tag Pattern | Models |
|
|
290
|
-
|--------|-------------|--------|
|
|
291
|
-
| `default` | `<tool_call>{"tool":"name","arguments":{}}</tool_call>` | Llama, Qwen, Mistral, SmolLM, most GGUF models |
|
|
292
|
-
| `lfm2` | `<\|tool_call_start\|>[func(arg="val")]<\|tool_call_end\|>` | Liquid AI LFM2-Tool models |
|
|
293
|
-
|
|
294
|
-
---
|
|
295
|
-
|
|
296
|
-
#### Model Management
|
|
102
|
+
### Metadata
|
|
297
103
|
|
|
298
104
|
```typescript
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
// Unload to free memory
|
|
306
|
-
await RunAnywhere.unloadModel();
|
|
307
|
-
|
|
308
|
-
// Cancel ongoing generation
|
|
309
|
-
await RunAnywhere.cancelGeneration();
|
|
105
|
+
LlamaCPP.moduleId
|
|
106
|
+
LlamaCPP.moduleName
|
|
107
|
+
LlamaCPP.inferenceFramework
|
|
108
|
+
LlamaCPP.capabilities
|
|
109
|
+
LlamaCPP.defaultPriority
|
|
310
110
|
```
|
|
311
111
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
## Supported Models
|
|
315
|
-
|
|
316
|
-
Any GGUF-format model works with this backend. Recommended models:
|
|
317
|
-
|
|
318
|
-
### Small Models (< 1GB RAM)
|
|
319
|
-
|
|
320
|
-
| Model | Size | Memory | Tool Calling | Description |
|
|
321
|
-
|-------|------|--------|:------------:|-------------|
|
|
322
|
-
| SmolLM2 360M Q8_0 | ~400MB | 500MB | - | Fast, lightweight |
|
|
323
|
-
| Qwen 2.5 0.5B Q6_K | ~500MB | 600MB | Yes | Multilingual |
|
|
324
|
-
| LFM2 350M Q4_K_M | ~200MB | 250MB | Yes (lfm2) | Ultra-compact, Liquid AI |
|
|
325
|
-
|
|
326
|
-
### Medium Models (1-3GB RAM)
|
|
327
|
-
|
|
328
|
-
| Model | Size | Memory | Tool Calling | Description |
|
|
329
|
-
|-------|------|--------|:------------:|-------------|
|
|
330
|
-
| Phi-3 Mini Q4_K_M | ~2GB | 2.5GB | - | Microsoft |
|
|
331
|
-
| Gemma 2B Q4_K_M | ~1.5GB | 2GB | - | Google |
|
|
332
|
-
| LFM2 1.2B Q4_K_M | ~800MB | 1GB | Yes (lfm2) | Liquid AI tool-calling |
|
|
333
|
-
| Qwen 2.5 1.5B Instruct Q4_K_M | ~1GB | 1.5GB | Yes | Alibaba, multilingual |
|
|
334
|
-
| TinyLlama 1.1B Q4_K_M | ~700MB | 1GB | - | Fast chat |
|
|
335
|
-
|
|
336
|
-
### Large Models (4GB+ RAM)
|
|
337
|
-
|
|
338
|
-
| Model | Size | Memory | Tool Calling | Description |
|
|
339
|
-
|-------|------|--------|:------------:|-------------|
|
|
340
|
-
| Llama 3.2 3B Instruct Q4_K_M | ~2GB | 3GB | Yes | Meta latest |
|
|
341
|
-
| Mistral 7B Instruct Q4_K_M | ~4GB | 5GB | Yes | Mistral AI |
|
|
342
|
-
| Qwen 2.5 7B Instruct Q4_K_M | ~4GB | 5GB | Yes | Alibaba |
|
|
343
|
-
| Llama 2 7B Chat Q4_K_M | ~4GB | 5GB | - | Meta |
|
|
344
|
-
|
|
345
|
-
### Tool Calling Model Selection Guide
|
|
346
|
-
|
|
347
|
-
- **Best for tool calling (small):** LFM2-350M-Tool (use `format: 'lfm2'`) or Qwen 2.5 0.5B
|
|
348
|
-
- **Best for tool calling (medium):** LFM2-1.2B-Tool or Qwen 2.5 1.5B Instruct
|
|
349
|
-
- **Best for tool calling (large):** Mistral 7B Instruct or Qwen 2.5 7B Instruct
|
|
350
|
-
- **Instruct-tuned models** generally perform better at following tool calling instructions
|
|
351
|
-
- Use `format: 'lfm2'` only with Liquid AI LFM2-Tool models; all others use `format: 'default'`
|
|
352
|
-
|
|
353
|
-
---
|
|
354
|
-
|
|
355
|
-
## Performance Tips
|
|
356
|
-
|
|
357
|
-
### Device Recommendations
|
|
358
|
-
|
|
359
|
-
- **Apple Silicon (M1/M2/M3, A14+)**: Metal GPU acceleration provides 3-5x speedup
|
|
360
|
-
- **Modern Android**: 6GB+ RAM recommended for 7B models
|
|
361
|
-
- **Older devices**: Use smaller models (360M-1B)
|
|
362
|
-
|
|
363
|
-
### Optimization Strategies
|
|
112
|
+
## Native Boundary
|
|
364
113
|
|
|
365
|
-
|
|
366
|
-
2. **Limit maxTokens** — Shorter responses = faster generation
|
|
367
|
-
3. **Unload when idle** — Free memory for other apps
|
|
368
|
-
4. **Pre-download models** — Better UX during onboarding
|
|
114
|
+
The generated Nitro spec exposes only backend registration hooks:
|
|
369
115
|
|
|
370
|
-
|
|
116
|
+
- `registerBackend`
|
|
117
|
+
- `unregisterBackend`
|
|
118
|
+
- `isBackendRegistered`
|
|
119
|
+
- `registerVLMBackend`
|
|
120
|
+
- `unregisterVLMBackend`
|
|
121
|
+
- `isVLMBackendRegistered`
|
|
371
122
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
| iPhone 15 Pro | Llama 3.2 3B Q4 | 15-25 tok/s |
|
|
376
|
-
| MacBook M2 | Llama 2 7B Q4 | 20-40 tok/s |
|
|
377
|
-
| Pixel 8 | SmolLM2 360M Q8 | 30-50 tok/s |
|
|
378
|
-
|
|
379
|
-
---
|
|
380
|
-
|
|
381
|
-
## Native Integration
|
|
382
|
-
|
|
383
|
-
### iOS
|
|
384
|
-
|
|
385
|
-
This package uses `RABackendLLAMACPP.xcframework` which includes:
|
|
386
|
-
- llama.cpp compiled for iOS (arm64)
|
|
387
|
-
- Metal GPU acceleration
|
|
388
|
-
- Optimized NEON SIMD
|
|
389
|
-
|
|
390
|
-
The framework is automatically downloaded during `pod install`.
|
|
391
|
-
|
|
392
|
-
### Android
|
|
393
|
-
|
|
394
|
-
Native library `librunanywhere_llamacpp.so` includes:
|
|
395
|
-
- llama.cpp compiled for Android (arm64-v8a, armeabi-v7a)
|
|
396
|
-
- OpenMP threading support
|
|
397
|
-
- Optimized for ARM NEON
|
|
398
|
-
|
|
399
|
-
Libraries are automatically downloaded during Gradle build.
|
|
400
|
-
|
|
401
|
-
---
|
|
123
|
+
Direct llama.cpp model loading, generation, structured-output, and VLM process
|
|
124
|
+
bridges were deleted. Use `@runanywhere/core` for public model lifecycle and
|
|
125
|
+
inference APIs.
|
|
402
126
|
|
|
403
127
|
## Package Structure
|
|
404
128
|
|
|
405
|
-
```
|
|
129
|
+
```text
|
|
406
130
|
packages/llamacpp/
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
│ └── librunanywhere_llamacpp.so
|
|
428
|
-
└── nitrogen/
|
|
429
|
-
└── generated/
|
|
131
|
+
|-- src/
|
|
132
|
+
| |-- index.ts
|
|
133
|
+
| |-- LlamaCPP.ts
|
|
134
|
+
| |-- LlamaCppProvider.ts
|
|
135
|
+
| |-- native/
|
|
136
|
+
| | `-- NativeRunAnywhereLlama.ts
|
|
137
|
+
| `-- specs/
|
|
138
|
+
| `-- RunAnywhereLlama.nitro.ts
|
|
139
|
+
|-- cpp/
|
|
140
|
+
| |-- HybridRunAnywhereLlama.cpp
|
|
141
|
+
| `-- HybridRunAnywhereLlama.hpp
|
|
142
|
+
|-- ios/
|
|
143
|
+
| `-- Binaries/
|
|
144
|
+
| `-- RABackendLLAMACPP.xcframework
|
|
145
|
+
|-- RunAnywhereLlama.podspec
|
|
146
|
+
|-- android/
|
|
147
|
+
| |-- build.gradle
|
|
148
|
+
| `-- CMakeLists.txt
|
|
149
|
+
`-- nitrogen/
|
|
150
|
+
`-- generated/
|
|
430
151
|
```
|
|
431
|
-
|
|
432
|
-
---
|
|
433
|
-
|
|
434
|
-
## Troubleshooting
|
|
435
|
-
|
|
436
|
-
### Model fails to load
|
|
437
|
-
|
|
438
|
-
**Symptoms:** `modelLoadFailed` error
|
|
439
|
-
|
|
440
|
-
**Solutions:**
|
|
441
|
-
1. Check file exists at the path
|
|
442
|
-
2. Verify GGUF format (not GGML, SafeTensors, etc.)
|
|
443
|
-
3. Ensure sufficient memory (check `memoryRequirement`)
|
|
444
|
-
4. Try a smaller model
|
|
445
|
-
|
|
446
|
-
### Slow generation
|
|
447
|
-
|
|
448
|
-
**Symptoms:** < 5 tokens/second
|
|
449
|
-
|
|
450
|
-
**Solutions:**
|
|
451
|
-
1. Use a smaller model (360M instead of 7B)
|
|
452
|
-
2. Check device isn't thermal throttling
|
|
453
|
-
3. Close other apps to free memory
|
|
454
|
-
4. On iOS, ensure Metal is enabled
|
|
455
|
-
|
|
456
|
-
### Out of memory
|
|
457
|
-
|
|
458
|
-
**Symptoms:** App crash during inference
|
|
459
|
-
|
|
460
|
-
**Solutions:**
|
|
461
|
-
1. Unload model before loading a new one
|
|
462
|
-
2. Use a smaller/more quantized model
|
|
463
|
-
3. Reduce context length (fewer tokens)
|
|
464
|
-
|
|
465
|
-
---
|
|
466
|
-
|
|
467
|
-
## See Also
|
|
468
|
-
|
|
469
|
-
- [Main SDK README](../../README.md) — Full SDK documentation
|
|
470
|
-
- [API Reference](../../Docs/Documentation.md) — Complete API docs
|
|
471
|
-
- [@runanywhere/core](../core/README.md) — Core SDK
|
|
472
|
-
- [@runanywhere/onnx](../onnx/README.md) — STT/TTS backend
|
|
473
|
-
- [llama.cpp](https://github.com/ggerganov/llama.cpp) — Underlying engine
|
|
474
|
-
|
|
475
|
-
---
|
|
476
|
-
|
|
477
|
-
## License
|
|
478
|
-
|
|
479
|
-
MIT License
|
package/RunAnywhereLlama.podspec
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require "json"
|
|
2
|
+
require "pathname"
|
|
2
3
|
|
|
3
4
|
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
5
|
|
|
@@ -10,43 +11,56 @@ Pod::Spec.new do |s|
|
|
|
10
11
|
s.license = package["license"]
|
|
11
12
|
s.authors = "RunAnywhere AI"
|
|
12
13
|
|
|
13
|
-
s.platforms = { :ios => "
|
|
14
|
+
s.platforms = { :ios => "17.0" }
|
|
14
15
|
s.source = { :git => "https://github.com/RunanywhereAI/sdks.git", :tag => "#{s.version}" }
|
|
15
16
|
|
|
16
17
|
# =============================================================================
|
|
17
18
|
# LlamaCPP Backend - xcframework is bundled in npm package
|
|
18
|
-
# No downloads needed - framework is included in ios/
|
|
19
|
+
# No downloads needed - framework is included in ios/Binaries/
|
|
19
20
|
# =============================================================================
|
|
20
21
|
puts "[RunAnywhereLlama] Using bundled RABackendLLAMACPP.xcframework from npm package"
|
|
21
|
-
s.vendored_frameworks = "ios/
|
|
22
|
+
s.vendored_frameworks = "ios/Binaries/RABackendLLAMACPP.xcframework"
|
|
22
23
|
|
|
23
24
|
# Source files
|
|
24
25
|
s.source_files = [
|
|
25
26
|
"cpp/HybridRunAnywhereLlama.cpp",
|
|
26
27
|
"cpp/HybridRunAnywhereLlama.hpp",
|
|
27
|
-
"cpp/bridges/**/*.{cpp,hpp}",
|
|
28
28
|
]
|
|
29
29
|
|
|
30
|
+
# Header search paths for the RACommons xcframework (sibling @runanywhere/core
|
|
31
|
+
# package). Include the Headers root so qualified includes like
|
|
32
|
+
# "rac/backends/rac_llm_llamacpp.h" (and the canonical header's own
|
|
33
|
+
# "rac/core/..."/"rac/features/llm/..." includes) resolve, plus every
|
|
34
|
+
# subdirectory for flat includes like "rac_logger.h".
|
|
35
|
+
rac_headers_root = File.expand_path("../core/ios/Binaries/RACommons.xcframework/ios-arm64/Headers", __dir__)
|
|
36
|
+
rac_headers_root_rel = "$(PODS_TARGET_SRCROOT)/" +
|
|
37
|
+
Pathname.new(rac_headers_root).relative_path_from(Pathname.new(__dir__)).to_s
|
|
38
|
+
rac_header_dirs = [rac_headers_root_rel] +
|
|
39
|
+
Dir.glob(File.join(rac_headers_root, "**", "*.h"))
|
|
40
|
+
.map { |f| File.dirname(f) }
|
|
41
|
+
.uniq
|
|
42
|
+
.map { |d| "$(PODS_TARGET_SRCROOT)/" + Pathname.new(d).relative_path_from(Pathname.new(__dir__)).to_s }
|
|
43
|
+
|
|
30
44
|
s.pod_target_xcconfig = {
|
|
31
45
|
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
|
|
32
|
-
"HEADER_SEARCH_PATHS" => [
|
|
46
|
+
"HEADER_SEARCH_PATHS" => ([
|
|
47
|
+
# Package-local hybrid headers (HybridRunAnywhereLlama.hpp) — needed by the
|
|
48
|
+
# nitrogen-generated OnLoad + cpp-adapter (the forked rac_llm_llamacpp.h that
|
|
49
|
+
# used to live here was deleted; canonical commons header comes via rac_header_dirs).
|
|
33
50
|
"$(PODS_TARGET_SRCROOT)/cpp",
|
|
34
|
-
|
|
35
|
-
"$(PODS_TARGET_SRCROOT)/
|
|
36
|
-
"$(PODS_TARGET_SRCROOT)/ios/Frameworks/RABackendLLAMACPP.xcframework/ios-arm64_x86_64-simulator/RABackendLLAMACPP.framework/Headers",
|
|
37
|
-
"$(PODS_TARGET_SRCROOT)/../core/ios/Frameworks/RACommons.xcframework/ios-arm64/RACommons.framework/Headers",
|
|
38
|
-
"$(PODS_TARGET_SRCROOT)/../core/ios/Frameworks/RACommons.xcframework/ios-arm64_x86_64-simulator/RACommons.framework/Headers",
|
|
51
|
+
# nlohmann/json (header-only) vendored by sibling @runanywhere/core package.
|
|
52
|
+
"$(PODS_TARGET_SRCROOT)/../core/cpp/third_party",
|
|
39
53
|
"$(PODS_ROOT)/Headers/Public",
|
|
40
|
-
].join(" "),
|
|
54
|
+
] + rac_header_dirs).join(" "),
|
|
41
55
|
"GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) HAS_LLAMACPP=1",
|
|
42
56
|
"DEFINES_MODULE" => "YES",
|
|
43
57
|
"SWIFT_OBJC_INTEROP_MODE" => "objcxx",
|
|
44
58
|
}
|
|
45
59
|
|
|
46
60
|
s.libraries = "c++"
|
|
47
|
-
s.frameworks = "Accelerate", "Foundation", "
|
|
61
|
+
s.frameworks = "Accelerate", "Foundation", "Metal", "MetalKit"
|
|
48
62
|
|
|
49
|
-
s.dependency 'RunAnywhereCore'
|
|
63
|
+
s.dependency 'RunAnywhereCore', "~> #{s.version}"
|
|
50
64
|
s.dependency 'React-jsi'
|
|
51
65
|
s.dependency 'React-callinvoker'
|
|
52
66
|
|