use cooklang_import::{ImportResult, RecipeImporter};
use std::time::Duration;
#[allow(unused_imports)]
use cooklang_import::LlmProvider;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("=== Builder with Custom Timeout ===");
let result = RecipeImporter::builder()
.url("https://www.bbcgoodfood.com/recipes/classic-cottage-pie")
.timeout(Duration::from_secs(60))
.build()
.await?;
match result {
ImportResult::Cooklang {
content,
conversion_metadata,
} => {
println!("Successfully imported recipe with custom timeout:");
println!("Recipe length: {} bytes", content.len());
if let Some(meta) = conversion_metadata {
println!("Model: {:?}", meta.model_version);
println!("Latency: {}ms", meta.latency_ms);
}
}
ImportResult::Components(_) => unreachable!(),
}
println!("\n=== Builder with Custom Provider ===");
println!("Note: This requires a config.toml with Anthropic configuration");
println!("\n=== Error Handling Example ===");
let result = RecipeImporter::builder().build().await;
match result {
Ok(_) => println!("Unexpected success"),
Err(e) => println!("Expected error: {}", e),
}
let result = RecipeImporter::builder()
.text("ingredients\n\ninstructions")
.extract_only()
.build()
.await;
match result {
Ok(_) => println!("Unexpected success"),
Err(e) => println!("Expected error: {}", e),
}
println!("\n=== Method Chaining ===");
let result = RecipeImporter::builder()
.url("https://www.bbcgoodfood.com/recipes/classic-cottage-pie")
.timeout(Duration::from_secs(90))
.build()
.await?;
println!("Successfully chained methods and imported recipe");
if let ImportResult::Cooklang { content, .. } = result {
println!("Recipe length: {} bytes", content.len());
}
println!("\n=== Using Ollama (Local LLM) ===");
println!("Note: This requires Ollama running locally with config.toml");
Ok(())
}