Rust macro that uses GPT3 codex to generate code at compiletime

Related tags

Utilities gpt3_macro
Overview

gpt3_macro

GitHub Workflow Status Crates.io Lines of code Crates.io Crates.io

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.

Example 1

create_function!("checks if number is prime" fn is_prime(num: u64) -> bool);

will (usually) expand to something like:

// A rust function that checks if number is prime
fn is_prime(num: u64) -> bool {
    if num == 2 {
        return true;
    }
    if num % 2 == 0 {
        return false;
    }
    let mut i = 3;
    while i * i <= num {
        if num % i == 0 {
            return false;
        }
        i += 2;
    }
    true
}

Example 2

create_function!("prints n elements of the fibonnacci sequence to stdout" fn fib(n: u64));

sometimes expands to:

// prints n elements of the fibonnacci sequence to stdout
fn fib (n : u64) {
    let mut a = 0;
    let mut b = 1;
    let mut c = 0;
    for _ in 0..n {
        c = a + b;
        a = b;
        b = c;
        println!("{}", c);
    }
}

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.2.2"

to your Cargo.toml

You might also like...
No-nonsense input!(...) macro for Rust

No-nonsense input!(...) macro for Rust

hado-rshado — A little macro for writing haskell-like do expressions without too much ceremony

hado Monadic haskell-like expressions brought to rust via the hado! macro What? A little macro for writing haskell-like do expressions without too muc

Yet another geter/setter derive macro.

Gusket Gusket is a getter/setter derive macro. Comparison with getset: gusket only exposes one derive macro. No need to derive(Getters, MutGetters, Se

A proc-macro to get Vecu8 from struct and vise versa

byteme A proc-macro to convert a struct into Vec and back by implemeting From trait on the struct. The conversion is Big Endian by default. We have ma

Derive macro for encoding/decoding instructions and operands as bytecode

bytecoding Derive macro for encoding and decoding instructions and operands as bytecode. Documentation License Licensed under either of Apache License

Derive macro implementing 'From' for structs

derive-from-ext A derive macro that auto implements 'std::convert::From' for structs. The default behaviour is to create an instance of the structure

A proc macro for creating compile-time checked CSS class sets, in the style of classNames

semester Semester is a declarative CSS conditional class name joiner, in the style of React's classnames. It's intended for use in web frameworks (lik

A set of bison skeleton files that can be used to generate a Bison grammar that is written in Rust.

rust-bison-skeleton A set of bison skeleton files that can be used to generate a Bison grammar that is written in Rust. Technically it's more like a B

Generate Rust register maps (`struct`s) from SVD files

svd2rust Generate Rust register maps (structs) from SVD files This project is developed and maintained by the Tools team. Documentation API Minimum Su

Comments
  • Cache generated code to reduce API usage

    Cache generated code to reduce API usage

    Currently, on incremental builds, an Api request would be made. Having some sort of local cache would help prevent running into any API limits usage for the stated case. Something like cacache alongside the description (and maybe an optional source path) as the cache key could serve some good :)

    And then maybe exposing an optional feature flag to invalidate/not utilize the cache during build wouldn't be bad also.

    opened by tnkemdilim 0
Owner
Maximilian von Gaisberg
https://twitter.com/vongaisberg https://keybase.io/vongaisberg
Maximilian von Gaisberg
Communicate with OpenAi's GPT3.5 (ChatGPT) API.

ChatGPT Rust Communicate with OpenAi's GPT3.5 (ChatGPT) API. Usage use chat_gpt_rs::prelude::*; #[tokio::main] async fn main() { let token = Toke

Aiden 4 Mar 10, 2023
Proc. macro to generate C-like `enum` tags.

Continuous Integration Documentation Crates.io #[derive(EnumTag)] This crate provides a proc. macro to derive the EnumTag trait for the given Rust enu

Robin Freyler 5 Mar 27, 2023
A simple to use rust package to generate or parse Twitter snowflake IDs,generate time sortable 64 bits unique ids for distributed systems

A simple to use rust package to generate or parse Twitter snowflake IDs,generate time sortable 64 bits unique ids for distributed systems (inspired from twitter snowflake)

houseme 5 Oct 6, 2022
Generate bindings to use Rust code in Qt and QML

Rust Qt Binding Generator This code generator gets you started quickly to use Rust code from Qt and QML. In other words, it helps to create a Qt based

KDE GitHub Mirror 768 Dec 24, 2022
A Kubernetes Operator that uses Bitwarden to provision secrets, written in Rust with kube-rs

bitwarden-secret-operator-rs bitwarden-secret-operator-rs is a kubernetes Operator written in Rust thanks to kube-rs. The goal is to create Kubernetes

Blowa 4 Mar 28, 2024
Like jq, but for HTML. Uses CSS selectors to extract bits content from HTML files.

Like jq, but for HTML. Uses CSS selectors to extract bits content from HTML files. Mozilla's MDN has a good reference for CSS selector syntax.

Michael Maclean 6.3k Jan 3, 2023
Macro for Python-esque comprehensions in Rust

Cute Macro for Python-esque list comprehensions in Rust. The c! macro implements list and hashmap comprehensions similar to those found in Python, all

Matt Gathu 306 Jan 6, 2023
A Rust macro for writing regex pattern matching.

regexm A Rust macro for writing regex pattern matching.

Takayuki Maeda 46 Oct 24, 2022
Rust crate that provides a convenient macro to quickly plot variables.

Debug Plotter This crate provides a convenient macro to quickly plot variables. Documentation For more information on how to use this crate, please ta

Fabian Bösiger 82 Dec 31, 2022
Rust macro to make recursive function run on the heap (i.e. no stack overflow).

Decurse Example #[decurse::decurse] // ?? Slap this on your recursive function and stop worrying about stack overflow! fn factorial(x: u32) -> u32 {

Wisha W. 18 Dec 28, 2022