Compare commits

..

No commits in common. "9716a6ea1b5123fe4c5ef402f987cee0b8887668" and "3c0a1c505cdd7b662ad7212bbea3ce3c78371d37" have entirely different histories.

6 changed files with 33 additions and 65 deletions

View File

@ -13,7 +13,6 @@ impl ArgParser {
let arg = args().nth(1);
if arg.is_none() {
// <-- interactive mode will go here
println!("...(future) interactive mode not implimented... exiting");
return None;
}
let arg = arg.unwrap();
@ -21,10 +20,13 @@ impl ArgParser {
"-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
}
_ => None,
}
}
}

View File

@ -4,17 +4,7 @@ pub struct CommitHandler {}
impl CommitHandler {
pub fn new() -> Option<(String, String)> {
let dirs = String::from(format!("
<Variables>
change_type: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
<Commit Instructions>
create a short commit message from this entire diff, with format <change_type>(<scope>): <commit_message>.
the commit message should vaguely describe the changes present unless a small change is made that can be
precisely described withtin a short commit message
<Response Constraints>
Only respond with the commit message.
"));
let prompt = GitGrabber::get_diff();
Some((dirs, prompt))
let dirs = String::from("create a short commit message from this diff, with format Task(<branch_name>): <commit_message>. only respond with the commit message");
Some((dirs, GitGrabber::get_diff()))
}
}

View File

@ -1,4 +1,3 @@
use core::panic;
use std::{
fs::write,
io::Write,
@ -21,39 +20,32 @@ impl GitGrabber {
.expect("Failed to get branch");
let b = from_utf8(&branch.stdout).unwrap();
String::from(b.strip_suffix("\n").unwrap())
String::from(b)
}
pub fn get_diff() -> String {
// just to print
let output = Command::new("git")
.args([
"diff",
"--staged",
"--ignore-all-space",
"--ignore-blank-lines",
"--ignore-cr-at-eol",
"--minimal",
"--no-prefix",
"--no-renames",
"--word-diff",
"--inter-hunk-context=0",
])
let staged_files_output = Command::new("git")
.args(["diff", "--staged"])
.output()
.expect("Failed to get diff");
if !output.status.success() {
panic!("Did you forget to stage your files?");
}
let b = from_utf8(&output.stdout).unwrap();
let b = from_utf8(&staged_files_output.stdout).unwrap();
String::from(b)
}
pub fn generate_repo_desc() -> String {
let curr_branch = GitGrabber::get_current_branch();
pub fn generate_repo_desc(origin_branch: &str, local_branch: &str) -> String {
let output = Command::new("git")
.args(["reflog", "show", &curr_branch])
.args([
"rev-list",
"--left-right",
"--pretty=oneline",
&format!(
"{}...{}",
origin_branch.to_string(),
local_branch.to_string()
),
])
.output()
.expect("Failed to get repo details");

View File

@ -16,19 +16,18 @@ fn main() {
None => None,
};
// 1+2 = 5
if prompt.is_none() {
println!("Sorry nothing to do.. exiting");
return;
}
let mut ml = MlInterface::new();
let (directions, content) = prompt.unwrap();
let body = MlBody::new(content, directions);
let res_text = ml.make_request(body).unwrap().text().unwrap();
let mind_gen_text = MlBody::new(content, directions);
let res_text = ml.make_request(mind_gen_text).unwrap().text().unwrap();
let response: Result<MlResponse, _> = serde_json::from_str(&res_text);
if response.is_err() {
panic!("oop something went wrong: {:?}", response.err());
}
println!("{:?}", response.unwrap().response);
println!("{:#?}", response.unwrap());
}

View File

@ -1,5 +1,3 @@
use std::error::Error;
use reqwest::blocking::Client;
use serde::{Deserialize, Serialize};
@ -50,7 +48,7 @@ impl MlBody {
prompt: content,
system: directions,
options: MlOptions {
temperature: 0.1,
temperature: 0.5,
num_predict: 0,
repeat_last_n: 0,
top_k: 10,
@ -75,15 +73,11 @@ impl MlInterface {
}
#[allow(unused)]
pub fn make_request(&mut self, gen_data: MlBody) -> Result<reqwest::blocking::Response, &str> {
if gen_data.prompt.len() < 1 {
panic!("No prompt provided");
}
pub fn make_request(
&mut self,
gen_data: MlBody,
) -> Result<reqwest::blocking::Response, reqwest::Error> {
let json_body = serde_json::to_string(&gen_data).unwrap();
let res = self.client.post(OLLAMA_ENDP).body(json_body).send();
if res.is_err() {
panic!("Failed to send ollama payload");
}
Ok(res.unwrap())
self.client.post(OLLAMA_ENDP).body(json_body).send()
}
}

View File

@ -3,16 +3,7 @@ use crate::git_grabber::GitGrabber;
pub struct PrHandler {}
impl PrHandler {
pub fn new() -> Option<(String, String)> {
let directions = String::from("
<Variables>
change_type: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
<PR Title>
create a short PR title from this diff, with format <change_type>(<scope>): <pr_description>.
<PR Description>
create an additional PR Description in markdown format to describe the changes made in this diff.
<Response Constraints>
Only respond with the Pr title and Pr description.
");
Some((directions, GitGrabber::generate_repo_desc()))
let dirs = String::from("Pull Request Handler");
Some((dirs, GitGrabber::generate_repo_desc("", "")))
}
}