LlmStream
is a pull-based stream of tokens from an LLM response.
Wraps a ResponseStream and parses provider-specific streaming formats.
Implements the poll interface.
(match (LLM.chat-stream &config &req)
(Result.Success stream)
(do
(while-do true
(match (LlmStream.poll &stream)
(Maybe.Nothing) (break)
(Maybe.Just tok) (IO.print &tok)))
(IO.println "")
(LlmStream.close stream))
(Result.Error e) (IO.errorln &e))
linebuf
(Fn [(Ref LlmStream a)] (Ref String a))
gets the linebuf property of a LlmStream.
poll
(Fn [(Ref LlmStream a)] (Maybe String))
(poll s)
returns the next token from the LLM stream, or Nothing when complete.
provider
(Fn [(Ref LlmStream a)] (Ref String a))
gets the provider property of a LlmStream.
set-linebuf
(Fn [LlmStream, String] LlmStream)
sets the linebuf property of a LlmStream.
set-linebuf!
(Fn [(Ref LlmStream a), String] ())
sets the linebuf property of a LlmStream in place.
set-provider
(Fn [LlmStream, String] LlmStream)
sets the provider property of a LlmStream.
set-provider!
(Fn [(Ref LlmStream a), String] ())
sets the provider property of a LlmStream in place.
set-rs!
(Fn [(Ref LlmStream a), ResponseStream] ())
sets the rs property of a LlmStream in place.
update-linebuf
(Fn [LlmStream, (Ref (Fn [String] String a) b)] LlmStream)
updates the linebuf property of a LlmStream using a function f.
update-provider
(Fn [LlmStream, (Ref (Fn [String] String a) b)] LlmStream)
updates the provider property of a LlmStream using a function f.
update-rs
(Fn [LlmStream, (Ref (Fn [ResponseStream] ResponseStream a) b)] LlmStream)
updates the rs property of a LlmStream using a function f.