use kernelx_core::{prelude::*, Structured}; #[lmp_schema] struct JokeResponse { setup: String, punchline: String, genre: String, rating: f32, tags: Vec, } #[tokio::main] async fn main() -> Result<()> { let provider = OpenAI::from_env()?; let model = provider .get_model::("gpt-4")? .system_prompt("You are a funny comedian.") .temperature(0.7); // Get structured response using schema from lmp_schema derive let schema = schemars::schema_for!(JokeResponse); let json = model .structured_complete("Tell me a joke", &serde_json::to_value(schema.schema)?) .await?; // Parse response using serde let joke: JokeResponse = serde_json::from_value(json)?; println!("Setup: {}", joke.setup); println!("Punchline: {}", joke.punchline); println!("Genre: {}", joke.genre); println!("Rating: {}", joke.rating); println!("Tags: {:?}", joke.tags); Ok(()) }