Crates.io | ai_functions |
lib.rs | ai_functions |
version | 0.1.1 |
source | src |
created_at | 2023-06-07 10:03:43.937948 |
updated_at | 2023-06-07 10:11:27.062446 |
description | Procedural macro for creating text from a function for use in Large Language Models |
homepage | |
repository | |
max_upload_size | |
id | 884635 |
size | 4,516 |
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.
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.
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.
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}");
}