Class NaruOllamaNativeStreamParser
- All Implemented Interfaces:
NaruStreamResponseParser
/api/chat stream.
Not SSE, and the difference matters: Ollama writes one bare JSON document
per line with no data: prefix, no frame separator and no
[DONE] sentinel. Termination is a done:true field on the last
document. Reusing the SSE reader here would silently produce zero events
rather than an error, which is the worst possible failure mode -- it looks
like a model that has nothing to say.
Reasoning arrives in message.thinking for models that emit it, in
its own field and interleaved with the answer, so it is fed as native
thinking and kept out of the answer. Content is still scanned for thinking
tags, because a model configured for inline reasoning puts the tags there
instead -- the same rule the OpenAI-compatible path uses, and the reason a
streamed Ollama turn equals a batched one.
Tool calls arrive whole rather than in fragments, so unlike the OpenAI-compatible protocol there is nothing to reassemble here.
-
Constructor Summary
ConstructorsConstructorDescriptionNaruOllamaNativeStreamParser(String provider, NaruStreamHandler handler, NaruModelConfig model) -
Method Summary
Modifier and TypeMethodDescriptionfinish(boolean interrupted) booleanWhether any user-visible output has already been delivered.booleanPolled between documents, which is where a cancel lands.booleanConsumes one NDJSON document.read(net.thevpc.nuts.net.NHttpResponse response) Consumes the body incrementally and returns the assembled response.
-
Constructor Details
-
NaruOllamaNativeStreamParser
public NaruOllamaNativeStreamParser(String provider, NaruStreamHandler handler, NaruModelConfig model)
-
-
Method Details
-
read
Description copied from interface:NaruStreamResponseParserConsumes the body incrementally and returns the assembled response.Must deliver events as they arrive rather than reading the whole body first: the entire point is that a renderer sees text while the model is still generating it.
- Specified by:
readin interfaceNaruStreamResponseParser- Throws:
IOException
-
onLine
Consumes one NDJSON document.- Returns:
falseonce the stream has ended
-
finish
-
hasDeliveredContent
public boolean hasDeliveredContent()Description copied from interface:NaruStreamResponseParserWhether any user-visible output has already been delivered.Consulted by the caller before retrying. A stream that has delivered nothing can be retried invisibly; one that has cannot, because the tokens cannot be recalled.
- Specified by:
hasDeliveredContentin interfaceNaruStreamResponseParser
-
isCancelled
public boolean isCancelled()Polled between documents, which is where a cancel lands.
-