Crate google_ai_rs

Source
Expand description

Rust client for Google’s Generative AI APIs

Provides a type-safe, ergonomic interface for interacting with Google’s AI services including Gemini. Features comprehensive API coverage with compile-time schema validation and async/await support.

§Highlights

  • Type-Safe API Interactions: Generated from official Google discovery documents
  • Multi-modal Support: Text, images, and structured data in single requests
  • Production-Ready: Connection pooling, retries, and comprehensive error handling

§Quickstart

use google_ai_rs::{Client, GenerativeModel};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new("API_KEY".into()).await?;
    let model = client.generative_model("gemini-pro");
     
    let response = model.generate_content(
        "Explain quantum physics using pirate metaphors"
    ).await?;
     
    println!("{}", response.text());
    Ok(())
}

Re-exports§

pub use auth::Auth;
pub use client::Client;
pub use error::Error;
pub use genai::GenerativeModel;
pub use genai::TypedModel;
pub use genai::TypedResponse;
pub use crate::schema::AsSchema;
pub use crate::schema::Map;
pub use crate::schema::MapTrait;
pub use crate::schema::SchemaType;
pub use crate::schema::Tuple;
pub use content::IntoContent;
pub use content::IntoContents;
pub use content::IntoParts;
pub use content::TryFromCandidates;
pub use content::TryFromContents;
pub use content::TryIntoContent;
pub use content::TryIntoContents;

Modules§

auth
chat
client
content
embedding
error
genai
schema

Structs§

CachedContent
Content that has been preprocessed and can be used in subsequent request to GenerativeService.
Candidate
A response candidate generated from the model.
Content
The base structured datatype containing multi-part content of a message.
FunctionCall
A predicted FunctionCall returned from the model that contains a string representing the FunctionDeclaration.name with the arguments and their values.
GenerationConfig
Configuration options for model generation and outputs. Not all parameters are configurable for every model.
Part
A datatype containing media that is part of a multi-part Content message.
Schema
The Schema object allows the definition of input and output data types. These types can be objects, but also primitives and arrays. Represents a select subset of an OpenAPI 3.0 schema object.
Tool
Tool details that the model may use to generate response.

Enums§

Data
TaskType
Type of task for which the embedding will be used.

Derive Macros§

AsSchema
Derive macro for AsSchema trait.