ai-transform

Crates.ioai-transform
lib.rsai-transform
version0.1.0
created_at2025-06-16 13:47:37.507665+00
updated_at2025-06-16 13:47:37.507665+00
descriptionProcedural macro for AI-powered data transformations between JSON-serializable types
homepagehttps://github.com/kallyaleksiev/ai-transform
repositoryhttps://github.com/kallyaleksiev/ai-transform
max_upload_size
id1714312
size57,735
(kallyaleksiev)

documentation

https://docs.rs/ai-transform

README

AI Transform

Crates.io Documentation License: MIT

AI-powered data transformations between JSON-serializable types using OpenAI.

Quick Start

[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(())
}

⚠️ Important: Type Compatibility

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

Requirements

Dependencies:

  • ai-transform - The macro
  • ai-transform-runtime - Runtime (called by generated code)

Environment: OPENAI_API_KEY="your-key"

Types: Must implement Serialize + Deserialize + Default

How It Works

  1. Macro generates call to runtime
  2. Serializes source value to JSON
  3. Creates example schemas using Default
  4. Sends AI transformation prompt
  5. Deserializes response to target type

Examples

See examples/ for usage examples.

Considerations

  • Makes HTTP request to OpenAI per transformation
  • Costs based on OpenAI pricing

Configuration

  • OPENAI_API_KEY: Required
  • OPENAI_MODEL: Default "gpt-4o"
  • OPENAI_BASE_URL: Default OpenAI endpoint

Testing

cargo test                                    # Unit tests
OPENAI_API_KEY="key" cargo test -- --ignored # Integration tests

License

MIT

Commit count: 0

cargo fmt