pub fn response_format_from_type<T: JsonSchema>(
schema_name: Option<&str>,
) -> Result<ResponseFormat, StructuredError>Available on crate feature
client only.Expand description
Generates a ResponseFormat with automatic JSON schema from a type.
This function uses schemars to generate a JSON schema from a type that
implements JsonSchema, then wraps it in a ResponseFormat with
type = "json_schema" and strict = true.
§Example
ⓘ
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use modelrelay::response_format_from_type;
#[derive(JsonSchema, Deserialize)]
struct WeatherResponse {
temperature: f64,
conditions: String,
}
let format = response_format_from_type::<WeatherResponse>(None)?;