ai-transform 0.1.0

Procedural macro for AI-powered data transformations between JSON-serializable types
Documentation
# AI Transform

[![Crates.io](https://img.shields.io/crates/v/ai-transform.svg)](https://crates.io/crates/ai-transform)
[![Documentation](https://docs.rs/ai-transform/badge.svg)](https://docs.rs/ai-transform)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

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

## Quick Start

```toml
[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"] }
```

```rust
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:**
```rust
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/`](./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

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

## License

MIT