ai_rs
ai_rs is a Rust library that provides a unified interface to interact with multiple AI models. This library is designed to be modular, allowing you to easily add and use different AI models.
Features
- Modular design: Each AI model is implemented in its own module.
- Easy setup: Initialize and configure AI models with simple method calls.
- Logging: Configurable logging levels using an
.envfile.
Installation
Add ai_rs to your Cargo.toml:
[]
= "0.0.1"
Usage
Example
Here's an example of how to use the ai_rs library with the GeminiClient:
use ;
async
Gemini API Support
The library provides comprehensive support for Google's Gemini API with the following features:
Basic Usage
use ;
let client = new;
// Simple text generation
let response = client.generate_content.await?;
if let Some = response.get_text
Advanced Configuration
let config = GenerationConfig ;
let response = client.generate_content_with_config.await?;
Streaming Support
use StreamExt;
let mut stream = client.stream_content.await?;
while let Some = stream.next.await
Structured Requests
use ;
let request = GenerateContentRequest ;
let response = client.generate_content_with_request.await?;
Environment Setup
Set your Gemini API key as an environment variable:
Or create a .env file:
GEMINI_API_KEY=your_api_key_here
RUST_LOG=info
Logging
The library uses the log crate for logging and the env_logger crate to configure logging levels via an .env file. Create a .env file in the root of your project to specify the logging level:
RUST_LOG=info
Adding New Models
To add a new AI model, create a new module in the src directory and implement the necessary methods. Update src/lib.rs to export the new module.
For example, to add a new model called xyz:
- Create a folder for the
xyzmodel:
- Create a
xyz.rsfile inside thexyzfolder with proper api calls and test cases. Sample code:
use ;
-
Update
src/lib.rsto export thexyzmodule:pub use GeminiClient; pub use xyzClient; use dotenv; use env;
testing
- Run example to ensure proper working:
- run build
- run tests
- get documentation
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
License