(wip): reworking architecture

This commit is contained in:
Triston Armstrong 2025-01-05 11:12:25 -05:00
parent e5036b55b1
commit 3feb7b3335
7 changed files with 280 additions and 91 deletions

32
src/arg_parser.rs Normal file
View File

@ -0,0 +1,32 @@
use std::env::args;
pub struct ArgParser {}
#[derive(Debug)]
pub enum ParsedArg {
Commit,
PullRequest,
}
impl ArgParser {
pub fn parse() -> Option<ParsedArg> {
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
}
}
}
}

7
src/commit_handler.rs Normal file
View File

@ -0,0 +1,7 @@
pub struct CommitHandler {}
impl CommitHandler {
pub fn new() -> Option<String> {
Some(String::from("create a short commit message from this diff, with format Task(<branch_name>): <commit_message>. only respond with the commit message"))
}
}

View File

@ -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<String> = 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(<branch_name>): <commit_message>. 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<GenRes, _> = 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<GenRes, _> = 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(<branch_name>): <commit_message>. 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<GenRes, _> = 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<GenRes, _> = serde_json::from_str(&repo_text);
// if repo_response.is_err() {
// panic!("oop something went wrong: {:?}", repo_response.err());
// }
// println!("{:#?}", repo_response.unwrap().response);
}

View File

@ -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,
},
}
}
}

6
src/pr_handler.rs Normal file
View File

@ -0,0 +1,6 @@
pub struct PrHandler {}
impl PrHandler {
pub fn new() -> Option<String> {
Some("Pull Request Handler".to_string())
}
}

View File

@ -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)]

125
src/uml.drawio Normal file
View File

@ -0,0 +1,125 @@
<mxfile host="Electron" agent="Mozilla/5.0 (X11; Linux aarch64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/25.0.1 Chrome/128.0.6613.186 Electron/32.2.6 Safari/537.36" version="25.0.1">
<diagram name="Page-1" id="3ifs8vQQYQUBUYL4we8P">
<mxGraphModel dx="1824" dy="729" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="2AVEHZDF9yeEspTbbptQ-7" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="2AVEHZDF9yeEspTbbptQ-1" target="2AVEHZDF9yeEspTbbptQ-3" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-1" value="IN" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="110" y="30" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-2" value="Out" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="110" y="500" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-8" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="2AVEHZDF9yeEspTbbptQ-3" target="2AVEHZDF9yeEspTbbptQ-4" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-14" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" parent="1" source="2AVEHZDF9yeEspTbbptQ-3" target="2AVEHZDF9yeEspTbbptQ-5" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-3" value="Arg Parser" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="110" y="140" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-15" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" parent="1" source="2AVEHZDF9yeEspTbbptQ-5" target="2AVEHZDF9yeEspTbbptQ-6" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="PAK-VcJjs1wrBpZ3mVEH-2" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="1" source="2AVEHZDF9yeEspTbbptQ-5" target="PAK-VcJjs1wrBpZ3mVEH-1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-5" value="pull request handler" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="10" y="280" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-17" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="2AVEHZDF9yeEspTbbptQ-6" target="2AVEHZDF9yeEspTbbptQ-2" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-6" value="Ml interface" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="110" y="390" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-16" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="2AVEHZDF9yeEspTbbptQ-4" target="2AVEHZDF9yeEspTbbptQ-6" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="PAK-VcJjs1wrBpZ3mVEH-4" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="1" source="2AVEHZDF9yeEspTbbptQ-4" target="PAK-VcJjs1wrBpZ3mVEH-3">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-4" value="commit handler" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="210" y="280" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-18" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="2AVEHZDF9yeEspTbbptQ-19" target="2AVEHZDF9yeEspTbbptQ-23" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-19" value="IN" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="710" y="30" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-20" value="Out" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="710" y="500" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-21" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="2AVEHZDF9yeEspTbbptQ-23" target="2AVEHZDF9yeEspTbbptQ-29" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-22" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" parent="1" source="2AVEHZDF9yeEspTbbptQ-23" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="670" y="240" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-23" value="Arg Parser" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="710" y="140" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-24" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" parent="1" target="2AVEHZDF9yeEspTbbptQ-27" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="670" y="300" as="sourcePoint" />
</mxGeometry>
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-25" value="pull request handler" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="600" y="240" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-26" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="2AVEHZDF9yeEspTbbptQ-27" target="2AVEHZDF9yeEspTbbptQ-20" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-27" value="Ml interface" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="710" y="390" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-28" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="2AVEHZDF9yeEspTbbptQ-29" target="2AVEHZDF9yeEspTbbptQ-27" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-29" value="commit handler" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="810" y="240" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-30" value="Options Picker&lt;div&gt;interactive&lt;/div&gt;" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="910" y="140" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-33" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" parent="1" source="2AVEHZDF9yeEspTbbptQ-23" target="2AVEHZDF9yeEspTbbptQ-30" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points" />
</mxGeometry>
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-35" value="No args" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" parent="2AVEHZDF9yeEspTbbptQ-33" vertex="1" connectable="0">
<mxGeometry x="-0.1972" y="1" relative="1" as="geometry">
<mxPoint x="8" as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-34" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="2AVEHZDF9yeEspTbbptQ-30" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="830" y="189" as="targetPoint" />
<Array as="points">
<mxPoint x="870" y="189" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-43" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="2AVEHZDF9yeEspTbbptQ-42" target="2AVEHZDF9yeEspTbbptQ-19" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="2AVEHZDF9yeEspTbbptQ-42" value="config loader" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="890" y="40" width="80" height="40" as="geometry" />
</mxCell>
<mxCell id="PAK-VcJjs1wrBpZ3mVEH-1" value="PR branch diff" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="-130" y="290" width="100" height="40" as="geometry" />
</mxCell>
<mxCell id="PAK-VcJjs1wrBpZ3mVEH-3" value="staged diff" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="360" y="295" width="130" height="30" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>