gpt-macro  by retrage

Rust proc macro for compile-time code generation via ChatGPT

created 2 years ago
652 stars

Top 52.1% on sourcepulse

GitHubView on GitHub
Project Summary

This Rust crate provides a compile-time code generation utility powered by OpenAI's ChatGPT. It targets Rust developers seeking to automate repetitive coding tasks, such as generating function implementations or unit tests, by leveraging natural language prompts. The primary benefit is reduced boilerplate and faster development cycles.

How It Works

The gpt-macro crate utilizes Rust's procedural macro system to intercept code during compilation. The auto_impl! macro takes a natural language prompt and a code stub, sends them to the OpenAI API, and replaces the stub with the generated code from the API's response. The auto_test macro similarly generates unit tests based on provided test case names and a function stub. This approach integrates AI-driven code generation directly into the Rust build process.

Quick Start & Requirements

  • Install via cargo add gpt-macro.
  • Requires an OpenAI API key set as the OPENAI_API_KEY environment variable.
  • Uses the rustfmt tool for code formatting.

Highlighted Details

  • auto_impl!{} macro for generating function implementations from prompts.
  • #[auto_test(...)] attribute macro for generating unit tests.
  • Integrates directly into the Rust compile-time workflow.

Maintenance & Community

  • The project is maintained by retrage.
  • No community links (Discord, Slack) or roadmap are provided in the README.

Licensing & Compatibility

  • Released under the MIT license.
  • Permissive license suitable for commercial use and integration into closed-source projects.

Limitations & Caveats

The effectiveness of code generation is dependent on the quality of the prompt and the capabilities of the OpenAI API. Compilation time will increase due to external API calls. The project is in its early stages, and extensive testing or formal benchmarks are not yet available.

Health Check
Last commit

3 weeks ago

Responsiveness

Inactive

Pull Requests (30d)
2
Issues (30d)
0
Star History
13 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.