ChatBroker class abstract

Chat / completion / streaming capability. Implemented by every chat-capable provider in this package (OpenAiBroker, AnthropicBroker, GeminiBroker).

A provider implements chatWithMeta and stream; chat, complete and completeWithMeta are defaults built on chatWithMeta, so a class that extends ChatBroker gets them for free. A class that implements ChatBroker must supply all five.

Implemented types

Constructors

ChatBroker()

Properties

hashCode → int
The hash code for this object.
no setterinherited
id → String
Stable identifier — 'openai', 'anthropic', 'gemini', 'google_translate', … Used as the key in AiBrokerRegistry and as the KeyResolver lookup id.
no setterinherited
label → String
Human label for picker UIs. 'OpenAI', 'Anthropic (Claude)', 'Google (Gemini)', 'Google (Translate)'.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

chat({required String apiKey, required String model, required ChatRequest request}) → Future<String>
Multi-turn. Returns the assistant's raw text for the final turn. Same call as chatWithMeta, keeping only AiCompletion.text.
chatWithMeta({required String apiKey, required String model, required ChatRequest request}) → Future<AiCompletion>
Multi-turn, returning the final turn's reply with why the model stopped and the token counts the provider reported. Every provider call goes through here; chat, complete and completeWithMeta are built on it.
complete({required String apiKey, required String model, required String system, required String user, double temperature = 0.3, int maxTokens = 2048}) → Future<String>
Single-shot. Returns the assistant's raw text. Same call as completeWithMeta, keeping only AiCompletion.text.
completeWithMeta({required String apiKey, required String model, required String system, required String user, double temperature = 0.3, int maxTokens = 2048}) → Future<AiCompletion>
Single-shot, returning the reply with why the model stopped and the token counts the provider reported. Use it to tell a reply cut off at maxTokens (AiFinishReason.maxTokens) from a complete one.
listModels(String apiKey) → Future<List<String>>
Models suitable for the broker's primary capability, newest first. Returns an empty list for an unset / invalid key, or for providers that have no user-selectable model (e.g. Google Translate v2).
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
stream({required String apiKey, required String model, required ChatRequest request}) → Stream<String>
Token-streaming chat. Each event is an incremental delta — concatenating every event yields the same string chat would return. Closes the stream cleanly on end-of-message; errors are surfaced via the stream.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited