flutter_ai_client 0.1.1 copy "flutter_ai_client: ^0.1.1" to clipboard
flutter_ai_client: ^0.1.1 copied to clipboard

Provider-agnostic chat controller for flutter_ai. Wraps any LlmProvider in a Listenable UseChatController with optimistic send, cancellation, regeneration, and frame-batched streaming — without imposi [...]

flutter_ai_client #

☕ Support this project #

Buy me a coffee on Ko-fi

If flutter_ai saves you time, buy me a coffee ☕ — it keeps the whole family maintained.


Live chat driven by UseChatController

Provider-agnostic chat controller for the flutter_ai family.

UseChatController wraps any LlmProvider (from flutter_ai_core) and exposes conversation state as a plain Listenable — so it drops into ListenableBuilder and adapts cleanly to Bloc, Riverpod, or Provider. It bundles no state-manager of its own.

Features #

  • Optimistic send — the user's message paints synchronously, before the request is dispatched.
  • Streaming, batched — events are folded by flutter_ai_core's MessageProcessor; notifications are coalesced (injectable scheduler) so high token rates don't drop frames.
  • Full controlsendText, submit, stop, regenerate, clear.
  • Provider/model switchingsetProvider, setOptions, setTools take effect on the next turn without touching the UI.
  • Escape hatch — a raw events stream for custom state layers.

Usage #

final controller = UseChatController(
  provider: myProvider,                 // any LlmProvider
  options: const AiRequestOptions(model: 'gpt-4o'),
);

// Bind to the UI — rebuilds when the conversation changes.
ListenableBuilder(
  listenable: controller,
  builder: (context, _) => ListView(
    children: [
      for (final m in controller.messages) Text('${m.role.name}: ${m.text}'),
    ],
  ),
);

// Send / stop.
controller.sendText('Hello');
if (controller.status.isBusy) controller.stop();

// Switch model live.
controller.setOptions(const AiRequestOptions(model: 'gpt-4o-mini'));

See example/ for a minimal end-to-end widget.

Implementing a provider #

A provider maps your backend's stream onto flutter_ai_core's AiStreamEvents:

class MyProvider implements LlmProvider {
  @override
  Stream<AiStreamEvent> send(
    AiConversation conversation, {
    List<ToolDefinition>? tools,
    AiRequestOptions? options,
  }) async* {
    yield const MessageStarted(messageId: 'a1', role: AiRole.assistant);
    yield const TextDelta(messageId: 'a1', delta: 'Hello!');
    yield const MessageFinished(messageId: 'a1', reason: FinishReason.stop);
  }
}

Status #

0.1.0. Published on pub.dev; depends on flutter_ai_core.

0
likes
0
points
687
downloads

Publisher

unverified uploader

Weekly Downloads

Provider-agnostic chat controller for flutter_ai. Wraps any LlmProvider in a Listenable UseChatController with optimistic send, cancellation, regeneration, and frame-batched streaming — without imposing a state-management library.

Homepage
Repository (GitHub)
View/report issues

Topics

#ai #llm #chat #streaming #flutter

License

unknown (license)

Dependencies

flutter, flutter_ai_core

More

Packages that depend on flutter_ai_client