evgenyigumnov / rustsn

Code snippets generator via LLMs and compiler/tester via build tools
GNU General Public License v3.0
18 stars 5 forks source link

rustsn - Code snippets generator via LLMs and compiler/tester via build tools

A Rust-based tool that automates the generation, compilation, and testing of code using Large Language Models (LLMs). It interacts with LLMs to generate code based on user-provided explanations, compiles the code, resolves dependencies, and runs tests to ensure functionality.

Supported languages

How it works

stateDiagram
[*] --> GenerateCode
GenerateCode --> CompileCode
CompileCode --> GenerateTests : Compilation successful
CompileCode --> CheckDependencies : Compilation failed
CheckDependencies --> GenerateDependencies : Dependencies required
GenerateDependencies --> CompileCode
CheckDependencies --> RewriteCode : No dependencies required
RewriteCode --> CompileCode
GenerateTests --> RunTests
RunTests --> TestsPass : Tests passed
RunTests --> DecideFix : Tests failed
DecideFix --> RewriteCode : Error in code
DecideFix --> RewriteTests : Error in tests
RewriteCode --> CompileCode
RewriteTests --> RunTests
TestsPass --> [*]

Project name explanation

Project name "rustsn" is a combination of "Rust" and "Snippet" words. Code snippets are generated by the tool written in Rust language.

Installation

Prerequisites

Clone the Repository

git clone https://github.com/evgenyigumnov/rustsn.git
cd rustsn

Usage

  1. Start the Program

    cargo run -- --lang=rust
  2. Provide an Explanation

    The program will prompt:

    Explain what the function should do:

    Enter a detailed explanation of the function you want to generate.

    parse json string and return struct User (age, name)
    1. Automatic Processing

    The tool will:

  1. Completion

    Once the code compiles and all tests pass, the final code and tests will be displayed and result of work will be saved in sandbox folder.

For example:

[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize, Debug)]
struct User {
    name: String,
    age: u32,
}

fn solution(json_string: &str) -> Result<User, serde_json::Error> {
    let user: User = serde_json::from_str(json_string)?;
    Ok(user)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_solution() {
        let json_string = r#"{"name": "John Doe", "age": 30}"#;
        let user = solution(json_string).unwrap();
        assert_eq!(user.name, "John Doe");
        assert_eq!(user.age, 30);
    }

    #[test]
    fn test_solution_invalid_json() {
        let json_string = r#"{"name": "John Doe", "age": }"#;
        assert!(solution(json_string).is_err());
    }
}

Finished

Examples of queries for code generation

  1. take 2 params and multiply and return result

  2. take 1 parameter multiply by random number and return tuple with result and random number

  3. parse json string and return struct User (age, name)

Contributing

I would love to see contributions from the community. If you experience bugs, feel free to open an issue. If you would like to implement a new feature or bug fix, please follow the steps:

  1. Read "Contributor License Agreement (CLA)"
  2. Do fork
  3. Add comment to the issue that you are going to work on it
  4. Create pull request

Versions

0.14.0 - Swift 23 September 2024

0.13.0 - Kotlin 23 September 2024

0.12.0 - Python 22 September 2024

0.11.0 - PHP 22 September 2024

0.10.0 - JavaScript 22 September 2024

0.9.0 - Scala 22 September 2024

0.8.0 - Java 22 September 2024

0.7.0 - Simplification 22 September 2024

0.6.0 - Add "clap" crate 21 September 2024

0.5.0 - Support multi-language code generation 21 September 2024

0.4.0 - LLM Generate Result Extraction - 20 September 2024

0.3.0 - State Machine - 20 September 2024

0.2.0 - State Machine - 19 September 2024

0.1.0 - Prototype - 17 September 2024