gemini_rust/
lib.rs

1//! # gemini-rust
2//!
3//! A Rust client library for Google's Gemini 2.0 API.
4//!
5//! ## Crate Organization
6//!
7//! This crate is organized into domain-specific modules that align with the Gemini API's
8//! capabilities:
9//!
10//! - **`generation`** - Content generation, including text, images, and audio
11//! - **`embedding`** - Text embedding generation for semantic analysis
12//! - **`batch`** - Batch processing for multiple requests
13//! - **`files`** - File upload and management
14//! - **`cache`** - Content caching for reusable contexts
15//! - **`safety`** - Content moderation and safety settings
16//! - **`tools`** - Function calling and tool integration
17//! - **`models`** - Core primitive types shared across modules
18//! - **`prelude`** - Convenient re-exports of commonly used types
19//!
20//! ## Quick Start
21//!
22//! For most use cases, import from the prelude:
23//!
24//! ```rust
25//! use gemini_rust::prelude::*;
26//! ```
27//!
28//! For more specialized types, import them directly from the crate root or their
29//! respective modules.
30
31pub mod client;
32mod models;
33
34/// Convenient re-exports of commonly used types
35pub mod prelude;
36
37/// Batch processing for multiple generation requests
38pub mod batch;
39
40/// Content caching for reusable contexts and system instructions
41pub mod cache;
42
43/// Common utilities and serialization helpers
44pub mod common;
45
46/// Text embedding generation for semantic analysis
47pub mod embedding;
48
49/// File upload and management
50pub mod files;
51
52/// Content generation including text, images, and audio
53pub mod generation;
54
55/// Content moderation and safety settings
56pub mod safety;
57
58/// Function calling and tool integration
59pub mod tools;
60
61#[cfg(test)]
62mod tests;
63
64// ========== Core Types ==========
65// These are the fundamental types used throughout the API
66
67/// The main client error type
68pub use client::Error as ClientError;
69/// The main Gemini API client
70pub use client::Gemini;
71/// Builder for creating a new Gemini client
72pub use client::GeminiBuilder;
73/// Available Gemini models
74pub use client::Model;
75
76/// Core primitive types for building requests and parsing responses
77pub use models::{Blob, Content, Message, Modality, Part, Role};
78
79// ========== Content Generation ==========
80// Types for generating text, images, and audio content
81
82pub use generation::{
83    builder::ContentBuilder, model::BlockReason, model::Candidate, model::CitationMetadata,
84    model::CitationSource, model::FinishReason, model::GenerateContentRequest,
85    model::GenerationConfig, model::GenerationResponse, model::MultiSpeakerVoiceConfig,
86    model::PrebuiltVoiceConfig, model::PromptFeedback, model::PromptTokenDetails,
87    model::SpeakerVoiceConfig, model::SpeechConfig, model::ThinkingConfig, model::UsageMetadata,
88    model::VoiceConfig,
89};
90
91// ========== Text Embeddings ==========
92// Types for generating and working with text embeddings
93
94pub use embedding::{
95    builder::EmbedBuilder, model::BatchContentEmbeddingResponse, model::BatchEmbedContentsRequest,
96    model::ContentEmbedding, model::ContentEmbeddingResponse, model::EmbedContentRequest,
97    model::TaskType,
98};
99
100// ========== Safety & Content Filtering ==========
101// Types for content moderation and safety settings
102
103pub use safety::model::{
104    HarmBlockThreshold, HarmCategory, HarmProbability, SafetyRating, SafetySetting,
105};
106
107// ========== Function Calling & Tools ==========
108// Types for integrating external tools and function calling
109
110pub use tools::model::{
111    FunctionCall, FunctionCallingConfig, FunctionCallingMode, FunctionDeclaration,
112    FunctionResponse, Tool, ToolConfig,
113};
114
115// ========== Batch Processing ==========
116// Types for processing multiple requests in batch operations
117
118pub use batch::{
119    builder::BatchBuilder, handle::BatchGenerationResponseItem, handle::BatchHandle,
120    handle::BatchHandle as Batch, handle::BatchStatus, handle::Error as BatchHandleError,
121    model::BatchConfig, model::BatchGenerateContentRequest, model::BatchOperation,
122    model::BatchStats, model::IndividualRequestError, model::RequestMetadata, Error as BatchError,
123};
124
125// ========== File Management ==========
126// Types for uploading and managing files
127
128pub use files::{
129    builder::FileBuilder, handle::FileHandle, model::File, model::FileState, Error as FilesError,
130};
131
132// ========== Content Caching ==========
133// Types for caching contexts and system instructions
134
135pub use cache::{
136    builder::CacheBuilder, handle::CachedContentHandle, model::CacheExpirationRequest,
137    model::CacheExpirationResponse, model::CachedContent, model::CreateCachedContentRequest,
138};