46 lines
1.3 KiB
Rust
46 lines
1.3 KiB
Rust
|
|
#[cfg(feature = "kogral")]
|
||
|
|
use stratum_llm::{Message, Role, UnifiedClient};
|
||
|
|
|
||
|
|
#[cfg(feature = "kogral")]
|
||
|
|
#[tokio::main]
|
||
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||
|
|
tracing_subscriber::fmt::init();
|
||
|
|
|
||
|
|
println!("Creating UnifiedClient with Kogral integration...");
|
||
|
|
let client = UnifiedClient::builder()
|
||
|
|
.auto_detect()?
|
||
|
|
.with_kogral()
|
||
|
|
.build()?;
|
||
|
|
|
||
|
|
let messages = vec![Message {
|
||
|
|
role: Role::User,
|
||
|
|
content: "Write a simple Rust function to add two numbers.".to_string(),
|
||
|
|
}];
|
||
|
|
|
||
|
|
println!("\nSending request with Rust guidelines from Kogral...");
|
||
|
|
match client
|
||
|
|
.generate_with_kogral(&messages, None, Some("rust"), None)
|
||
|
|
.await
|
||
|
|
{
|
||
|
|
Ok(response) => {
|
||
|
|
println!("\n✓ Success!");
|
||
|
|
println!("Provider: {}", response.provider);
|
||
|
|
println!("Model: {}", response.model);
|
||
|
|
println!("Response:\n{}", response.content);
|
||
|
|
println!("\nCost: ${:.4}", response.cost_cents / 100.0);
|
||
|
|
println!("Latency: {}ms", response.latency_ms);
|
||
|
|
}
|
||
|
|
Err(e) => {
|
||
|
|
eprintln!("\n✗ Error: {}", e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
Ok(())
|
||
|
|
}
|
||
|
|
|
||
|
|
#[cfg(not(feature = "kogral"))]
|
||
|
|
fn main() {
|
||
|
|
eprintln!("This example requires the 'kogral' feature.");
|
||
|
|
eprintln!("Run with: cargo run --example with_kogral --features kogral");
|
||
|
|
}
|