经 AI Skill Hub 精选评估,llama-rn AI技能包 获评「强烈推荐」。这款AI工具在功能完整性、社区活跃度和易用性方面表现出色,AI 评分 8.2 分,适合有一定技术背景的用户使用。
为React Native提供llama.cpp的原生绑定库,支持iOS和Android平台集成大型语言模型。开发者可在移动应用中部署本地LLM推理,实现离线AI功能,适合需要隐私保护和边缘计算的移动应用开发者。
llama-rn AI技能包 是一款基于 C++ 开发的开源工具,专注于 React Native、LLM推理、跨平台 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
为React Native提供llama.cpp的原生绑定库,支持iOS和Android平台集成大型语言模型。开发者可在移动应用中部署本地LLM推理,实现离线AI功能,适合需要隐私保护和边缘计算的移动应用开发者。
llama-rn AI技能包 是一款基于 C++ 开发的开源工具,专注于 React Native、LLM推理、跨平台 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
# 克隆仓库 git clone https://github.com/mybigday/llama.rn cd llama.rn # 查看安装说明 cat README.md # 按 README 完成环境依赖安装后即可使用
# 查看帮助 llama.rn --help # 基本运行 llama.rn [options] <input> # 详细使用说明请查阅文档 # https://github.com/mybigday/llama.rn
# llama.rn 配置说明 # 查看配置选项 llama.rn --config-example > config.yml # 常见配置项 # output_dir: ./output # log_level: info # workers: 4 # 环境变量(覆盖配置文件) export LLAMA.RN_CONFIG="/path/to/config.yml"
React Native binding of llama.cpp - LLM inference in C/C++
Key Features:
[!IMPORTANT] Starting with v0.10,llama.rnrequires React Native's New Architecture. For Old Architecture support or documentation for v0.9.x, please refer to thev0.9branch.
npm install llama.rn
llama.rn downloads the pre-built ios/rnllama.xcframework and android/src/main/jniLibs from the matching GitHub release during postinstall. Existing downloads are reused, and each archive is verified with SHA-256 before extraction.
Bun does not run dependency lifecycle scripts unless the package is trusted. If you install llama.rn with Bun and want the native downloads to run automatically, add it to trustedDependencies and re-run bun install:
{
"trustedDependencies": ["llama.rn"]
}
If you prefer not to trust dependency lifecycle scripts, run the downloader manually before npx pod-install or your Android build:
node ./node_modules/llama.rn/install/download-native-artifacts.js
Please re-run npx pod-install again.
By default, llama.rn will use pre-built rnllama.xcframework for iOS. If you want to build from source, please set RNLLAMA_BUILD_FROM_SOURCE to 1 in your Podfile.
Add proguard rule if it's enabled in project (android/app/proguard-rules.pro):
```proguard
First, you need a multimodal model and its corresponding multimodal projector (mmproj) file, see how to obtain mmproj for more details.
💡 You can find complete examples in the example project.
Load model info only:
import { loadLlamaModelInfo } from 'llama.rn'
const modelPath = 'file://<path to gguf model>'
console.log('Model Info:', await loadLlamaModelInfo(modelPath))
Initialize a Llama context & do completion:
import { initLlama } from 'llama.rn'
// Initial a Llama context with the model (may take a while)
const context = await initLlama({
model: modelPath,
use_mlock: true,
n_ctx: 2048,
n_gpu_layers: 99, // number of layers to store in GPU memory (Metal/OpenCL)
// embedding: true, // use embedding
})
const stopWords = ['</s>', '<|end|>', '<|eot_id|>', '<|end_of_text|>', '<|im_end|>', '<|EOT|>', '<|END_OF_TURN_TOKEN|>', '<|end_of_turn|>', '<|endoftext|>']
// Do chat completion
const msgResult = await context.completion(
{
messages: [
{
role: 'system',
content: 'This is a conversation between user and assistant, a friendly chatbot.',
},
{
role: 'user',
content: 'Hello!',
},
],
n_predict: 100,
stop: stopWords,
// ...other params
},
(data) => {
// This is a partial completion callback
const { token } = data
},
)
console.log('Result:', msgResult.text)
console.log('Timings:', msgResult.timings)
// Or do text completion
const textResult = await context.completion(
{
prompt: 'This is a conversation between user and llama, a friendly chatbot. respond in simple markdown.\n\nUser: Hello!\nLlama:',
n_predict: 100,
stop: [...stopWords, 'Llama:', 'User:'],
// ...other params
},
(data) => {
// This is a partial completion callback
const { token } = data
},
)
console.log('Result:', textResult.text)
console.log('Timings:', textResult.timings)
The binding's deisgn inspired by server.cpp example in llama.cpp:
/completion and /chat/completions: context.completion(params, partialCompletionCallback)/tokenize: context.tokenize(content)/detokenize: context.detokenize(tokens)/embedding: context.embedding(content)/rerank: context.rerank(query, documents, params)Please visit the Documentation for more details.
You can also visit the example to see how to use it.
const result = await context.completion({
messages: [
{
role: 'user',
content: [
{
type: 'text',
text: 'What do you see in this image?',
},
{
type: 'image_url',
image_url: {
url: 'file:///path/to/image.jpg',
// or base64: 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD...'
},
},
],
},
],
n_predict: 100,
temperature: 0.1,
})
console.log('AI Response:', result.text)
// Method 1: Using structured message content (Recommended)
const result = await context.completion({
messages: [
{
role: 'user',
content: [
{
type: 'text',
text: 'Transcribe or describe this audio:',
},
{
type: 'input_audio',
input_audio: {
data: 'data:audio/wav;base64,UklGRiQAAABXQVZFZm10...',
// or url: 'file:///path/to/audio.wav',
format: 'wav', // or 'mp3'
},
},
],
},
],
n_predict: 200,
})
console.log('Transcription:', result.text)
import { initLlama } from 'llama.rn'
const context = await initLlama({
model: modelPath,
n_ctx: 8192,
n_gpu_layers: 99,
n_parallel: 4, // Max number of parallel slots supported
})
// Enable parallel mode with 4 slots
await context.parallel.enable({
n_parallel: 4, // new_n_ctx (2048) = n_ctx / n_parallel
n_batch: 512,
})
// Queue multiple completion requests
const request1 = await context.parallel.completion(
{
messages: [{ role: 'user', content: 'What is AI?' }],
n_predict: 100,
},
(requestId, data) => {
console.log(`Request ${requestId}:`, data.token)
}
)
const request2 = await context.parallel.completion(
{
messages: [{ role: 'user', content: 'Explain quantum computing' }],
n_predict: 100,
},
(requestId, data) => {
console.log(`Request ${requestId}:`, data.token)
}
)
// Cancel a request if needed
await request1.stop()
// Wait for completion
const result = await request2.promise
console.log('Result:', result.text)
// Disable parallel mode when done
await context.parallel.disable()
ws ::= | " " | "\n" [ \t]{0,20}
js import { initLlama } from 'llama.rn'
const gbnf = '...'
const context = await initLlama({ // ...params grammar: gbnf, })
const { text } = await context.completion({ // ...params messages: [ { role: 'system', content: 'You are a helpful assistant that can answer questions and help with tasks.', }, { role: 'user', content: 'Test', }, ], }) console.log('Result:', text) ```
Also, this is how json_schema works in response_format during completion, it converts the json_schema to gbnf grammar.
context.parallel.enable(config?): - config.n_parallel (number): Number of concurrent slots (default: 2) - config.n_batch (number): Batch size for processing (default: 512) - Returns: Promise<boolean>
context.parallel.disable(): - Disables parallel mode - Returns: Promise<boolean>
context.parallel.configure(config): - Reconfigures parallel mode (enables if not already enabled) - config.n_parallel (number): Number of concurrent slots - config.n_batch (number): Batch size for processing - Returns: Promise<boolean>
context.parallel.completion(params, onToken?): - params: Same completion parameters as completion() - onToken: Optional callback (requestId, data) => void for token streaming - requestId: Unique request identifier - data: Token data with token, content, reasoning_content, tool_calls, accumulated_text - Returns: Promise<{ requestId, promise, stop }> - requestId: Unique request identifier - promise: Resolves to NativeCompletionResult when complete - stop: Function to cancel this request
context.parallel.embedding(text, params?): - text: Text content to get embedding for - params: Optional embedding parameters - Returns: Promise<{ requestId, promise }> - requestId: Unique request identifier - promise: Resolves to embedding result when complete
context.parallel.rerank(query, documents, params?): - query: Query string for ranking - documents: Array of document strings to rank - params: Optional rerank parameters (e.g., normalize) - Returns: Promise<{ requestId, promise }> - requestId: Unique request identifier - promise: Resolves to rerank results when complete
高质���React Native-LLM集成方案,活跃维护,技术选型合理,填补移动平台本地推理空白。
AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。
建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。
✅ MIT 协议 — 最宽松的开源协议之一,可自由商用、修改、分发,仅需保留版权声明。
AI Skill Hub 点评:llama-rn AI技能包 的核心功能完整,质量优秀。对于AI 技术爱好者来说,这是一个值得纳入个人工具库的选择。建议先在非生产环境试用,再逐步推广。
| 原始名称 | llama-rn |
| 原始描述 | 开源AI工具:React Native binding of llama.cpp。⭐947 · C++ |
| Topics | React NativeLLM推理跨平台C++绑定移动AI |
| GitHub | https://github.com/mybigday/llama.rn |
| License | MIT |
| 语言 | C++ |
收录时间:2026-05-18 · 更新时间:2026-05-19 · License:MIT · AI Skill Hub 不对第三方内容的准确性作法律背书。