AI Transform
AI-powered data transformations between JSON-serializable types using OpenAI.
Quick Start
[]
= "0.1.0"
= "0.1.0" # Required
= { = "1.0.219", = ["derive"] }
= { = "1.45.1", = ["full"] }
use transform;
use ;
async
⚠️ 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:
// Clear semantic relationship
Requirements
Dependencies:
ai-transform
- The macroai-transform-runtime
- Runtime (called by generated code)
Environment: OPENAI_API_KEY="your-key"
Types: Must implement Serialize + Deserialize + Default
How It Works
- Macro generates call to runtime
- Serializes source value to JSON
- Creates example schemas using
Default
- Sends AI transformation prompt
- 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
: RequiredOPENAI_MODEL
: Default"gpt-4o"
OPENAI_BASE_URL
: Default OpenAI endpoint
Testing
OPENAI_API_KEY="key"
License
MIT