StreamDecoder#
- class scikitplot.cleanprompt.StreamDecoder(guard)[source]#
Decode a model’s reply as it streams in, never splitting a label.
- Parameters:
- guardGuard
Supplies the vault and the placeholder grammar.
- Parameters:
guard (Guard)
Notes
User notes. Call
feedwith each chunk and print what it returns; callflushonce at the end. The text you print is exactly what decoding the whole reply at once would give.Developer notes. Two things can be cut by a chunk boundary: a bracket label (
[EMA|IL-1]) and a literal stand-in (Marion|Holt, orid_1|0whereid_10is also a stand-in). The decoder emits everything before the earliest point where either could still be in progress, and keeps the rest:from the last unclosed opening delimiter within
MAX_LABELcharacters, including a backslash escaping it;the longest tail of the buffer that is a proper prefix of a literal stand-in, or a whole stand-in that is also a prefix of a longer one.
Everything emitted is decoded with the same function as a whole reply.
One reply, one audit event. A reply decoded whole records one
decodedevent. Streamed, it arrives in as many chunks as the model emits tokens, and recording each chunk turned one reply into thousands of events that said nothing a single one does not (CP-090). The counts are gathered as chunks arrive and recorded once, byflush, with the number of chunks; they equal the counts of the same reply decoded whole. A stream that is abandoned withoutflushrecords no event;flushis what ends a reply.