diff --git a/src/git_grabber.rs b/src/git_grabber.rs index f4220a3..1f4ff3f 100644 --- a/src/git_grabber.rs +++ b/src/git_grabber.rs @@ -1,4 +1,9 @@ -use std::{fs::write, io::Write, process::Command, str::from_utf8}; +use std::{ + fs::write, + io::Write, + process::{Command, Output}, + str::from_utf8, +}; // this is a comment test here pub struct GitGrabber {} @@ -25,4 +30,23 @@ impl GitGrabber { let b = from_utf8(&output.stdout).unwrap(); String::from(b) } + + pub fn generate_repo_desc(&self, origin_branch: &str, local_branch: &str) -> String { + let output = Command::new("git") + .args([ + "rev-list", + "--left-right", + "--pretty=oneline", + &format!( + "{}...{}", + origin_branch.to_string(), + local_branch.to_string() + ), + ]) + .output() + .expect("Failed to get repo details"); + + let b = from_utf8(&output.stdout).unwrap(); + String::from(b) + } } diff --git a/src/main.rs b/src/main.rs index c7953e7..f38bb75 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,17 +12,32 @@ fn main() { let gg = GitGrabber::new(); let diff = gg.get_diff(); - let mind_gen_text = MindGen::new(format!("input: {}; branch: {}", diff, "dev")); + 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 fc253e3..9ad4e9f 100644 --- a/src/mind_bridge.rs +++ b/src/mind_bridge.rs @@ -1,56 +1,56 @@ - use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; - // this is a test comment - #[derive(Debug, Deserialize)] +// 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 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(input: String) -> Self { - Self { + pub fn new(directions: String, input: String) -> Self { + Self { model: String::from("llama3.1"), stream: false, raw: false, prompt: input, - system: String::from("create a short commit message from this diff, with format Task(): . only respond with the commit message"), - options: GenOptions { + system: directions, + options: GenOptions { temperature: 0.1, num_predict: 0, repeat_last_n: 0, top_k: 10, - top_p: 0.5 - } + top_p: 0.5, + }, } } }