55 lines
1.6 KiB
Rust
55 lines
1.6 KiB
Rust
use stratum_llm::{Message, Role, UnifiedClient};
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
tracing_subscriber::fmt::init();
|
|
|
|
println!("Creating UnifiedClient with budget-based fallback strategy...");
|
|
|
|
let client = UnifiedClient::builder().auto_detect()?.build()?;
|
|
|
|
let messages = vec![Message {
|
|
role: Role::User,
|
|
content: "Explain quantum computing in simple terms.".to_string(),
|
|
}];
|
|
|
|
println!("\nProvider chain:");
|
|
for (idx, provider) in client.providers().iter().enumerate() {
|
|
println!(
|
|
" {}. {} ({}) - circuit: {:?}",
|
|
idx + 1,
|
|
provider.name,
|
|
provider.model,
|
|
provider.circuit_state
|
|
);
|
|
}
|
|
|
|
println!("\nSending multiple requests to test fallback...");
|
|
|
|
for i in 1..=3 {
|
|
println!("\n--- Request {} ---", i);
|
|
match client.generate(&messages, None).await {
|
|
Ok(response) => {
|
|
println!(
|
|
"✓ Provider: {} | Model: {} | Cost: ${:.4} | Latency: {}ms",
|
|
response.provider,
|
|
response.model,
|
|
response.cost_cents / 100.0,
|
|
response.latency_ms
|
|
);
|
|
println!(
|
|
"Response preview: {}...",
|
|
&response.content[..100.min(response.content.len())]
|
|
);
|
|
}
|
|
Err(e) => {
|
|
eprintln!("✗ All providers failed: {}", e);
|
|
}
|
|
}
|
|
|
|
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
|
|
}
|
|
|
|
Ok(())
|
|
}
|