use cactus_rs::needle::{Needle, Tool, Weights};
use serde::Deserialize;
use serde_json::json;
#[derive(Debug, Deserialize)]
struct Contact {
name: String,
email: String,
company: String,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let sentence = "Ada Lovelace, ada@analytical.co, heads research at Analytical Engines.";
let mut needle = Needle::builder(Weights::fetch()?)
.system("Record every contact the text describes. Copy values exactly as written.")
.tool(Tool::new(
"record_contact",
"Record one person's name, email address and employer",
json!({
"type": "object",
"properties": {
"name": { "type": "string", "description": "The person's full name." },
"email": { "type": "string", "description": "The person's email address." },
"company": { "type": "string", "description": "The employer named for them." }
},
"required": ["name", "email", "company"]
}),
))
.build()?;
let completion = needle.complete(sentence)?;
println!("{sentence}");
for call in completion.calls() {
let contact: Contact = call.parse()?;
println!(" name {}", contact.name);
println!(" email {}", contact.email);
println!(" company {}", contact.company);
}
if completion.calls().is_empty() {
println!(" nothing to record");
}
println!("confidence {:.2}", completion.confidence());
Ok(())
}