use anyhow::Result;
use rig::prelude::*;
use rig::providers::openai;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, JsonSchema, Serialize)]
enum Sentiment {
Positive,
Negative,
Neutral,
}
#[derive(Debug, Deserialize, JsonSchema, Serialize)]
struct DocumentSentiment {
sentiment: Sentiment,
}
#[tokio::main]
async fn main() -> Result<()> {
let extractor = openai::Client::from_env()
.extractor::<DocumentSentiment>(openai::GPT_4)
.build();
let sentiment = extractor.extract("I am happy").await?;
println!("GPT-4: {sentiment:?}");
Ok(())
}