gemini_rs/
lib.rs

1#![warn(unreachable_pub, unused_qualifications)]
2
3//! *A Rust client library for Google's Gemini AI models.*
4//!
5//! # Overview
6//!
7//! This library provides a fully-featured client for interacting with Google's Gemini AI models,
8//! supporting all major API features including:
9//!
10//! - Text generation and chat conversations
11//! - JSON-structured outputs
12//! - Function calling
13//! - Safety settings and content filtering
14//! - System instructions
15//! - Model configuration (temperature, tokens, etc.)
16//!
17//! # Authentication
18//!
19//! The client requires a Gemini API key which can be provided in two ways:
20//! - Environment variable: `GEMINI_API_KEY`
21//! - Programmatically: `Client::new(api_key)`
22//!
23//! # Basic Usage
24//!
25//! ```rust,no_run
26//! #[tokio::main]
27//! async fn main() -> gemini_rs::Result<()> {
28//!     // Simple chat interaction
29//!     let response = gemini_rs::chat("gemini-2.0-flash")
30//!         .send_message("What is Rust's ownership model?")
31//!         .await?;
32//!     println!("{}", response);
33//!
34//!     Ok(())
35//! }
36//! ```
37//!
38//! # Advanced Features
39//!
40//! The library supports advanced Gemini features through the `Client` and `Chat` types:
41//!
42//! - Model management (`client().models()`)
43//! - Custom generation settings (`chat.config_mut()`)
44//! - Safety settings (`chat.safety_settings()`)
45//! - System instructions (`chat.system_instruction()`)
46//! - Conversation history management (`chat.history_mut()`)
47
48mod chat;
49mod client;
50mod error;
51mod stream;
52pub mod types;
53
54pub type Result<T> = std::result::Result<T, Error>;
55
56pub use chat::Chat;
57pub use client::Client;
58pub use error::Error;
59pub use stream::{RouteStream, StreamGenerateContent};
60
61/// Creates a new Gemini client instance using the default configuration.
62pub fn client() -> Client {
63    Client::instance()
64}
65
66/// Creates a new chat session with the specified Gemini model.
67pub fn chat(model: &str) -> Chat<chat::Text> {
68    client().chat(model)
69}