litert_dart 0.2.0 copy "litert_dart: ^0.2.0" to clipboard
litert_dart: ^0.2.0 copied to clipboard

On-device LiteRT-LM (.litertlm) LLM inference for pure Dart via dart:ffi. No Flutter. Load a model (Gemma, Qwen, DeepSeek…) and generate text locally.

example/litert_dart_example.dart

// Minimal litert_dart example: load a .litertlm model and ask a question.
//
// First download the native binaries once:
//   dart run litert_dart:fetch_natives
//
// Usage:
//   dart run example/litert_dart_example.dart /path/to/model.litertlm "Your question"
import 'dart:io';

import 'package:litert_dart/litert_dart.dart';

Future<void> main(List<String> args) async {
  if (args.isEmpty) {
    stderr.writeln(
      'Usage: dart run example/litert_dart_example.dart '
      '<model.litertlm> ["question"]',
    );
    exit(1);
  }
  final modelPath = args[0];
  final prompt = args.length > 1 ? args[1] : 'What is 2 + 2? Answer briefly.';

  stdout.writeln('Loading ${modelPath.split('/').last} (CPU)…');
  final model = await LiteRtModel.load(modelPath);

  stdout.writeln('Question: $prompt');
  stdout.write('Answer: ');
  await for (final chunk in model.askStream(prompt)) {
    stdout.write(chunk);
  }
  stdout.writeln();

  await model.close();
}
1
likes
150
points
8
downloads

Documentation

API reference

Publisher

verified publisherjhonacode.com

Weekly Downloads

On-device LiteRT-LM (.litertlm) LLM inference for pure Dart via dart:ffi. No Flutter. Load a model (Gemma, Qwen, DeepSeek…) and generate text locally.

Repository (GitHub)
View/report issues

Topics

#llm #ffi #gemma #on-device #ai

License

unknown (license)

Dependencies

crypto, ffi, mutex

More

Packages that depend on litert_dart