Crates.io | ai-transform |
lib.rs | ai-transform |
version | 0.1.0 |
created_at | 2025-06-16 13:47:37.507665+00 |
updated_at | 2025-06-16 13:47:37.507665+00 |
description | Procedural macro for AI-powered data transformations between JSON-serializable types |
homepage | https://github.com/kallyaleksiev/ai-transform |
repository | https://github.com/kallyaleksiev/ai-transform |
max_upload_size | |
id | 1714312 |
size | 57,735 |
AI-powered data transformations between JSON-serializable types using OpenAI.
[dependencies]
ai-transform = "0.1.0"
ai-transform-runtime = "0.1.0" # Required
serde = { version = "1.0.219", features = ["derive"] }
tokio = { version = "1.45.1", features = ["full"] }
use ai_transform::transform;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Default)]
struct User { name: String, age: u32 }
#[derive(Serialize, Deserialize, Default)]
struct Profile { full_name: String, years_old: u32, is_adult: bool }
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
std::env::set_var("OPENAI_API_KEY", "your-api-key");
let user = User { name: "Alice".to_string(), age: 28 };
let profile: Profile = transform!(User, Profile, user).await?;
// AI maps: name → full_name, age → years_old, computes is_adult
Ok(())
}
Only use this macro when you are confident the transformation makes semantic sense.
The AI will attempt to map between your types, but you must make sure the mapping is logically sound and meaningful within your context.
Good use cases:
struct ApiResponse { user_id: String, first_name: String, last_name: String }
struct InternalUser { id: String, full_name: String }
// Clear semantic relationship
Dependencies:
ai-transform
- The macroai-transform-runtime
- Runtime (called by generated code)Environment: OPENAI_API_KEY="your-key"
Types: Must implement Serialize + Deserialize + Default
Default
See examples/
for usage examples.
OPENAI_API_KEY
: RequiredOPENAI_MODEL
: Default "gpt-4o"
OPENAI_BASE_URL
: Default OpenAI endpointcargo test # Unit tests
OPENAI_API_KEY="key" cargo test -- --ignored # Integration tests
MIT