use secretary::llm_providers::openai::OpenAILLM;
use secretary::traits::{GenerateData, Task};
use serde::{Deserialize, Serialize};
#[derive(Task, Serialize, Deserialize, Debug)]
struct Info {
#[task(instruction = "Extract the person's email address if mentioned")]
pub email: Option<String>,
#[task(instruction = "Extract the person's occupation or job title")]
pub occupation: String,
}
#[derive(Task, Serialize, Deserialize, Debug)]
struct PersonExtraction {
#[task(instruction = "Extract the person's full name from the text")]
pub name: String,
#[task(instruction = "Extract the person's age as a number")]
pub age: u32,
pub info: Info,
}
fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
let task = PersonExtraction::new();
let additional_instructions = vec![
"Focus on extracting accurate information".to_string(),
"If information is not available, use appropriate defaults".to_string(),
];
let text =
"John Smith is a 30-year-old software engineer. You can reach him at john.smith@email.com";
let llm = OpenAILLM::new(
&std::env::var("SECRETARY_OPENAI_API_BASE").unwrap(),
&std::env::var("SECRETARY_OPENAI_API_KEY").unwrap(),
&std::env::var("SECRETARY_OPENAI_MODEL").unwrap(),
)?;
let result: PersonExtraction =
llm.fields_generate_data(&task, text, &additional_instructions)?;
println!("Generated data: {:#?}", result);
Ok(())
}