gpt3_macro
Rust macro that uses GPT3 codex to generate code at compiletime.
Just describe what you want the function to do and (optionally) define a function header. The macro will generate the sourcecode for you at compiletime.
It can also generate tests for you. (See example 3)
Example 1
create_function!;
will (usually) expand to something like:
// A rust function that checks if number is prime
Example 2
create_function!;
sometimes expands to:
// prints n elements of the fibonnacci sequence to stdout
Example 3: Code and test generation
create_function_and_tests!
will often expand to:
// A rust function that fizzbuzz
// 5 tests for the function
Pros and Cons
Pros | Cons |
---|---|
Spend less time coding simple utility functions and save your brainpower for the big problems | Compilation takes way longer |
Create more readable sourcecode — the documentation IS the sourcode. | You need to be part of the GPT3 Codex private beta |
A little nondeterminism during compilation is fun! | GPT3 Codex will not always be free :( |
Installation
Generate an OpenAI API key at the OpenAI Account Page and set the $OPENAI_KEY
environment variable
Then execute
cargo add gpt3_macro
or manually add
gpt3_macro = "0.3.1"
to your Cargo.toml