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/Output/index.html

Module Ai_core.OutputSource

Structured output API for generate_text and stream_text.

Matches the Vercel AI SDK v6 Output API: Output.text, Output.object_, Output.array, Output.choice. Controls model response format and adds parsing/validation.

Sourcetype ('complete, 'partial) t = {
  1. name : string;
  2. response_format : Ai_provider.Mode.json_schema option;
    (*

    Schema to pass to the provider via Mode.Object_json. None means text mode (no JSON instruction).

    *)
  3. parse_complete : string -> ('complete, string) result;
    (*

    Parse and validate the complete model response text. Returns Error msg if JSON parsing or schema validation fails.

    *)
  4. parse_partial : string -> 'partial option;
    (*

    Parse a potentially incomplete response for streaming. Returns None if text is empty or unparseable. No schema validation.

    *)
}

An output specification parameterized by the parsed output type.

  • 'complete is the type returned by parse_complete (final validated output)
  • 'partial is the type returned by parse_partial (streaming partial output)
Sourceval mode_of_output : (_, _) t option -> Ai_provider.Mode.t

Derive the provider Mode.t from an optional output spec. Some o with a schema maps to Object_json; otherwise Regular.

Sourceval parse_output : (Yojson.Basic.t, _) t option -> Generate_text_result.step list -> Yojson.Basic.t option

Parse the final output from completed steps. Returns None if no output spec, text mode, or parse failure.

Sourceval text : (string, string) t

Default text output — no structured format, returns raw text.

Sourceval object_ : name:string -> schema:Yojson.Basic.t -> unit -> (Yojson.Basic.t, Yojson.Basic.t) t

Object output — model produces JSON matching the given schema. name is passed to the provider for context. Complete output is validated against the schema. Partial output uses repair-and-parse (no validation).

Sourceval array : name:string -> element_schema:Yojson.Basic.t -> unit -> (Yojson.Basic.t, Yojson.Basic.t) t

Array output — model produces an array of elements matching the schema. Wraps in {"elements":[...]} envelope for the model, unwraps on parse. Complete output validates every element against the schema. Partial output drops the last element on repaired parses and silently skips invalid elements.

Sourceval choice : name:string -> string list -> (Yojson.Basic.t, Yojson.Basic.t) t

Choice output — model picks one of the given string options. Wraps in {"result":"..."} envelope for the model, unwraps on parse. Complete output validates the choice is in the allowed list. Partial output uses prefix matching: on repaired parses, only returns when exactly one option matches the prefix (unambiguous).

Sourceval enum : name:string -> string list -> (Yojson.Basic.t, Yojson.Basic.t) t
  • deprecated

    Use choice instead. Alias kept for backwards compatibility.