package ocaml-ai-sdk

  1. Overview
  2. Docs
OCaml AI SDK - Provider abstraction for AI models

Install

dune-project
 Dependency

Authors

Maintainers

Sources

ocaml-ai-sdk-0.6.1.tbz
sha256=cb3b82428abcda76c02ec92f8103a4db28edf3f42795794a37135e9a3c40af96
sha512=11be8889ee25bee67b2be00553c42a4692bc73e5ce23985e8bb87f8a07e9d8f556b5a63b219fe5fe30366c8b0d4edae494afa80ccfbfcb112f1fa1e458de55bf

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.

Sourcetype chunking =
  1. | Word
    (*

    Stream word-by-word. Matches non-whitespace followed by whitespace (regex \S+\s+). Default.

    *)
  2. | Line
    (*

    Stream line-by-line. Matches one or more newlines (regex \n+).

    *)
  3. | 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 RegExp chunking.

    *)
  4. | Segmenter
    (*

    Unicode UAX#29 word segmentation via uuseg. Recommended for CJK languages where words are not separated by spaces. Equivalent to upstream Intl.Segmenter.

    *)
  5. | Custom of string -> string option
    (*

    User-provided chunk detector. Receives the buffer, returns the prefix to emit as Some chunk, or None to 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.

Sourceval 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.t

create ?delay_ms ?chunking () returns a stream transformer.

  • parameter delay_ms

    Delay in milliseconds between emitted chunks. Default is 10. Pass 0 to disable delays.

  • parameter chunking

    Controls how text is split into chunks. Default is Word.

  • parameter sleep

    Function called to sleep between chunks (default Lwt_unix.sleep).