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.
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 "rustsn" is a combination of "Rust" and "Snippet" words. Code snippets are generated by the tool written in Rust language.
ollama run gemma2:27b
After downloading the model, you can say "hello" to the model to check if it is working correctly. After that, you can use type "Ctrl+D" to exit the model.
git clone https://github.com/evgenyigumnov/rustsn.git
cd rustsn
Start the Program
cargo run -- --lang=rust
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)
The tool will:
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
take 2 params and multiply and return result
take 1 parameter multiply by random number and return tuple with result and random number
parse json string and return struct User (age, name)
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: