use siumai::models;
use siumai::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("🚀 Siumai Quick Start\n");
quick_start_with_openai().await;
quick_start_with_anthropic().await;
quick_start_with_ollama().await;
println!("\n✅ Quick start completed!");
Ok(())
}
async fn quick_start_with_openai() {
println!("Method 1: OpenAI");
match std::env::var("OPENAI_API_KEY") {
Ok(api_key) if !api_key.is_empty() => {
match LlmBuilder::new()
.openai()
.api_key(&api_key)
.model(models::openai::GPT_4O_MINI)
.temperature(0.7)
.build()
.await
{
Ok(client) => {
let messages = vec![user!("Hello! Please introduce yourself in one sentence.")];
match client.chat(messages).await {
Ok(response) => {
if let Some(text) = response.content_text() {
println!(" AI Reply: {text}");
println!(" ✅ Success\n");
}
}
Err(e) => {
println!(" ❌ Chat failed: {e}");
}
}
}
Err(e) => {
println!(" ❌ Client creation failed: {e}");
}
}
}
_ => {
println!(" ⚠️ OPENAI_API_KEY not set, skipping OpenAI example\n");
}
}
}
async fn quick_start_with_anthropic() {
println!("Method 2: Anthropic (Claude)");
match std::env::var("ANTHROPIC_API_KEY") {
Ok(api_key) if !api_key.is_empty() => {
match LlmBuilder::new()
.anthropic()
.api_key(&api_key)
.model(models::anthropic::CLAUDE_HAIKU_3_5)
.temperature(0.7)
.build()
.await
{
Ok(client) => {
let messages = vec![user!(
"What is the capital of France? Answer in one sentence."
)];
match client.chat(messages).await {
Ok(response) => {
if let Some(text) = response.content_text() {
println!(" AI Reply: {text}");
println!(" ✅ Success\n");
}
}
Err(e) => {
println!(" ❌ Chat failed: {e}");
}
}
}
Err(e) => {
println!(" ❌ Client creation failed: {e}");
}
}
}
_ => {
println!(" ⚠️ ANTHROPIC_API_KEY not set, skipping Anthropic example\n");
}
}
}
async fn quick_start_with_ollama() {
println!("Method 3: Ollama (local)");
match LlmBuilder::new()
.ollama()
.base_url("http://localhost:11434")
.model("llama3.2")
.temperature(0.7)
.build()
.await
{
Ok(client) => {
let messages = vec![user!("Hello! Introduce yourself in one sentence.")];
match client.chat(messages).await {
Ok(response) => {
if let Some(text) = response.content_text() {
println!(" AI Reply: {text}");
println!(" ✅ Success\n");
}
}
Err(e) => {
println!(" ❌ Chat failed: {e}");
println!(" 💡 Ensure Ollama is running: ollama serve");
println!(" 💡 Install model: ollama pull llama3.2\n");
}
}
}
Err(e) => {
println!(" ❌ Client creation failed: {e}");
println!(" 💡 Ensure Ollama is running: ollama serve\n");
}
}
}