#language-model #procedural #proc-macro #definition #i32 #ai #string

macro ai_functions

Procedural macro for creating text from a function for use in Large Language Models

2 releases

0.1.1 Jun 7, 2023
0.1.0 Jun 7, 2023

#1009 in Procedural macros

Download history 47/week @ 2024-01-01 52/week @ 2024-01-08 58/week @ 2024-01-15 38/week @ 2024-01-22 38/week @ 2024-01-29 48/week @ 2024-02-05 69/week @ 2024-02-12 101/week @ 2024-02-19 81/week @ 2024-02-26 84/week @ 2024-03-04 104/week @ 2024-03-11 101/week @ 2024-03-18 105/week @ 2024-03-25 151/week @ 2024-04-01 77/week @ 2024-04-08 107/week @ 2024-04-15

452 downloads per month

MIT license

5KB

AI Function Crate

The ai_function crate provides a Rust procedural macro that allows you to transform any function into a function that returns its own definition as a string. This is useful for sending the function's code to a large language model for further processing.

Installation

Add the following to your Cargo.toml file:

[dependencies]
ai_function = "0.1.0"

Then run cargo build to download and compile the ai_function crate.

Usage

To use the ai_function macro, simply annotate your function with #[ai_function].

use ai_function::ai_function;

#[ai_function]
fn example_function(arg: i32) -> i32 {
  arg \* 2
}

When you call example_function(), instead of returning arg * 2, it will return a string containing the source code of the example_function.

Limitations

The #[ai_function] macro currently does not support functions with complex control flow like loops or conditionals. It only supports simple function definitions.

use ai_functions::ai_function;

#[ai_function]
fn add(a: i32, b: i32) -> i32 {
    a + b
}

fn main() {
    assert_eq!(add(2, 3), "fn add(a: i32, b: i32) -> i32 {\n    a + b\n}");
}

Dependencies

~305–760KB
~18K SLoC