retrage/gpt-macro
ChatGPT powered Rust proc macro that generates code at compile-time.
What it solves
This project provides a way to generate Rust code automatically during the compilation process using ChatGPT. It allows developers to fill in incomplete function implementations or generate tests based on a prompt and existing code structure.
How it works
The tool is implemented as a Rust procedural macro. When the compiler encounters a macro like auto_impl!, it sends a prompt and the target code snippet to the OpenAI API. The macro then extracts the completed code from the ChatGPT response and replaces the incomplete target code with the AI-generated implementation before the final compilation continues.
Who it’s for
Rust developers who want to experiment with AI-assisted code generation directly within their source code and build pipeline.
Highlights
- Compile-time generation: Code is generated and inserted into the binary during the build process.
- Prompt-driven implementation: Use a string literal as a prompt to tell the AI what the logic should be.
- Automatic test generation: Includes an
#[auto_test]attribute macro for creating tests. - OpenAI Integration: Leverages the ChatGPT API via the
OPENAI_API_KEYenvironment variable.
Related
- Project
- Project
- Project
- Project
- Dispatch