6 releases (3 breaking)
new 0.4.1 | Mar 28, 2025 |
---|---|
0.4.0 | Mar 26, 2025 |
0.3.0 | Mar 26, 2025 |
0.2.0 | Mar 26, 2025 |
0.1.1 | Mar 25, 2025 |
#972 in Machine learning
449 downloads per month
41KB
811 lines
gemini-rust
A Rust client library for Google's Gemini 2.0 API.
Features
- Complete implementation of the Gemini 2.0 API
- Support for system prompts, user prompts
- Tools and function calling (including Google Search)
- Streaming responses
- Async/await API
Installation
Add this to your Cargo.toml
:
[dependencies]
gemini-rust = "0.1.0"
Usage
Basic Usage
use gemini_rust::{Gemini, Message, Role, Content};
use tokio;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = std::env::var("GEMINI_API_KEY")?;
let client = Gemini::new(&api_key);
let response = client.generate_content()
.with_system_prompt("You are a helpful assistant.")
.with_user_message("Hello, how are you?")
.execute()
.await?;
println!("Response: {}", response.text());
Ok(())
}
Using Google Search Tool
use gemini_rust::{Gemini, Tool};
use tokio;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = std::env::var("GEMINI_API_KEY")?;
let client = Gemini::new(&api_key);
// Create a Google Search tool
let google_search_tool = Tool::google_search();
let response = client.generate_content()
.with_user_message("What is the current Google stock price?")
.with_tool(google_search_tool)
.execute()
.await?;
println!("Response: {}", response.text());
Ok(())
}
Documentation
For more examples and detailed documentation, see docs.rs.
License
MIT
Dependencies
~7–18MB
~240K SLoC