llm_dart 0.11.0-alpha.1 copy "llm_dart: ^0.11.0-alpha.1" to clipboard
llm_dart: ^0.11.0-alpha.1 copied to clipboard

Provider-neutral Dart AI runtime interfaces and helpers for composing llm_dart provider packages.

example/README.md

LLM Dart Examples #

Practical examples for the LLM Dart library, organized by learning path and use case.

For modern app examples, use package:llm_dart/llm_dart.dart or package:llm_dart/core.dart for app-facing helpers and import concrete provider packages directly. Use package:llm_dart/provider_authoring.dart only for custom provider implementations or tests that intentionally exercise provider prompt/request/stream contracts.

When you need runtime provider selection, use ProviderRegistry with provider facades from direct provider packages. ModelRegistry remains a low-level compatibility factory registry for custom adapters. When you need structured JSON as a first-class app result, prefer generateObject(...) and streamObject(...) over the lower-level structured-output helpers.

For shared chat UI projection, keep ChatMessageMapper on package:llm_dart/core.dart. When the UI also needs provider-owned metadata, inspect ProviderMetadata namespaces in app UI code. Provider custom-part helpers such as OpenAICustomPart and GoogleCustomPart operate on provider content parts and stream events rather than UI parts.

Recommended default route:

  • start in 01_getting_started/ for model-first setup
  • spend most new app work in the stable examples under 02_core_features/
  • treat provider directories as focused provider-native appendices rather than the default learning path
  • keep ModelMessage on app-facing examples and PromptMessage on provider-authoring examples
  • do not use the removed root legacy barrel, builder, model, provider, or legacy core subpaths in new examples

Quick Start #

I need to... Go to
Get started quickly quick_start.dart
Build a chatbot chatbot.dart
Compare stable models by provider provider_comparison.dart
Use streaming streaming_chat.dart
Gate app UI by capability profiles capability_profile_ui_gating.dart
Cancel requests cancellation_demo.dart
Call functions tool_calling.dart
Handle audio audio_processing.dart
Generate images image_generation.dart
Edit provider images openai/image_generation.dart or google/image_generation.dart
Process large datasets batch_processor.dart
Build multimodal apps multimodal_app.dart
Use the pure chat runtime packages/llm_dart_chat/example/chat_runtime.dart
Send backend chat hints packages/llm_dart_chat/example/http_backend_hint_mapping.dart
Use Flutter + backend hints packages/llm_dart_flutter/example/flutter_http_backend_integration.dart
Run a Flutter Material chat demo packages/llm_dart_flutter/example/flutter_material_chat_demo.dart
Gate Flutter controls by model capabilities packages/llm_dart_flutter/example/flutter_capability_gated_controls.dart
Recover HTTP chat after disconnect packages/llm_dart_flutter/example/flutter_http_reconnect_demo.dart
Handle tool approvals in Flutter packages/llm_dart_flutter/example/flutter_tool_approval_demo.dart
Connect external tools mcp_concept_demo.dart

Directory Structure #

Read these directories from top to bottom if you are new to the repository: 01_getting_started and most of 02_core_features are the default path; provider directories are explicit boundary appendices.

Getting Started #

First-time users

Core Features #

Essential functionality

Compatibility Appendices #

Migration-only examples

Advanced Features #

Specialized capabilities

Provider Examples #

Provider-specific features

Most provider directories now follow one of two roles:

  • stable model examples for providers that already have short provider factories such as openai(...) or direct provider packages such as package:llm_dart_openai/llm_dart_openai.dart
  • compatibility or provider-specific residual examples for broader legacy shells

Ollama and ElevenLabs now also have modern shared-capability surfaces in the workspace llm_dart_ollama and llm_dart_elevenlabs packages. The directories below focus on the remaining provider-specific or compatibility-oriented flows rather than the shared-capability happy path.

Provider Features Directory
OpenAI Stable chat/image/audio plus files, moderation, and image-editing helpers openai/
Anthropic Claude chat, extended thinking, MCP, and files anthropic/
DeepSeek / OpenRouter / custom OpenAI-family Stable profile flows plus explicit compatible endpoint wiring others/
Groq Fast inference groq/
Google Gemini/Imagen images, embeddings, speech, and image editing/variation google/
Ollama Modern local runtime tuning with provider-owned options ollama/
ElevenLabs Stable shared speech/transcription plus provider-owned voice and realtime appendices elevenlabs/
xAI Live search, Grok xai/

Use Cases #

Complete applications

Capability-profile demos now also include the modern llm_dart_ollama and llm_dart_elevenlabs surfaces. Treat current ElevenLabs capability answers as stronger hosted-API descriptors, while reading Ollama vision/reasoning affordances as model-family inference that still needs real request-path validation.

MCP Integration #

External tool connections

Run these examples from the standalone package in example/06_mcp_integration.

Setup #

Set API keys for the providers you want to use:

export OPENAI_API_KEY="your-key"
export ANTHROPIC_API_KEY="your-key"
export GROQ_API_KEY="your-key"
export DEEPSEEK_API_KEY="your-key"

Run examples:

dart run 01_getting_started/quick_start.dart
dart run 02_core_features/chat_basics.dart
dart run 02_core_features/capability_profile_ui_gating.dart
dart run 05_use_cases/chatbot.dart
dart run ../packages/llm_dart_chat/example/chat_runtime.dart
dart run ../packages/llm_dart_chat/example/http_backend_hint_mapping.dart
dart run 05_use_cases/batch_processor.dart --help
dart run 05_use_cases/multimodal_app.dart --demo

# Flutter package examples should be run from the Flutter package directory.
cd ../packages/llm_dart_flutter
flutter run -t example/flutter_material_chat_demo.dart
flutter run -t example/flutter_capability_gated_controls.dart

Learning Path #

Beginner: Start with quick_start.dartprovider_comparison.dartchat_basics.dart

Intermediate: Focus on tool_calling.dartstructured_output.darterror_handling.dartcapability_profile_ui_gating.dart

Advanced: Study chat_runtime.darthttp_backend_hint_mapping.dartbatch_processor.dartcustom_providers.dart

Production: Explore performance_optimization.dartflutter_material_chat_demo.dartflutter_http_backend_integration.dart → provider-owned appendices or MCP integration only when product requirements justify them

Production Example #

Yumcha - A production Flutter app built with LLM Dart, showcasing real-world integration patterns and best practices.

Resources #

21
likes
150
points
573
downloads

Publisher

unverified uploader

Weekly Downloads

Provider-neutral Dart AI runtime interfaces and helpers for composing llm_dart provider packages.

Repository (GitHub)
View/report issues

Topics

#ai #llms #nlp

License

MIT (license)

Dependencies

llm_dart_ai, llm_dart_chat, llm_dart_provider, llm_dart_transport

More

Packages that depend on llm_dart