#gemini #live #api #gemini-live-api

gemini-live-api

Crate to interact with the Gemini live API

2 releases

Uses new Rust 2024

new 0.1.1 May 9, 2025
0.1.0 May 9, 2025

#325 in Audio

Download history 82/week @ 2025-05-04

82 downloads per month

MIT license

48KB
1K SLoC

Gemini Live API

crates.io docs.rs License: MIT OR Apache-2.0

A Rust client for real-time, bidirectional communication with Google's Gemini large language models via WebSockets. This crate enables interactive conversations, function calling, and streaming responses, with flexible state management for your application.

It's built on tokio for asynchronous operations and serde for robust JSON handling.

Features

  • Real-time WebSocket Communication: Establishes a persistent WebSocket connection with the Gemini API.
  • Robust Function Calling:
    • Declare tool functions using the #[tool_function] procedural macro.
    • Automatic JSON schema generation for function parameters (derived from function signature).
    • Handles server-side function call requests and sends back responses.
  • Flexible Application State Management:
    • The GeminiLiveClient<S> is generic over a state type S.
    • Your custom state S (wrapped in Arc<S>) is accessible within tool functions and can be captured by event handlers.
    • Supports interior mutability patterns (e.g., Arc<Mutex<T>> within your state S) for concurrent modifications.
  • Event-Driven Architecture:
    • Register asynchronous handlers for server events like on_server_content (for model responses, text, turn completion) and on_usage_metadata.
  • Configurable:
    • Set generation parameters (temperature, max tokens, etc.).
    • Provide system instructions to guide the model's behavior.
  • Typed API: Rust structs for Gemini API requests and responses, ensuring type safety.
  • Asynchronous: Fully async/await based using tokio.

Dependencies

~14–25MB
~439K SLoC