functions_ai

Crates.iofunctions_ai
lib.rsfunctions_ai
version0.1.4
sourcesrc
created_at2024-01-01 10:59:56.081608
updated_at2024-01-01 11:29:09.997819
descriptionFunction to string implementation for LLMs
homepage
repository
max_upload_size
id1085260
size4,427
Jeric (jericodings)

documentation

README

Functions AI Crate

The 'function_ai' 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]
function_ai = "0.1.0"

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

Usage

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

use function_ai::function_ai;

#[function_ai]
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 #[function_ai] macro currently does not support functions with complex control flow like loops or conditionals. It only supports simple function definitions.

use function_ais::function_ai;

#[function_ai]
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}");
}
Commit count: 0

cargo fmt