GemmaStreamDecoder class
Turns the Stream<String> from LlamaCppFlutter.generate into a stream of
ChatResponseUpdates for an M.E.AI chat client.
Three kinds of content are separated as they stream in:
- Thinking — when thinking is enabled the model opens its turn with a
<|channel>thought\n…\n<channel|>block (see the Gemma 4 prompt format). Its contents are emitted asTextReasoningContent, with the<|channel>markers and thethoughtlabel stripped. - Prose — ordinary answer text, emitted as
TextContent. - Tool calls — the first
<|tool_call>marker flips the decoder into buffering mode: everything from the marker onward is accumulated and, when the stream ends, parsed intoFunctionCallContentvia GemmaChatTemplate.parse.
Text and tool calls are emitted in separate updates on purpose:
FunctionInvokingChatClient suppresses any update that carries a function
call, so combining them in one update would drop the prose.
A confused model can also emit control markup that doesn't belong in a
well-formed turn — a <channel|> close with no matching opener, or a
self-invented <|turn>role header. Both are stripped from prose rather
than surfaced, so raw control tokens never leak into user-visible text.
Constructors
- GemmaStreamDecoder([GemmaChatTemplate template = const GemmaChatTemplate()])
-
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- template → GemmaChatTemplate
-
final
Methods
-
decode(
Stream< String> tokens) → Stream<ChatResponseUpdate> -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited