Module accumulator

Module accumulator 

Source
Expand description

Stateful streaming accumulator for thinking-tag detection.

An LLM may stream < in one SSE chunk, thi in the next, and nk> in a third. ThinkingAccumulator handles this by buffering partial tags and only emitting classified ThinkingEvents once enough bytes have arrived to decide.

Structsยง

ThinkingAccumulator
Stateful accumulator for streaming thinking-tag detection.

Enumsยง

AccState ๐Ÿ”’
Internal state of the accumulator FSM.

Constantsยง

CLOSE_TAG ๐Ÿ”’
The canonical closing tag (lowercase for matching).
OPEN_TAG_PREFIX ๐Ÿ”’
All possible opening-tag prefixes after normalisation (lowercase). Used to determine whether the buffer could still become a valid tag.

Functionsยง

is_potential_open_tag_prefix ๐Ÿ”’
Check whether s is a valid prefix of any opening tag we recognise.
safe_thinking_emit_len ๐Ÿ”’
Return how many bytes from the start of buf are safe to emit as thinking content โ€” i.e. bytes that cannot be part of a </think> tag.