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ยง
- Thinking
Accumulator - 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
sis a valid prefix of any opening tag we recognise. - safe_
thinking_ ๐emit_ len - Return how many bytes from the start of
bufare safe to emit as thinking content โ i.e. bytes that cannot be part of a</think>tag.