use api_gemini::{ client::Client, models::* };
use base64::Engine;
#[ allow( clippy::too_many_lines ) ]
fn main()
{
println!( "=== Gemini API Examples Dry Run ===\n" );
println!( "1. Testing client initialization patterns:" );
match Client::builder()
.api_key( "test-api-key".to_string() )
.build()
{
Ok( _ ) => println!( " Client::builder() works correctly" ),
Err( e ) => println!( " Client::builder() failed : {e}" ),
}
match Client::builder().build()
{
Ok( _ ) => println!( " Empty API key should fail" ),
Err( e ) => println!( " Empty API key correctly fails : {e}" ),
}
println!( "\n2. Testing request structures:" );
let _chat_request = GenerateContentRequest
{
contents: vec!
[
Content
{
parts: vec!
[
Part
{
text: Some( "Hello!".to_string() ),
..Default::default()
}
],
role: "user".to_string(),
}
],
..Default::default()
};
println!( " Basic chat request created" );
let conversation =
[
Content
{
role: "user".to_string(),
parts: vec!
[
Part
{
text: Some( "Question 1".to_string() ),
..Default::default()
}
],
},
Content
{
role: "model".to_string(),
parts: vec!
[
Part
{
text: Some( "Answer 1".to_string() ),
..Default::default()
}
],
},
Content
{
role: "user".to_string(),
parts: vec!
[
Part
{
text: Some( "Question 2".to_string() ),
..Default::default()
}
],
},
];
let conversation_len = conversation.len();
println!( " Multi-turn conversation with {conversation_len} turns" );
println!( "\n3. Testing special features:" );
let tools =
[
Tool
{
function_declarations: Some( vec!
[
FunctionDeclaration
{
name: "test_function".to_string(),
description: "A test function".to_string(),
parameters: Some( serde_json::json!
({
"type": "object",
"properties": {
"param": {
"type": "string"
}
}
})),
}
]),
code_execution: None,
google_search_retrieval: None,
code_execution_tool: None,
}
];
let functions_len = tools[ 0 ].function_declarations.as_ref().unwrap().len();
println!( " Function calling tools created with {functions_len} functions" );
let embed_request = EmbedContentRequest
{
content: Content
{
parts: vec!
[
Part
{
text: Some( "Test text".to_string() ),
..Default::default()
}
],
role: "user".to_string(),
},
task_type: Some( "RETRIEVAL_DOCUMENT".to_string() ),
title: None,
output_dimensionality: None,
};
let task_type = embed_request.task_type.as_ref().unwrap();
println!( " Embeddings request created with task type : {task_type}" );
let image_data = vec![ 0x89, 0x50, 0x4E, 0x47 ]; let base64_image = base64::engine::general_purpose::STANDARD.encode( &image_data );
let multimodal_request = GenerateContentRequest
{
contents: vec!
[
Content
{
parts: vec!
[
Part
{
text: Some( "Describe this image".to_string() ),
..Default::default()
},
Part
{
inline_data: Some( Blob
{
mime_type: "image/png".to_string(),
data: base64_image,
}),
..Default::default()
},
],
role: "user".to_string(),
}
],
..Default::default()
};
let parts_len = multimodal_request.contents[ 0 ].parts.len();
println!( " Multimodal request with {parts_len} parts" );
let safety_settings =
[
SafetySetting
{
category: "HARM_CATEGORY_HARASSMENT".to_string(),
threshold: "BLOCK_MEDIUM_AND_ABOVE".to_string(),
}
];
let settings_len = safety_settings.len();
println!( " Safety settings configured with {settings_len} categories" );
println!( "\n4. Testing error handling:" );
let errors = vec!
[
api_gemini ::error::Error::AuthenticationError( "API key missing".to_string() ),
api_gemini ::error::Error::NetworkError( "Connection timeout".to_string() ),
api_gemini ::error::Error::RateLimitError( "Too many requests".to_string() ),
api_gemini ::error::Error::InvalidArgument( "Invalid model name".to_string() ),
];
for error in &errors
{
println!( " Error type handled : {error}" );
}
println!( "\n=== Summary ===" );
println!( "All example patterns validated successfully!" );
println!( "\nTo run the actual examples with API calls:" );
println!( "1. Set GEMINI_API_KEY environment variable" );
println!( "2. Run individual examples:" );
println!( " - cargo run --example chat" );
println!( " - cargo run --example list_models" );
println!( " - cargo run --example multi_turn_conversation" );
println!( " - cargo run --example embeddings" );
println!( " - cargo run --example function_calling" );
println!( " - cargo run --example multimodal" );
println!( " - cargo run --example safety_settings" );
println!( " - cargo run --example error_handling" );
}