Skip to content

Commit

Permalink
feat: Improve OpenAI request function and commit message generation
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisostome01 committed May 5, 2024
1 parent bda3c80 commit b669dee
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ fn get_diff(repo: &Repository) -> Result<String, git2::Error>{
Ok(diff_content)
}

async fn send_openai_request(api_key: &str, prompt: &str) -> Result<(), Box<dyn Error>> {
async fn send_openai_request(api_key: &str, change_diff: String) -> Result<(), Box<dyn Error>> {
let prompt = format!("Generate a semmantic commit basaed on the following change diff, commit should not be more than 100chars and prefixs are [feat:, chore:, refactor:, fix: ], do not mention change diff in you commit \n change diff: {}", change_diff);

let client = Client::new();
let params = json!({
"model": "gpt-3.5-turbo",
Expand Down Expand Up @@ -81,9 +83,8 @@ async fn main() -> Result<(), git2::Error> {

let change_diff = get_diff(&repo)?;

let prompt = format!("Generate a semmantic commit basaed on the following change diff, commit should not be more than 100chars and prefixs are [feat:, chore:, refactor:, fix: ], do not mention change diff in you commit \n change diff: {}", change_diff);

let commit = send_openai_request(&openai_api_key, &prompt).await;

let commit = send_openai_request(&openai_api_key, change_diff).await;

println!("{:?}", commit);
Ok(())
Expand Down

0 comments on commit b669dee

Please sign in to comment.