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/// File search for retrieval augmented generation (RAG)
62pub mod file_search;
63
64#[cfg(test)]
65mod tests;
66
67// ========== Core Types ==========
68// These are the fundamental types used throughout the API
69
70/// The main client error type
71pub use client::Error as ClientError;
72/// The main Gemini API client
73pub use client::Gemini;
74/// Builder for creating a new Gemini client
75pub use client::GeminiBuilder;
76/// Type alias for streaming generation responses
77pub use client::GenerationStream;
78/// Available Gemini models
79pub use client::Model;
80
81/// Core primitive types for building requests and parsing responses
82pub use models::{Blob, Content, FileData, Message, Modality, Part, Role};
83
84// ========== Content Generation ==========
85// Types for generating text, images, and audio content
86
87pub use generation::{
88    builder::ContentBuilder, model::BlockReason, model::Candidate, model::CitationMetadata,
89    model::CitationSource, model::CountTokensResponse, model::FinishReason,
90    model::GenerateContentRequest, model::GenerationConfig, model::GenerationResponse,
91    model::GroundingChunk, model::GroundingMetadata, model::GroundingSegment,
92    model::GroundingSupport, model::MapsGroundingChunk, model::MediaResolution,
93    model::MediaResolutionLevel, model::MultiSpeakerVoiceConfig, model::PrebuiltVoiceConfig,
94    model::PromptFeedback, model::PromptTokenDetails, model::SpeakerVoiceConfig,
95    model::SpeechConfig, model::ThinkingConfig, model::ThinkingLevel, model::UsageMetadata,
96    model::VoiceConfig, model::WebGroundingChunk,
97};
98
99// ========== Text Embeddings ==========
100// Types for generating and working with text embeddings
101
102pub use embedding::{
103    builder::EmbedBuilder, model::BatchContentEmbeddingResponse, model::BatchEmbedContentsRequest,
104    model::ContentEmbedding, model::ContentEmbeddingResponse, model::EmbedContentRequest,
105    model::TaskType,
106};
107
108// ========== Safety & Content Filtering ==========
109// Types for content moderation and safety settings
110
111pub use safety::model::{
112    HarmBlockThreshold, HarmCategory, HarmProbability, SafetyRating, SafetySetting,
113};
114
115// ========== Function Calling & Tools ==========
116// Types for integrating external tools and function calling
117
118pub use tools::model::{
119    CodeExecutionConfig, CodeExecutionOutcome, CodeExecutionResult, CodeLanguage, ExecutableCode,
120    FunctionCall, FunctionCallingConfig, FunctionCallingMode, FunctionDeclaration,
121    FunctionResponse, GoogleMapsConfig, LatLng, RetrievalConfig, Tool, ToolConfig,
122};
123
124// ========== Batch Processing ==========
125// Types for processing multiple requests in batch operations
126
127pub use batch::{
128    builder::BatchBuilder, handle::BatchGenerationResponseItem, handle::BatchHandle,
129    handle::BatchHandle as Batch, handle::BatchStatus, handle::Error as BatchHandleError,
130    model::BatchConfig, model::BatchGenerateContentRequest, model::BatchOperation,
131    model::BatchStats, model::IndividualRequestError, model::RequestMetadata, Error as BatchError,
132};
133
134// ========== File Management ==========
135// Types for uploading and managing files
136
137pub use files::{
138    builder::FileBuilder, handle::FileHandle, model::File, model::FileState, Error as FilesError,
139};
140
141// ========== Content Caching ==========
142// Types for caching contexts and system instructions
143
144pub use cache::{
145    builder::CacheBuilder, handle::CachedContentHandle, model::CacheExpirationRequest,
146    model::CacheExpirationResponse, model::CachedContent, model::CreateCachedContentRequest,
147};
148
149// ========== File Search ==========
150// Types for file search and retrieval augmented generation (RAG)
151
152pub use file_search::{
153    model::ChunkingConfig, model::CustomMetadata, model::CustomMetadataValue, model::Document,
154    model::DocumentState, model::FileSearchStore, model::Operation, model::OperationResult,
155    model::Status, model::StringList, model::WhiteSpaceConfig, DocumentBuilder, DocumentHandle,
156    FileSearchStoreBuilder, FileSearchStoreHandle, ImportBuilder, OperationHandle, UploadBuilder,
157};