Skip to content

Commit

Permalink
feat(actor): add auto-commit feature to streamline message generation…
Browse files Browse the repository at this point in the history
… and commit process

This commit introduces an auto-commit functionality in the Actor struct to allow automatic generation and committing of messages, enhancing the usability of the application by reducing manual steps for users.
  • Loading branch information
dikkadev committed Aug 30, 2024
1 parent 6bcaa32 commit c9b3975
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "turbocommit"
version = "0.18.0"
version = "0.19.1"
edition = "2021"
authors = [ "Sett",]
description = "A CLI tool to create commit messages with OpenAI GPT models"
Expand Down
10 changes: 10 additions & 0 deletions src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ impl Actor {

Ok(())
}

pub async fn auto_commit(&mut self) -> anyhow::Result<String> {
let choices = self.ask().await?;
if choices.is_empty() {
return Err(anyhow::anyhow!("No commit message generated"));
}
let message = choices[0].clone();
git::commit(message.clone())?;
Ok(message)
}
}

enum Task {
Expand Down
10 changes: 9 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::config::Config;
use crate::openai::count_token;
use crate::model;
use crate::openai::count_token;
use colored::Colorize;
use std::str::FromStr;
use std::{cmp, env, process};
Expand All @@ -13,6 +13,7 @@ pub struct Options {
pub f: f64,
pub print_once: bool,
pub model: model::Model,
pub auto_commmit: bool,
}

impl From<&Config> for Options {
Expand All @@ -24,6 +25,7 @@ impl From<&Config> for Options {
f: config.default_frequency_penalty,
print_once: config.disable_print_as_stream,
model: config.model,
auto_commmit: false,
}
}
}
Expand Down Expand Up @@ -102,6 +104,11 @@ impl Options {
};
}
}
"--auto-commit" => {
opts.auto_commmit = true;
opts.n = 1;
opts.print_once = true;
}
"-h" | "--help" => help(),
"-v" | "--version" => {
println!("turbocommit version {}", env!("CARGO_PKG_VERSION").purple());
Expand Down Expand Up @@ -164,6 +171,7 @@ fn help() {
"(https://platform.openai.com/docs/api-reference/chat/create#chat/create-frequency-penalty)"
.bright_black()
);
println!(" --auto-commit Automatically generate and commit a single message\n");
println!("Anything else will be concatenated into an extra message given to the AI\n");
println!("You can change the defaults for these options and the system message prompt in the config file, that is created the first time running the program\n{}",
home::home_dir().unwrap_or_else(|| "".into()).join(".turbocommit.yaml").display());
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl Default for Config {
fn default() -> Self {
Self {
model: model::Model::Gpt4omini,
default_temperature: 0.5,
default_temperature: 1.05,
default_frequency_penalty: 0.0,
default_number_of_choices: 3,
disable_print_as_stream: false,
Expand Down
8 changes: 6 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ async fn main() -> anyhow::Result<()> {

actor.used_tokens = system_len + extra_len + diff_tokens;

let result = actor.start().await;
if options.auto_commmit {
let _ = actor.auto_commit().await?;
} else {
let _ = actor.start().await;
}

util::check_version().await;

Expand All @@ -66,5 +70,5 @@ async fn main() -> anyhow::Result<()> {
}
}

result
Ok(())
}

0 comments on commit c9b3975

Please sign in to comment.