Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Examples

This directory contains comprehensive examples demonstrating all features of the gemini-rust library. Each example is a complete, runnable program that showcases specific functionality.

Quick Start

Run any example with:

GEMINI_API_KEY="your-api-key" cargo run --example <example_name>

Get your API key from Google AI Studio.

Example Categories

🚀 Getting Started

Example Description
basic_generation.rs Simple content generation - best starting point for beginners
basic_streaming.rs Simple streaming responses - real-time content display
simple.rs Basic text generation and function calling - comprehensive example
advanced.rs Advanced content generation with comprehensive parameter configuration
test_api.rs Simple API connectivity test

💬 Content Generation

Example Description
streaming.rs Real-time streaming responses for interactive applications
generation_config.rs Custom generation parameters (temperature, tokens, etc.)
structured_response.rs Generate structured JSON output with schema validation
gemini_pro_example.rs Using Gemini 2.5 Pro for advanced tasks

🛠️ Function Calling & Tools

Example Description
tools.rs Custom function declarations and tool integration
complex_function.rs Advanced function calling with OpenAPI schema support using schemars
google_search.rs Google Search tool integration for real-time information
google_search_with_functions.rs Combining Google Search with custom functions
curl_google_search.rs Google Search functionality with cURL equivalent commands
url_context.rs URL Context tool for analyzing web content

🧠 Thinking Mode (Gemini 2.5)

Example Description
thinking_basic.rs Basic thinking mode for step-by-step reasoning
thinking_advanced.rs Advanced thinking capabilities with custom budgets
thinking_curl_equivalent.rs Thinking mode with cURL command equivalents
simple_thought_signature.rs Simple thought signature examples
text_thought_signature_example.rs Text-based thought signature demonstrations
thought_signature_example.rs Comprehensive thought signature usage

🚀 Gemini 3

Example Description
gemini_3_code_execution.rs Code execution with Python and tool integration
gemini_3_thinking_and_media.rs Thinking levels and media resolution for Gemini 3 Pro
gemini_3_all_thinking_levels.rs Demonstrate all 5 thinking levels (Minimal, Low, Medium, High) with Gemini 3 Flash

📦 Batch Processing

Example Description
batch_generate.rs Batch content generation for multiple requests
batch_embedding.rs Batch text embedding generation
batch_list.rs List and manage batch operations with streaming
batch_cancel.rs Cancel running batch operations
batch_delete.rs Delete completed batch operations

💾 Content Caching

Example Description
cache_basic.rs Cache system instructions and conversation history for cost optimization

📊 Text Embeddings

Example Description
embedding.rs Generate text embeddings with various task types

🖼️ Multimodal & Media

Example Description
blob.rs Process images and binary data with base64 encoding
mp4_describe.rs Analyze and describe video content

🎨 Image Generation

Example Description
simple_image_generation.rs Basic text-to-image generation
image_generation.rs Advanced image generation with detailed prompts
image_editing.rs Edit existing images with text prompts

🎤 Speech Generation

Example Description
simple_speech_generation.rs Basic text-to-speech generation
multi_speaker_tts.rs Multi-speaker text-to-speech dialogue generation

📁 File Management

Example Description
files_lifecycle.rs Complete file management lifecycle (upload, list, get, delete)
files_usage.rs Upload and use file in a request
files_delete_all.rs Bulk delete all uploaded files

⚙️ Configuration & Setup

Example Description
custom_models.rs Configure different Gemini models (Flash, Pro, Lite, custom models) with all available options
custom_base_url.rs Use custom API endpoints and configurations
http_client_builder.rs Advanced HTTP client configuration with timeouts, proxies, and connection pooling
tracing_telemetry.rs Comprehensive tracing and telemetry setup for observability and monitoring
curl_equivalent.rs See equivalent cURL commands for API calls

🚨 Error Handling

Example Description
error_handling.rs Comprehensive error handling patterns and best practices

Usage Patterns

Basic Content Generation

Start with simple.rs to understand the basic API usage:

GEMINI_API_KEY="your-api-key" cargo run --example simple

Streaming Responses

For real-time applications, use streaming:

GEMINI_API_KEY="your-api-key" cargo run --example streaming

Function Calling

Learn how to integrate custom functions:

GEMINI_API_KEY="your-api-key" cargo run --example tools
GEMINI_API_KEY="your-api-key" cargo run --example complex_function

Thinking Mode

Explore Gemini 2.5's reasoning capabilities:

GEMINI_API_KEY="your-api-key" cargo run --example thinking_basic
GEMINI_API_KEY="your-api-key" cargo run --example thinking_advanced

Batch Processing

For high-throughput applications:

GEMINI_API_KEY="your-api-key" cargo run --example batch_generate

Image and Media

Work with multimodal content:

GEMINI_API_KEY="your-api-key" cargo run --example blob
GEMINI_API_KEY="your-api-key" cargo run --example image_generation

Notes

  • All examples include comprehensive error handling
  • Examples demonstrate both async/await patterns and streaming
  • Code includes detailed comments explaining each step
  • Examples use environment variables for API keys (never hardcode credentials)
  • Some examples require specific model capabilities (e.g., image generation requires image-enabled models)

Contributing

When adding new examples:

  1. Follow the existing naming conventions
  2. Include comprehensive error handling
  3. Add detailed comments explaining the functionality
  4. Update this README.md with the new example
  5. Ensure the example runs successfully with cargo run --example <name>

Media Files

The examples directory includes sample media files for testing:

  • image-example.webp - Sample image for image processing examples
  • sample.mp4 - Sample video for video analysis examples

These files are used by various examples to demonstrate multimodal capabilities.