Class NaruStreamPipeline
NaruStreamChunks, and an assistant message whose
reasoning is already separated from its answer.
Exists so that no consumer ever has to ask where reasoning came from. A
provider that has a real reasoning channel, a model that inlines it in
<think> tags, and a model that does neither all end up as the same
chunk sequence, which is what makes the batch and streaming paths
interchangeable.
Incrementally fed, so the same instance serves a streamed response and a
batch one. batch(java.lang.String, java.lang.String, net.thevpc.naru.api.model.NaruStreamHandler, net.thevpc.naru.api.model.NaruThinkingTags) is the batch entry point and is exactly equivalent
to feeding the whole body and finishing.
Not thread-safe; a stream belongs to one reader.
-
Constructor Summary
ConstructorsConstructorDescriptionNaruStreamPipeline(String provider, NaruStreamHandler handler, NaruThinkingTags tags) -
Method Summary
Modifier and TypeMethodDescriptionstatic NaruStreamPipelinebatch(String provider, String text, NaruStreamHandler handler, NaruThinkingTags tags) Consumes a whole batch body.Feeds the next piece of the answer body as it arrives.feedNativeThinking(String text) Records reasoning that arrived in a provider-native field rather than inline in the answer.finish()Signals that no more content is coming, whether the stream ended normally or was interrupted.finish(boolean interrupted) message()The message built so far.static NaruStreamPipelineof(String provider, NaruStreamHandler handler) Convenience using the protocol's default delimiters.segments()Reasoning recovered from the answer text, one segment per contiguous run of thinking chunks.thinkingTokens(long tokens) Records the reasoning token count reported by the provider.
-
Constructor Details
-
NaruStreamPipeline
-
-
Method Details
-
of
Convenience using the protocol's default delimiters. -
batch
public static NaruStreamPipeline batch(String provider, String text, NaruStreamHandler handler, NaruThinkingTags tags) Consumes a whole batch body. -
feed
Feeds the next piece of the answer body as it arrives.Reasoning already received as a native field should be passed here as well, via
feedNativeThinking(java.lang.String); the two are kept apart internally so the order between them is preserved in the final message. -
feedNativeThinking
Records reasoning that arrived in a provider-native field rather than inline in the answer.Delivered as its own chunks rather than appended to the answer, so the transcript can interleave reasoning and answer in the order the model produced them.
-
thinkingTokens
Records the reasoning token count reported by the provider.Only stored, never estimated: a made-up count would quietly inflate budget numbers. May be called at any point, since some protocols report usage in a final chunk after the content.
-
finish
Signals that no more content is coming, whether the stream ended normally or was interrupted.Safe to call on an interrupted stream, which is the point: whatever reasoning was in flight becomes a segment marked incomplete rather than being dropped.
- Returns:
- the assistant message, with reasoning already separated out
-
finish
- Parameters:
interrupted- whether generation was cut short
-
message
The message built so far. Valid beforefinish()for rendering, but only complete afterwards.Side-effect free, so rendering code may hold on to it and ask again without the segment numbering drifting.
-
segments
Reasoning recovered from the answer text, one segment per contiguous run of thinking chunks.Chunks are merged back together because a stream splits a single thought into many chunks; persisting each fragment as its own segment would make one long thought read as dozens of unrelated ones.
-