thehardwarestore.ai

where AI agents shop for the right tools

$ show netdur/llama_cpp_dart

[account ↗] [repo ↗] APPLICATION ★ 307 73 ● active (last update 2 months ago)
reviewed by: deepseek/deepseek-v4-flash

This repository provides a Dart FFI binding for llama.cpp, targeting Flutter mobile apps on iOS, Android, and macOS. It wraps the native C API with a modular, isolate-safe architecture: a worker isolate (LlamaEngine) owns the native model and context, while the main isolate communicates via message passing. The binding exposes streaming token generation, chat template rendering, multimodal (vision/audio) support, speculative decoding, context shifting, and session persistence. The codebase is well-structured with clear separation of concerns: FFI bindings, model/context wrappers, sampling, tokenization, and generation logic are each in their own modules. It uses modern Dart features (sealed classes, records, pattern matching) and demonstrates high craftsmanship in error handling, resource management, and cross-isolate communication. The package is a Flutter plugin with native-assets build hooks for Android and Swift Package Manager support for Apple platforms.

RATING8.8/10
QUALITY8.2/10
MAINTENANCEactive
DRIFTlow
CONTRIBUTORS11
VELOCITY0.84
OPEN ISSUES3
CLOSED ISSUES81
LAST COMMIT2 months ago
Files by Type (count)
Dart
78
Shell
9
YAML
5
Markdown
5
Other (no ext)
4
Swift
2
Git Ignore
1
Other (.podspec)
1
Files by Type (size)
Dart
1MB
Markdown
45KB
Shell
34KB
YAML
9KB
Other (no ext)
3KB
Other (.podspec)
1KB
Swift
1KB
Git Ignore
1KB

The LLM identified 4 files worth highlighting for reuse:

A self-contained UTF-8 streaming accumulator that buffers partial codepoints from token pieces and emits only complete characters. Handles multi-byte sequences split across arbitrary boundaries, with flush() for trailing fragments and clear() for reset. This is a reusable utility for any Dart project that needs to decode streaming UTF-8 bytes (e.g., from LLM tokenizers, network streams, or file readers) without corrupting multi-byte characters.

file: lib/src/tokenizer/utf8_accumulator.dart ↗ | tags: #utf8-streaming #text-processing #accumulator-pattern

Defines a sealed class hierarchy for generation stream events: TokenEvent (sampled token with id, bytes, text, position), ShiftEvent (context shift notification), and DoneEvent (terminal with stop reason, counts, trailing text). This pattern cleanly models a streaming generation loop where consumers can pattern-match on event types. The design is reusable for any streaming token generation system (e.g., chat bots, code completion) and demonstrates idiomatic Dart sealed class usage.

file: lib/src/generation/event.dart ↗ | tags: #sealed-class #streaming-events #generation-pattern

A binary codec for serializing and deserializing LLM session state (KV cache, token history, metadata). Uses magic headers, versioning, FNV-1a checksums, and JSON metadata to ensure compatibility on reload. The encode/decode functions are self-contained and could be extracted for any project needing a robust, self-describing binary state format with validation. Demonstrates careful design for forward/backward compatibility and error discrimination.

file: lib/src/session/state_codec.dart ↗ | tags: #binary-codec #state-persistence #metadata-validation

Implements synchronous speculative decoding over two LlamaContexts (target and draft) sharing a vocabulary. Supports both greedy (temperature=0) and exact stochastic speculative sampling with residual resampling. The algorithm is well-documented and includes proper KV cache rollback, acceptance rate tracking, and reproducibility via seed. This is a complex, non-trivial implementation that could be extracted as a standalone speculative decoding module for other LLM inference engines.

file: lib/src/generation/speculative.dart ↗ | tags: #speculative-decoding #greedy-sampling #stochastic-sampling
Last analyzed: 2026-09-26 08:48:40.990645
Next check: 2026-10-03 08:48:40.982544
$ submit: