2 releases
Uses new Rust 2024
new 0.1.1 | May 9, 2025 |
---|---|
0.1.0 | May 9, 2025 |
#325 in Audio
82 downloads per month
48KB
1K
SLoC
Gemini Live API
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.
- Declare tool functions using the
- Flexible Application State Management:
- The
GeminiLiveClient<S>
is generic over a state typeS
. - Your custom state
S
(wrapped inArc<S>
) is accessible within tool functions and can be captured by event handlers. - Supports interior mutability patterns (e.g.,
Arc<Mutex<T>>
within your stateS
) for concurrent modifications.
- The
- Event-Driven Architecture:
- Register asynchronous handlers for server events like
on_server_content
(for model responses, text, turn completion) andon_usage_metadata
.
- Register asynchronous handlers for server events like
- 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 usingtokio
.
Dependencies
~14–25MB
~439K SLoC