refactor some things
This commit is contained in:
parent
149458411f
commit
3c0a1c505c
@ -1,7 +1,10 @@
|
|||||||
|
use crate::git_grabber::GitGrabber;
|
||||||
|
|
||||||
pub struct CommitHandler {}
|
pub struct CommitHandler {}
|
||||||
|
|
||||||
impl CommitHandler {
|
impl CommitHandler {
|
||||||
pub fn new() -> Option<String> {
|
pub fn new() -> Option<(String, 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"))
|
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()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,25 +13,28 @@ impl GitGrabber {
|
|||||||
GitGrabber {}
|
GitGrabber {}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_diff(&self) -> String {
|
pub fn get_current_branch() -> String {
|
||||||
// just to print
|
let branch = Command::new("git")
|
||||||
let staged_files_output = Command::new("git")
|
.args(["branch", "--show-current"])
|
||||||
.args(["diff", "--staged", "--stat"])
|
|
||||||
.output()
|
.output()
|
||||||
.expect("Failed to get diff");
|
.expect("Failed to get branch");
|
||||||
let _ = std::io::stdout().write_all(&staged_files_output.stdout);
|
|
||||||
|
|
||||||
// actual output
|
let b = from_utf8(&branch.stdout).unwrap();
|
||||||
let output = Command::new("git")
|
|
||||||
.args(["diff", "--staged", "--", ".", "':(exclude)*lock*'"])
|
|
||||||
.output()
|
|
||||||
.expect("Failed to execute process");
|
|
||||||
|
|
||||||
let b = from_utf8(&output.stdout).unwrap();
|
|
||||||
String::from(b)
|
String::from(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_repo_desc(&self, origin_branch: &str, local_branch: &str) -> String {
|
pub fn get_diff() -> String {
|
||||||
|
// just to print
|
||||||
|
let staged_files_output = Command::new("git")
|
||||||
|
.args(["diff", "--staged"])
|
||||||
|
.output()
|
||||||
|
.expect("Failed to get diff");
|
||||||
|
|
||||||
|
let b = from_utf8(&staged_files_output.stdout).unwrap();
|
||||||
|
String::from(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn generate_repo_desc(origin_branch: &str, local_branch: &str) -> String {
|
||||||
let output = Command::new("git")
|
let output = Command::new("git")
|
||||||
.args([
|
.args([
|
||||||
"rev-list",
|
"rev-list",
|
||||||
|
55
src/main.rs
55
src/main.rs
@ -1,21 +1,16 @@
|
|||||||
mod arg_parser;
|
mod arg_parser;
|
||||||
mod commit_handler;
|
mod commit_handler;
|
||||||
|
mod git_grabber;
|
||||||
|
mod ml_interface;
|
||||||
mod pr_handler;
|
mod pr_handler;
|
||||||
// mod git_grabber;
|
|
||||||
// mod mind_bridge;
|
|
||||||
// mod transporter;
|
|
||||||
|
|
||||||
use arg_parser::ArgParser;
|
use arg_parser::ArgParser;
|
||||||
use commit_handler::CommitHandler;
|
use commit_handler::CommitHandler;
|
||||||
|
use ml_interface::{MlBody, MlInterface, MlResponse};
|
||||||
use pr_handler::PrHandler;
|
use pr_handler::PrHandler;
|
||||||
// use core::panic;
|
|
||||||
// use ferrum_input::ArgParser;
|
|
||||||
// use git_grabber::GitGrabber;
|
|
||||||
// use mind_bridge::*;
|
|
||||||
// use transporter::Transporter;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let prompt: Option<String> = match ArgParser::parse() {
|
let prompt: Option<(String, String)> = match ArgParser::parse() {
|
||||||
Some(arg_parser::ParsedArg::Commit) => CommitHandler::new(),
|
Some(arg_parser::ParsedArg::Commit) => CommitHandler::new(),
|
||||||
Some(arg_parser::ParsedArg::PullRequest) => PrHandler::new(),
|
Some(arg_parser::ParsedArg::PullRequest) => PrHandler::new(),
|
||||||
None => None,
|
None => None,
|
||||||
@ -26,37 +21,13 @@ fn main() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("{prompt:?}")
|
let mut ml = MlInterface::new();
|
||||||
|
let (directions, content) = prompt.unwrap();
|
||||||
// let mut transporter = Transporter::new();
|
let mind_gen_text = MlBody::new(content, directions);
|
||||||
// let gg = GitGrabber::new();
|
let res_text = ml.make_request(mind_gen_text).unwrap().text().unwrap();
|
||||||
// let diff = gg.get_diff();
|
let response: Result<MlResponse, _> = serde_json::from_str(&res_text);
|
||||||
// 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");
|
if response.is_err() {
|
||||||
// let mind_gen_text = MindGen::new(commits_msg, format!("input: {}; branch: {}", diff, "dev"));
|
panic!("oop something went wrong: {:?}", response.err());
|
||||||
// let res_text = transporter
|
}
|
||||||
// .make_request(mind_gen_text)
|
println!("{:#?}", response.unwrap());
|
||||||
// .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);
|
|
||||||
}
|
}
|
||||||
|
@ -1 +0,0 @@
|
|||||||
|
|
@ -1,18 +1,12 @@
|
|||||||
use crate::MindGen;
|
|
||||||
use reqwest::blocking::Client;
|
use reqwest::blocking::Client;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub static OLLAMA_ENDP: &str = "http://localhost:11434/api/generate";
|
pub static OLLAMA_ENDP: &str = "http://localhost:11434/api/generate";
|
||||||
|
|
||||||
#[allow(unused)]
|
|
||||||
pub struct Transporter {
|
|
||||||
pub client: Client,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub struct GenRes {
|
pub struct MlResponse {
|
||||||
model: String,
|
model: String,
|
||||||
created_at: String,
|
created_at: String,
|
||||||
pub response: String,
|
pub response: String,
|
||||||
@ -26,7 +20,7 @@ pub struct GenRes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
struct GenOptions {
|
struct MlOptions {
|
||||||
temperature: f32,
|
temperature: f32,
|
||||||
num_predict: u8,
|
num_predict: u8,
|
||||||
repeat_last_n: u8,
|
repeat_last_n: u8,
|
||||||
@ -35,26 +29,26 @@ struct GenOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub struct MindGen {
|
pub struct MlBody {
|
||||||
model: String,
|
model: String,
|
||||||
prompt: String,
|
prompt: String,
|
||||||
stream: bool,
|
stream: bool,
|
||||||
raw: bool,
|
raw: bool,
|
||||||
system: String,
|
system: String,
|
||||||
options: GenOptions,
|
options: MlOptions,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MindGen {
|
impl MlBody {
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub fn new(directions: String, input: String) -> Self {
|
pub fn new(content: String, directions: String) -> Self {
|
||||||
Self {
|
Self {
|
||||||
model: String::from("llama3.1"),
|
model: String::from("llama3.1"),
|
||||||
stream: false,
|
stream: false,
|
||||||
raw: false,
|
raw: false,
|
||||||
prompt: input,
|
prompt: content,
|
||||||
system: directions,
|
system: directions,
|
||||||
options: GenOptions {
|
options: MlOptions {
|
||||||
temperature: 0.1,
|
temperature: 0.5,
|
||||||
num_predict: 0,
|
num_predict: 0,
|
||||||
repeat_last_n: 0,
|
repeat_last_n: 0,
|
||||||
top_k: 10,
|
top_k: 10,
|
||||||
@ -65,7 +59,12 @@ impl MindGen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
impl Transporter {
|
pub struct MlInterface {
|
||||||
|
pub client: Client,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
impl MlInterface {
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -76,7 +75,7 @@ impl Transporter {
|
|||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub fn make_request(
|
pub fn make_request(
|
||||||
&mut self,
|
&mut self,
|
||||||
gen_data: MindGen,
|
gen_data: MlBody,
|
||||||
) -> Result<reqwest::blocking::Response, reqwest::Error> {
|
) -> Result<reqwest::blocking::Response, reqwest::Error> {
|
||||||
let json_body = serde_json::to_string(&gen_data).unwrap();
|
let json_body = serde_json::to_string(&gen_data).unwrap();
|
||||||
self.client.post(OLLAMA_ENDP).body(json_body).send()
|
self.client.post(OLLAMA_ENDP).body(json_body).send()
|
@ -1,6 +1,9 @@
|
|||||||
|
use crate::git_grabber::GitGrabber;
|
||||||
|
|
||||||
pub struct PrHandler {}
|
pub struct PrHandler {}
|
||||||
impl PrHandler {
|
impl PrHandler {
|
||||||
pub fn new() -> Option<String> {
|
pub fn new() -> Option<(String, String)> {
|
||||||
Some("Pull Request Handler".to_string())
|
let dirs = String::from("Pull Request Handler");
|
||||||
|
Some((dirs, GitGrabber::generate_repo_desc("", "")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user