use agentix::Request;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
struct MovieReview {
title: String,
year: u16,
rating: f32,
summary: String,
pros: Vec<String>,
cons: Vec<String>,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = std::env::var("OPENAI_API_KEY")
.expect("Set OPENAI_API_KEY");
let http = reqwest::Client::new();
let schema = serde_json::to_value(schemars::schema_for!(MovieReview))?;
let response = Request::openai(api_key)
.model("gpt-4o-mini")
.system_prompt("You are a film critic. Always respond in the requested JSON format.")
.user("Review the movie Inception (2010).")
.json_schema("movie_review", schema, true)
.complete(&http)
.await?;
let review: MovieReview = response.json()?;
println!("Title: {} ({})", review.title, review.year);
println!("Rating: {}/10", review.rating);
println!("Summary: {}", review.summary);
println!("\nPros:");
for p in &review.pros { println!(" + {p}"); }
println!("\nCons:");
for c in &review.cons { println!(" - {c}"); }
Ok(())
}