use replicate_client::Client;
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("🚀 Replicate Rust Client Demo");
let client = match Client::from_env() {
Ok(client) => client,
Err(_) => {
println!("❌ Please set the REPLICATE_API_TOKEN environment variable");
println!(" You can get your token from: https://replicate.com/account");
return Ok(());
}
};
println!("\n📝 Creating a prediction...");
let prediction = client
.create_prediction("replicate/hello-world:5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa")
.input("text", "Hello from Rust!")
.send()
.await?;
println!("✅ Prediction created with ID: {}", prediction.id);
println!(" Status: {:?}", prediction.status);
println!("\n⏳ Waiting for prediction to complete...");
let completed_prediction = client
.predictions()
.wait_for_completion(&prediction.id, Some(Duration::from_secs(60)), None)
.await?;
println!("✅ Prediction completed!");
println!(" Status: {:?}", completed_prediction.status);
println!(" Output: {:?}", completed_prediction.output);
println!("\n🔄 Running a model with convenience method...");
let result = client
.run("replicate/hello-world:5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa")
.input("text", "Hello from the convenience method!")
.send_and_wait_with_timeout(Duration::from_secs(60))
.await?;
println!("✅ Model run completed!");
println!(" Output: {:?}", result.output);
println!("\n📋 Listing recent predictions...");
let predictions_page = client.predictions().list(None).await?;
println!("✅ Found {} predictions", predictions_page.results.len());
for (i, pred) in predictions_page.results.iter().take(3).enumerate() {
println!(" {}. {} - {:?}", i + 1, pred.id, pred.status);
}
if predictions_page.has_next() {
println!(" (and more...)");
}
println!("\n🎉 Demo completed successfully!");
Ok(())
}