Current section

Files

Jump to
liter_llm lib liter_llm response_format.ex
Raw

lib/liter_llm/response_format.ex

# This file is auto-generated by alef — DO NOT EDIT.
# alef:hash:b159ec7bf40f2249b9f5696d5819688bca2310a2b26cc9acae8194e6255f8b03
# To regenerate: alef generate
# To verify freshness: alef verify --exit-code
defmodule LiterLlm.ResponseFormat do
@moduledoc """
Wire format for the chat completions `response_format` field.
# Provider mapping
- **OpenAI** (and OpenAI-compatible providers): emitted verbatim as
`{"type": "json_schema", "json_schema": {...}}` per the
chat-completions spec.
- **Gemini / Vertex AI**: translated to
`generationConfig.responseMimeType = "application/json"` and
`generationConfig.responseSchema = <schema>`. The `name`,
`description`, and `strict` fields are dropped — Gemini's
structured-output API does not consume them.
- **Anthropic**: no native JSON mode. A system instruction is
prepended asking the model to respond with valid JSON.
`strict` is advisory only; callers should still validate the
returned JSON if the schema is load-bearing.
# Example
```no_run
# use liter_llm::types::{ResponseFormat, ChatCompletionRequest};
# use serde_json::json;
let request = ChatCompletionRequest {
model: "gpt-4o".into(),
messages: vec![],
response_format: Some(ResponseFormat::json_schema(
"PersonSchema",
json!({ "type": "object", "properties": { "name": { "type": "string" } } }),
)),
..Default::default()
};
# let _ = request;
```
"""
@typedoc "Wire format for the chat completions `response_format` field."
@type t :: term()
@typedoc "Plain text output (default)."
@type text :: :text
@typedoc "Output must be valid JSON object (no schema validation)."
@type json_object :: :json_object
@typedoc "Output must conform to the specified JSON schema."
@type json_schema :: %{type: :json_schema, json_schema: LiterLlm.JsonSchemaFormat.t()}
end