Crates.io | ask_gemini |
lib.rs | ask_gemini |
version | 0.1.4 |
source | src |
created_at | 2024-05-30 22:15:28.272008 |
updated_at | 2024-06-03 23:11:53.89065 |
description | A library for interacting with the Google Gemini API |
homepage | |
repository | https://github.com/vvmspace/ask_gemini |
max_upload_size | |
id | 1257310 |
size | 8,329 |
The ask_gemini
crate is a powerful and easy-to-use Rust crate designed for making asynchronous API calls to the Google Gemini API. This library simplifies the process of sending prompts and fetching responses, handling all network and serialization tasks internally. It is ideal for developers looking to integrate Google Gemini API capabilities into their Rust applications efficiently.
Please consider supporting this project by donating:
tokio
and reqwest
, ask_gemini
offers non-blocking API calls to Gemini.Get your Google Gemini API key from the Google AI Studio.
Add ask_gemini
to your Cargo.toml using cargo:
cargo add ask_gemini tokio
Or directly edit your Cargo.toml file:
[dependencies]
ask_gemini = "0.1.2"
tokio = "1.38.0"
Below is a simple example on how to use ask_gemini
to send a prompt to the Gemini API and receive a response:
use ask_gemini::Gemini;
#[tokio::main]
async fn main() {
let gemini = Gemini::new(Some("your_api_key_here"), None);
let prompt = "Hello, world!";
match gemini.ask(prompt).await {
Ok(response) => println!("Response: {:?}", response),
Err(e) => eprintln!("Error: {}", e),
}
}
You can also set the API key as an environment variable:
export GEMINI_API_KEY="your_api_key_here"
Then create a new instance of Gemini
without specifying the API key:
use ask_gemini::Gemini;
#[tokio::main]
async fn main() {
let gemini = Gemini::new(None, None);
let prompt = "Hello, world!";
match gemini.ask(prompt).await {
Ok(response) => println!("Response: {:?}", response),
Err(e) => eprintln!("Error: {}", e),
}
}
You can specify a custom model when creating a new instance of Gemini
:
use ask_gemini::Gemini;
#[tokio::main]
async fn main() {
let gemini = Gemini::new(None, Some("model_name_here"));
let prompt = "Hello, world!";
match gemini.ask(prompt).await {
Ok(response) => println!("Response: {:?}", response),
Err(e) => eprintln!("Error: {}", e),
}
}
Gemini
or set as an environment variable GEMINI_API_KEY
.Gemini
. The default model is used if none is specified.Contributions are welcome! Please feel free to submit pull requests or create issues for bugs, questions, or new features.