use gemini_crate::{client::GeminiClient, errors::Error};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenvy::dotenv().ok();
let client = match GeminiClient::new() {
Ok(c) => c,
Err(Error::Config(msg)) => {
eprintln!("❌ Configuration error: {}", msg);
eprintln!("💡 Make sure to set GEMINI_API_KEY in your .env file");
eprintln!(" Example: GEMINI_API_KEY=your_api_key_here");
return Ok(());
}
Err(e) => {
eprintln!("❌ Failed to create Gemini client: {}", e);
return Ok(());
}
};
println!("🤖 Gemini API - Available Models");
println!("=================================\n");
print!("📡 Fetching available models... ");
std::io::Write::flush(&mut std::io::stdout())?;
match client.list_models().await {
Ok(models_response) => {
println!("✅ Done!\n");
if models_response.models.is_empty() {
println!("⚠️ No models found.");
return Ok(());
}
println!("Found {} models:\n", models_response.models.len());
let mut text_generation_models = Vec::new();
let mut embedding_models = Vec::new();
let mut image_models = Vec::new();
let mut other_models = Vec::new();
for model in &models_response.models {
if model
.supported_generation_methods
.contains(&"generateContent".to_string())
{
if model.name.contains("embedding") {
embedding_models.push(model);
} else if model.name.contains("imagen") || model.name.contains("veo") {
image_models.push(model);
} else {
text_generation_models.push(model);
}
} else if model
.supported_generation_methods
.contains(&"embedContent".to_string())
|| model
.supported_generation_methods
.contains(&"embedText".to_string())
{
embedding_models.push(model);
} else if model
.supported_generation_methods
.contains(&"predict".to_string())
|| model
.supported_generation_methods
.contains(&"predictLongRunning".to_string())
{
image_models.push(model);
} else {
other_models.push(model);
}
}
if !text_generation_models.is_empty() {
println!("📝 TEXT GENERATION MODELS");
println!("-------------------------");
for model in text_generation_models {
print_model_details(model);
}
println!();
}
if !embedding_models.is_empty() {
println!("🔢 EMBEDDING MODELS");
println!("-------------------");
for model in embedding_models {
print_model_details(model);
}
println!();
}
if !image_models.is_empty() {
println!("🎨 IMAGE/VIDEO MODELS");
println!("---------------------");
for model in image_models {
print_model_details(model);
}
println!();
}
if !other_models.is_empty() {
println!("🔧 OTHER MODELS");
println!("---------------");
for model in other_models {
print_model_details(model);
}
println!();
}
println!("💡 RECOMMENDED MODELS FOR COMMON USE CASES");
println!("------------------------------------------");
println!("🚀 Fast text generation: gemini-2.5-flash");
println!("🧠 Complex reasoning: gemini-2.5-pro");
println!("🔄 Always latest version: gemini-flash-latest");
println!("📊 Text embeddings: text-embedding-004");
println!("🎯 Stable production: gemini-2.0-flash-001");
}
Err(Error::Network(e)) => {
println!("❌");
eprintln!("🌐 Network error: {}", e);
eprintln!("💡 Check your internet connection and try again.");
}
Err(Error::Api(msg)) => {
println!("❌");
eprintln!("🚫 API error: {}", msg);
eprintln!("💡 Check your API key and try again.");
}
Err(e) => {
println!("❌");
eprintln!("❌ Unexpected error: {}", e);
}
}
Ok(())
}
fn print_model_details(model: &gemini_crate::client::Model) {
println!(" 🔹 {}", model.name);
if !model.display_name.is_empty() {
println!(" Display Name: {}", model.display_name);
}
if !model.description.is_empty() {
println!(" Description: {}", model.description);
}
if !model.version.is_empty() {
println!(" Version: {}", model.version);
}
if model.input_token_limit > 0 {
println!(" Input Limit: {} tokens", model.input_token_limit);
}
if model.output_token_limit > 0 {
println!(" Output Limit: {} tokens", model.output_token_limit);
}
if !model.supported_generation_methods.is_empty() {
println!(
" Methods: {:?}",
model.supported_generation_methods
);
}
println!();
}