From 3feb7b333553db6684d76b5a028cb68a27a5498f Mon Sep 17 00:00:00 2001 From: Triston Armstrong Date: Sun, 5 Jan 2025 11:12:25 -0500 Subject: [PATCH] (wip): reworking architecture --- src/arg_parser.rs | 32 +++++++++++ src/commit_handler.rs | 7 +++ src/main.rs | 91 ++++++++++++++++++------------ src/mind_bridge.rs | 55 ------------------- src/pr_handler.rs | 6 ++ src/transporter.rs | 55 +++++++++++++++++++ src/uml.drawio | 125 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 280 insertions(+), 91 deletions(-) create mode 100644 src/arg_parser.rs create mode 100644 src/commit_handler.rs create mode 100644 src/pr_handler.rs create mode 100644 src/uml.drawio diff --git a/src/arg_parser.rs b/src/arg_parser.rs new file mode 100644 index 0000000..3a15f3a --- /dev/null +++ b/src/arg_parser.rs @@ -0,0 +1,32 @@ +use std::env::args; + +pub struct ArgParser {} + +#[derive(Debug)] +pub enum ParsedArg { + Commit, + PullRequest, +} + +impl ArgParser { + pub fn parse() -> Option { + let arg = args().nth(1); + if arg.is_none() { + // <-- interactive mode will go here + return None; + } + let arg = arg.unwrap(); + match arg.as_str() { + "-c" => Some(ParsedArg::Commit), + "-p" => Some(ParsedArg::PullRequest), + "-h" => { + println!("help stuff here"); + None + } + _ => { + println!("Available Commands: -c [commit] -p [pull request] -h [help]"); + None + } + } + } +} diff --git a/src/commit_handler.rs b/src/commit_handler.rs new file mode 100644 index 0000000..3475b72 --- /dev/null +++ b/src/commit_handler.rs @@ -0,0 +1,7 @@ +pub struct CommitHandler {} + +impl CommitHandler { + pub fn new() -> Option { + Some(String::from("create a short commit message from this diff, with format Task(): . only respond with the commit message")) + } +} diff --git a/src/main.rs b/src/main.rs index f38bb75..3577747 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,43 +1,62 @@ -mod git_grabber; -mod mind_bridge; -mod transporter; +mod arg_parser; +mod commit_handler; +mod pr_handler; +// mod git_grabber; +// mod mind_bridge; +// mod transporter; -use core::panic; -use git_grabber::GitGrabber; -use mind_bridge::*; -use transporter::Transporter; +use arg_parser::ArgParser; +use commit_handler::CommitHandler; +use pr_handler::PrHandler; +// use core::panic; +// use ferrum_input::ArgParser; +// use git_grabber::GitGrabber; +// use mind_bridge::*; +// use transporter::Transporter; fn main() { - let mut transporter = Transporter::new(); + let prompt: Option = match ArgParser::parse() { + Some(arg_parser::ParsedArg::Commit) => CommitHandler::new(), + Some(arg_parser::ParsedArg::PullRequest) => PrHandler::new(), + None => None, + }; - let gg = GitGrabber::new(); - let diff = gg.get_diff(); - let commits_msg = String::from("create a short commit message from this diff, with format Task(): . only respond with the commit message"); - let mind_gen_text = MindGen::new(commits_msg, format!("input: {}; branch: {}", diff, "dev")); - let res_text = transporter - .make_request(mind_gen_text) - .unwrap() - .text() - .unwrap(); - let response: Result = serde_json::from_str(&res_text); - if response.is_err() { - panic!("oop something went wrong: {:?}", response.err()); + if prompt.is_none() { + println!("Sorry nothing to do.. exiting"); + return; } - println!("{:#?}", response.unwrap().response); - let z = gg.generate_repo_desc("master", "dev"); - let pr_msg = String::from( - "create a pull request description in markdown from the following revlog output. Only respond with pr description, nothing else.", - ); - let mind_gen_repo = MindGen::new(pr_msg, z); - let repo_text = transporter - .make_request(mind_gen_repo) - .unwrap() - .text() - .unwrap(); - let repo_response: Result = serde_json::from_str(&repo_text); - if repo_response.is_err() { - panic!("oop something went wrong: {:?}", repo_response.err()); - } - println!("{:#?}", repo_response.unwrap().response); + println!("{prompt:?}") + + // let mut transporter = Transporter::new(); + // let gg = GitGrabber::new(); + // let diff = gg.get_diff(); + // let commits_msg = String::from("create a short commit message from this diff, with format Task(): . only respond with the commit message"); + // let mind_gen_text = MindGen::new(commits_msg, format!("input: {}; branch: {}", diff, "dev")); + // let res_text = transporter + // .make_request(mind_gen_text) + // .unwrap() + // .text() + // .unwrap(); + // let response: Result = serde_json::from_str(&res_text); + // if response.is_err() { + // panic!("oop something went wrong: {:?}", response.err()); + // } + // println!("{:#?}", response.unwrap().response); + + // let z = gg.generate_repo_desc("master", "dev"); + // let pr_msg = String::from( + // "create a pull request description in markdown from the following revlog output. Only respond with pr description, nothing else.", + // ); + // let mind_gen_repo = MindGen::new(pr_msg, z); + // let repo_text = transporter + // .make_request(mind_gen_repo) + // .unwrap() + // .text() + // .unwrap(); + // let repo_response: Result = serde_json::from_str(&repo_text); + // if repo_response.is_err() { + // panic!("oop something went wrong: {:?}", repo_response.err()); + // } + // println!("{:#?}", repo_response.unwrap().response); } diff --git a/src/mind_bridge.rs b/src/mind_bridge.rs index 9ad4e9f..8b13789 100644 --- a/src/mind_bridge.rs +++ b/src/mind_bridge.rs @@ -1,56 +1 @@ -use serde::{Deserialize, Serialize}; -// this is a test comment -#[derive(Debug, Deserialize)] -#[allow(unused)] -pub struct GenRes { - model: String, - created_at: String, - pub response: String, - done: bool, - total_duration: u64, - load_duration: u64, - prompt_eval_count: u64, - prompt_eval_duration: u64, - eval_count: u64, - eval_duration: u64, -} - -#[derive(Debug, Serialize)] -struct GenOptions { - temperature: f32, - num_predict: u8, - repeat_last_n: u8, - top_k: u8, - top_p: f32, -} - -#[derive(Debug, Serialize)] -pub struct MindGen { - model: String, - prompt: String, - stream: bool, - raw: bool, - system: String, - options: GenOptions, -} - -impl MindGen { - #[allow(unused)] - pub fn new(directions: String, input: String) -> Self { - Self { - model: String::from("llama3.1"), - stream: false, - raw: false, - prompt: input, - system: directions, - options: GenOptions { - temperature: 0.1, - num_predict: 0, - repeat_last_n: 0, - top_k: 10, - top_p: 0.5, - }, - } - } -} diff --git a/src/pr_handler.rs b/src/pr_handler.rs new file mode 100644 index 0000000..2f6885f --- /dev/null +++ b/src/pr_handler.rs @@ -0,0 +1,6 @@ +pub struct PrHandler {} +impl PrHandler { + pub fn new() -> Option { + Some("Pull Request Handler".to_string()) + } +} diff --git a/src/transporter.rs b/src/transporter.rs index 3f1d803..e982a59 100644 --- a/src/transporter.rs +++ b/src/transporter.rs @@ -1,5 +1,6 @@ use crate::MindGen; use reqwest::blocking::Client; +use serde::{Deserialize, Serialize}; #[allow(unused)] pub static OLLAMA_ENDP: &str = "http://localhost:11434/api/generate"; @@ -9,6 +10,60 @@ pub struct Transporter { pub client: Client, } +#[derive(Debug, Deserialize)] +#[allow(unused)] +pub struct GenRes { + model: String, + created_at: String, + pub response: String, + done: bool, + total_duration: u64, + load_duration: u64, + prompt_eval_count: u64, + prompt_eval_duration: u64, + eval_count: u64, + eval_duration: u64, +} + +#[derive(Debug, Serialize)] +struct GenOptions { + temperature: f32, + num_predict: u8, + repeat_last_n: u8, + top_k: u8, + top_p: f32, +} + +#[derive(Debug, Serialize)] +pub struct MindGen { + model: String, + prompt: String, + stream: bool, + raw: bool, + system: String, + options: GenOptions, +} + +impl MindGen { + #[allow(unused)] + pub fn new(directions: String, input: String) -> Self { + Self { + model: String::from("llama3.1"), + stream: false, + raw: false, + prompt: input, + system: directions, + options: GenOptions { + temperature: 0.1, + num_predict: 0, + repeat_last_n: 0, + top_k: 10, + top_p: 0.5, + }, + } + } +} + #[allow(unused)] impl Transporter { #[allow(unused)] diff --git a/src/uml.drawio b/src/uml.drawio new file mode 100644 index 0000000..f663125 --- /dev/null +++ b/src/uml.drawio @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +