| Crates.io | rgenai |
| lib.rs | rgenai |
| version | 0.1.1 |
| created_at | 2025-06-03 22:14:09.29724+00 |
| updated_at | 2025-06-16 19:53:48.130617+00 |
| description | RGen is a comprehensive Rust library for AWS Bedrock that provides easy-to-use clients for text generation, image generation, embeddings, and vector storage. Built with performance, type safety, and developer experience in mind. |
| homepage | https://github.com/DevMaan707/rgenai |
| repository | https://github.com/DevMaan707/rgenai |
| max_upload_size | |
| id | 1699561 |
| size | 218,007 |
RGenAi is a Rust library for AWS Bedrock that provides easy-to-use clients for text generation, image generation, embeddings, and vector storage. Built with performance, type safety, and developer experience in mind.
Add this to your Cargo.toml:
[dependencies]
rgenai = "0.1.0"
# For PostgreSQL vector storage support
rgenai = { version = "0.1.0", features = ["postgres"] }
postgres - Enable PostgreSQL with pgvector support (Recommended)pinecone - Pinecone support (Coming soon)upstash - Upstash support (Coming soon)use rgenai::{BedrockClient, BedrockConfig, TextGenerationRequest};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
match dotenv::dotenv() {
Ok(_) => log::info!("✅ .env file loaded"),
Err(_) => log::warn!("⚠️ No .env file found"),
}
rgenai::logger::init()?;
let access_key = env::var("AWS_ACCESS_KEY_ID")?;
let secret_key = env::var("AWS_SECRET_ACCESS_KEY")?;
let region = env::var("AWS_REGION").unwrap_or_else(|_| "us-east-1".to_string());
let config = BedrockConfig::new()
.with_region(®ion)
.with_credentials(access_key, secret_key);
let client = BedrockClient::new(config).await?;
let request = TextGenerationRequest {
prompt: "create me a very well designed frontend!".to_string(),
max_tokens: Some(150),
temperature: Some(0.7),
model_id: Some(
"arn:aws:bedrock:us-east-1:022499029734:application-inference-profile/....... {REPLACE WHOLE MODEL ID WITH YOUR INFERENCE ID}"
.to_string(),
),
stream: None,
provider: Some(ModelProvider::Anthropic)
};
let response = client.text().generate(request).await?;
println!("{:?}", response);
Ok(())
}
use rgenai::{BedrockClient, BedrockConfig, Config, PostgresConfig};
use std::collections::HashMap;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let bedrock_config = BedrockConfig::new();
let storage_config = Config::new()
.with_postgres(
PostgresConfig::new()
.with_connection_info("localhost", 5432, "vectordb")
.with_credentials("user", "password")
);
let client = BedrockClient::with_storage(bedrock_config, storage_config).await?;
let result = client.embed_and_store(
"Rust is a systems programming language focused on safety and performance.",
None,
Some(HashMap::new()),
Some("docs"),
).await?;
println!("Stored document with ID: {}", result.id);
let answer = client.generate_with_context(
"What is Rust programming language?",
3,
None,
None,
Some("docs"),
Some(200),
Some(0.7),
).await?;
println!("RAG Answer: {}", answer);
Ok(())
}
# AWS Configuration
AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key
# PostgreSQL Configuration (Required for vector storage)
USE_PSQL=true
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_USERNAME=postgres
POSTGRES_PASSWORD=password
POSTGRES_DATABASE=vectordb
# Application Configuration
PORT=8080
CREATE DATABASE vectordb;
\c vectordb
CREATE EXTENSION vector;
When no model_id is provided, the library uses these defaults:
amazon.titan-text-express-v1amazon.titan-image-generator-v1amazon.titan-embed-text-v1use rgenai::logger::{init_with_config, LoggerConfig, LogLevel};
let logger_config = LoggerConfig::new()
.with_level(LogLevel::Debug)
.with_colors(true)
.with_file_output("app.log");
init_with_config(logger_config)?;
use rgenai::{BedrockError, Result};
match client.text().generate(request).await {
Ok(response) => println!("Success: {}", response),
Err(BedrockError::ConfigError(msg)) => eprintln!("Configuration error: {}", msg),
Err(BedrockError::AwsError(msg)) => eprintln!("AWS error: {}", msg),
Err(e) => eprintln!("Other error: {}", e),
}
Contributions are welcome! Priority areas:
This project is licensed under the MIT License - see the LICENSE file for details.
Built with ❤️ by DevMaan707 - Empowering Rust AI applications 🦀