Expand description
Procedural macro for AI-powered data transformations between JSON-serializable types.
Transforms data from one JSON-serializable type to another using OpenAI’s
language models. The idea is to enable semantic understanding when that is
useful and easier than writing deterministic parser by hand.
Important: This crate requires ai_transform_runtime to run properly.
[dependencies]
ai-transform = "0.1.0"
ai-transform-runtime = "0.1.0" # Required!§How It Works
- Macro Expansion: Generates
ai_transform_runtime::transform::<S, T>(value) - Serialization: Converts source value to JSON
- Schema Generation: Creates example JSON for both types using
Default - AI Request: Sends transformation prompt to
OpenAIwith context - Response Processing: Extracts and validates JSON from AI response
- Deserialization: Converts result to target type
§Considerations
- Each call makes an HTTP request to
OpenAI’s API - Consider caching for repeated transformations
- Response time: ~1-5 seconds depending on complexity
§Configuration
Environment variables:
OPENAI_API_KEY: Your API key (required)OPENAI_MODEL: Model to use (default:"gpt-4o")OPENAI_BASE_URL: API endpoint (default:OpenAI’s URL)
See transform! for usage info.
Macros§
- transform
- AI-powered data transformation macro.