Class TextStreamer
java.lang.Object
smile.llm.engine.TextStreamer
Coalesces generated token ids into streamed UTF-8 text chunks.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault coalesce length before attempting a decode flush. -
Constructor Summary
ConstructorsConstructorDescriptionTextStreamer(int maxTokens, int chunkTokens, BiFunction<int[], Boolean, String> tryDecode) Creates a text streamer with an explicit coalesce length.TextStreamer(int maxTokens, BiFunction<int[], Boolean, String> tryDecode) Creates a text streamer withDEFAULT_CHUNK_TOKENS. -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(int tokenId) Appends one generated token id.voidmaybeEmit(GenerationListener listener, boolean force) Flushes a text chunk when enough tokens accumulated orforce.
-
Field Details
-
DEFAULT_CHUNK_TOKENS
public static final int DEFAULT_CHUNK_TOKENSDefault coalesce length before attempting a decode flush.- See Also:
-
-
Constructor Details
-
TextStreamer
Creates a text streamer withDEFAULT_CHUNK_TOKENS.- Parameters:
maxTokens- capacity of the completion token buffer.tryDecode-(tokens, skipSpecial) -> text; may throwCharacterCodingExceptionas unchecked via wrapper.
-
TextStreamer
Creates a text streamer with an explicit coalesce length.- Parameters:
maxTokens- capacity of the completion token buffer.chunkTokens- coalesce length before attempting a decode flush.tryDecode-(tokens, skipSpecial) -> text.
-
-
Method Details
-
accept
public void accept(int tokenId) Appends one generated token id.- Parameters:
tokenId- generated token id.
-
maybeEmit
Flushes a text chunk when enough tokens accumulated orforce.- Parameters:
listener- destination; may benull.force- flush even if belowchunkTokens.
-