llamafu / cognisoc

How it works

One thin path: Dart → FFI → llama.cpp

llamafu is deliberately a thin wrapper. Your Flutter code calls a typed Dart API; that crosses dart:ffi into a small native C++ layer, which drives the llama.cpp inference engine directly on the device.

1
Your Flutter app

Widgets and app logic. Calls llamafu like any other Dart package.

2
Llamafu Dart API

High-level, typed, async. init / complete / stream / chat / generateJson / embeddings.

3
FFI bindings

dart:ffi bridges Dart calls into the native C bridge — no platform channels.

4
Native C++ layer

RAII lifetime management, memory safety, and input validation around the engine.

5
llama.cpp engine

GGUF loading, tokenization, and transformer inference with hand-tuned kernels.

How a GGUF model loads and runs

1 · Load

The GGUF file is memory-mapped and parsed. Weights, tokenizer, and metadata come from one self-describing file — no separate config.

2 · Prompt

Your prompt is tokenized and evaluated to build the context. Sampling settings (temperature, top-k, top-p, penalties) are applied per request.

3 · Decode

Tokens are generated one at a time and streamed back across FFI into Dart, so your UI renders output as it is produced.

Design principles