package ocaml-ai-sdk
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=467ed85a42617ce399d0032d81f27f8dd2e8ca9b0753daeb2cbd84bf46761370
sha512=f5e96feea16c6ffdb45f49ee3e84e9cdb5426245c1ac32acc6434c15b949cc576c1007ed463bf1362dce507d10700eb96acf5a42fa7eed4e8e491ae0214a2e4a
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.
type ('complete, 'partial) t = {name : string;response_format : Ai_provider.Mode.json_schema option;(*Schema to pass to the provider via
*)Mode.Object_json.Nonemeans text mode (no JSON instruction).parse_complete : string -> ('complete, string) result;(*Parse and validate the complete model response text. Returns
*)Error msgif JSON parsing or schema validation fails.parse_partial : string -> 'partial option;(*Parse a potentially incomplete response for streaming. Returns
*)Noneif text is empty or unparseable. No schema validation.
}An output specification parameterized by the parsed output type.
'completeis the type returned byparse_complete(final validated output)'partialis the type returned byparse_partial(streaming partial output)
Derive the provider Mode.t from an optional output spec. Some o with a schema maps to Object_json; otherwise Regular.
val parse_output :
(Yojson.Basic.t, _) t option ->
Generate_text_result.step list ->
Yojson.Basic.t optionParse the final output from completed steps. Returns None if no output spec, text mode, or parse failure.
val object_ :
name:string ->
schema:Yojson.Basic.t ->
unit ->
(Yojson.Basic.t, Yojson.Basic.t) tObject 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).
val array :
name:string ->
element_schema:Yojson.Basic.t ->
unit ->
(Yojson.Basic.t, Yojson.Basic.t) tArray 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.
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).