package ocaml-ai-sdk
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=4f3f22ae61d360b994cd75323bcb6b6bf915f6755fd1e7bab6844ca8a240c1e7
sha512=3c52b17096da818f5d3bcf9fe16826c3bec4533d6a1681e8ba0f957f37ee4f425696017cb78f1a24732f8851010d436cf446f873b72b6a4f5004d6b492072abf
doc/ocaml-ai-sdk.ai_core/Ai_core/Smooth_stream/index.html
Module Ai_core.Smooth_streamSource
Smooth text and reasoning streaming output.
Buffers Text_stream_part.t.Text_delta and Text_stream_part.t.Reasoning_delta chunks and re-emits them in controlled pieces (word-by-word, line-by-line, or custom) with optional inter-chunk delays. Matches the upstream AI SDK's smoothStream transform.
All other stream events pass through immediately, flushing any buffered text first.
type chunking = | Word(*Stream word-by-word. Matches non-whitespace followed by whitespace (regex
*)\S+\s+). Default.| Line(*Stream line-by-line. Matches one or more newlines (regex
*)\n+).| Regex of Re2.t(*Stream using a custom Re2 pattern. The match (including everything before it) is emitted as one chunk — same semantics as upstream
*)RegExpchunking.| Segmenter(*Unicode UAX#29 word segmentation via
*)uuseg. Recommended for CJK languages where words are not separated by spaces. Equivalent to upstreamIntl.Segmenter.| Custom of string -> string option(*User-provided chunk detector. Receives the buffer, returns the prefix to emit as
*)Some chunk, orNoneto wait for more data. The returned string must be a non-empty prefix of the buffer.
How to split buffered text into chunks for emission.
val create :
?delay_ms:int ->
?chunking:chunking ->
?sleep:(float -> unit Lwt.t) ->
unit ->
Text_stream_part.t Lwt_stream.t ->
Text_stream_part.t Lwt_stream.tcreate ?delay_ms ?chunking () returns a stream transformer.