@rn-ai/llama
v0.2.0
Published
Memory-aware AI SDK 7 provider for llama.rn
Maintainers
Readme
@rn-ai/llama
Memory-aware AI SDK 7 V4 provider over the llama.rn 0.12.6 peer engine. It supports GGUF generation/streaming, tools, schema output, reasoning, local-path image/audio projectors, embeddings, reranking, and configured vocoder speech.
Model downloads are explicit and SHA-verified by @rn-ai/core; the package never bundles weights or a second llama.cpp fork.
Download and run a model
Runtime download is the recommended default on both iOS and Android. This example pins the small Qwen2.5 1.5B Q4 GGUF from the example app's catalog to an immutable Hugging Face commit:
import { generateText } from 'ai'
import { createOnDeviceRuntime } from '@rn-ai/core'
import { createLlamaProvider, defineLlamaModel } from '@rn-ai/llama'
const runtime = createOnDeviceRuntime()
const llama = createLlamaProvider({
runtime,
models: {
chat: defineLlamaModel({
source: {
kind: 'remote',
url: 'https://huggingface.co/Qwen/Qwen2.5-1.5B-Instruct-GGUF/resolve/91cad51170dc346986eccefdc2dd33a9da36ead9/qwen2.5-1.5b-instruct-q4_k_m.gguf?download=true',
sizeBytes: 1_117_320_736,
sha256: '6a1a2eb6d15622bf3c96857206351ba97e1af16c30d7a74ee38970e434e9407e',
fileName: 'qwen2.5-1.5b-instruct-q4_k_m.gguf',
},
contextTokens: 4096,
}),
},
})
const model = llama.languageModel('chat')
await model.control.download({
onProgress: ({ fraction }) => console.log(`${Math.round(fraction * 100)}%`),
})
await model.control.prepare()
console.log((await generateText({ model, prompt: 'Write a mobile-sized hello.' })).text)The runtime owns the app-private cache path and automatically reuses the verified file during
prepare(); do not ask the user to select a local GGUF. Use AbortController for cancellation and
model.control.remove() to delete it. For another model, choose a mobile-sized GGUF, pin its source
revision, and copy its exact Git LFS byte size and SHA-256 into the remote source. Confirm the
model's license and memory requirements before distributing it.
