Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ path = "src/main.rs"

[dependencies]
anyhow = "1.0.69"
async-openai = "0.8.0"
async-openai = "0.9.0"
async-std = "1.12.0"
async-trait = "0.1.64"
async-trait = "0.1.65"
backoff = "0.4.0"
clap = { version = "4.1.8", features = ["derive"] }
colored = "2.0.0"
Expand Down
25 changes: 25 additions & 0 deletions prompts/conventional_commit.tera
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
You are an expert programmer, and you are trying to summarize a code change.
You went over every file that was changed in it.
For some of these files changes where too big and were omitted in the files diff summary.
Determine the best label for the commit.

Here are the labels you can choose from:

- build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
- chore: Updating libraries, copyrights or other repo setting, includes updating dependencies.
- ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, GitHub Actions)
- docs: Non-code changes, such as fixing typos or adding new documentation
- feat: a commit of the type feat introduces a new feature to the codebase
- fix: A commit of the type fix patches a bug in your codebase
- perf: A code change that improves performance
- refactor: A code change that neither fixes a bug nor adds a feature
- style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
- test: Adding missing tests or correcting existing tests


THE FILE SUMMARIES:
###
{{ summary_points }}
###

The label best describing this change:
6 changes: 3 additions & 3 deletions prompts/summarize_commit.tera
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
You are an expert programmer, and you are trying to summarize a pull request.
You went over every file that was changed in it.
For some of these files changes where too big and were omitted in the files diff summary.
For some of these files changes were too big and were omitted in the files diff summary.
Please summarize the pull request.
Write your response in bullet points, using the imperative tense following the pull request style guide.
Starting each bullet point with a `-`.
Write a high level description. Do not repeat the commit summaries or the file summaries.
Write the most important bullet points. The list should not be more than a few bullet points.

THE FILE SUMMARIES:
```
###
{{ summary_points }}
```
###

Remember to write only the most important points and do not write more than a few bullet points.
THE PULL REQUEST SUMMARY:
Expand Down
8 changes: 4 additions & 4 deletions prompts/summarize_file_diff.tera
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ The output should be easily readable. When in doubt, write less comments and not
Readability is top priority. Write only the most important comments about the diff.

EXAMPLE SUMMARY COMMENTS:
```
###
- Raise the amount of returned recordings from `10` to `100`
- Fix a typo in the github action name
- Move the `octokit` initialization to a separate file
- Add an OpenAI API for completions
- Lower numeric tolerance for test files
- Add 2 tests for the inclusive string split function
```
###
Most commits will have less comments than this examples list.
The last comment does not include the file names,
because there were more than two relevant files in the hypothetical commit.
Expand All @@ -40,9 +40,9 @@ It is given only as an example of appropriate comments.


THE GIT DIFF TO BE SUMMARIZED:
```
###
{{ file_diff }}
```
###

THE SUMMARY:

6 changes: 3 additions & 3 deletions prompts/title_commit.tera
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
You are an expert programmer, and you are trying to title a pull request.
You went over every file that was changed in it.
For some of these files changes where too big and were omitted in the files diff summary.
For some of these files changes were too big and were omitted in the files diff summary.
Please summarize the pull request into a single specific theme.
Write your response using the imperative tense following the kernel git commit style guide.
Write a high level title.
Expand All @@ -16,9 +16,9 @@ Schedule all GitHub actions on all OSs
```

THE FILE SUMMARIES:
```
###
{{ summary_points }}
```
###

Remember to write only one line, no more than 50 characters.
THE PULL REQUEST TITLE:
7 changes: 4 additions & 3 deletions prompts/translation.tera
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ You want to ensure that the translation is high level and in line with the progr
Now, translate the following message into {{ output_language }}.

GIT COMMIT MESSAGE:
```

###
{{ commit_message }}
```
###

Remember translate all given git commit message.
THE TRANSLATION:
THE TRANSLATION:
13 changes: 3 additions & 10 deletions src/llms/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,11 @@ impl OpenAIClient {
) -> Result<String> {
let request = CreateChatCompletionRequestArgs::default()
.model(&self.model)
.messages([
ChatCompletionRequestMessageArgs::default()
.role(Role::System)
.content("You are an expect, helpful programming assistant that has a deep understanding of all programming languages including Python, Rust and Javascript.")
.build()?,
ChatCompletionRequestMessageArgs::default()
.messages([ChatCompletionRequestMessageArgs::default()
.role(Role::User)
.content(prompt)
.build()?,

])
.build()?;
.build()?])
.build()?;

let response = self.client.chat().create(request).await?;

Expand Down
2 changes: 2 additions & 0 deletions src/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub fn format_prompt(prompt: &str, map: HashMap<&str, &str>) -> Result<String, E
Tera::one_off(prompt, &context, false)
}

pub static PROMPT_TO_CONVENTIONAL_COMMIT_PREFIX: &str =
include_str!("../prompts/conventional_commit.tera");
pub static PROMPT_TO_SUMMARIZE_DIFF: &str = include_str!("../prompts/summarize_file_diff.tera");
pub static PROMPT_TO_SUMMARIZE_DIFF_SUMMARIES: &str =
include_str!("../prompts/summarize_commit.tera");
Expand Down
37 changes: 31 additions & 6 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use strum_macros::{Display, IntoStaticStr};
use crate::{
git::get_hooks_path,
prompt::{
PROMPT_TO_SUMMARIZE_DIFF, PROMPT_TO_SUMMARIZE_DIFF_SUMMARIES,
PROMPT_TO_SUMMARIZE_DIFF_TITLE, PROMPT_TO_TRANSLATE,
PROMPT_TO_CONVENTIONAL_COMMIT_PREFIX, PROMPT_TO_SUMMARIZE_DIFF,
PROMPT_TO_SUMMARIZE_DIFF_SUMMARIES, PROMPT_TO_SUMMARIZE_DIFF_TITLE, PROMPT_TO_TRANSLATE,
},
};

Expand Down Expand Up @@ -89,19 +89,21 @@ impl From<OpenAISettings> for config::ValueKind {

#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub(crate) struct PromptSettings {
pub file_diff: Option<String>,
pub conventional_commit_prefix: Option<String>,
pub commit_summary: Option<String>,
pub commit_title: Option<String>,
pub file_diff: Option<String>,
pub translation: Option<String>,
}

// implement the trait `From<PromptSettings>` for `ValueKind`
impl From<PromptSettings> for config::ValueKind {
fn from(settings: PromptSettings) -> Self {
let mut properties = HashMap::new();

properties.insert(
"file_diff".to_string(),
config::Value::from(settings.file_diff),
"conventional_commit_prefix".to_string(),
config::Value::from(settings.conventional_commit_prefix),
);
properties.insert(
"commit_summary".to_string(),
Expand All @@ -111,6 +113,10 @@ impl From<PromptSettings> for config::ValueKind {
"commit_title".to_string(),
config::Value::from(settings.commit_title),
);
properties.insert(
"file_diff".to_string(),
config::Value::from(settings.file_diff),
);
properties.insert(
"translation".to_string(),
config::Value::from(settings.translation),
Expand All @@ -119,9 +125,10 @@ impl From<PromptSettings> for config::ValueKind {
}
}

#[derive(Debug, Clone, Copy, PartialEq, Display, EnumString, IntoStaticStr)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Display, EnumString, IntoStaticStr)]
#[strum(serialize_all = "kebab-case")]
pub enum Language {
#[default]
#[strum(serialize = "en")]
#[strum(to_string = "English")]
En,
Expand All @@ -138,14 +145,27 @@ pub enum Language {

#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct OutputSettings {
/// Whether to add a conventional commit tag to the commit message
pub conventional_commit: Option<bool>,
/// Output language of the commit message
pub lang: Option<String>,
/// Whether to show the summary of each file in the commit
pub show_per_file_summary: Option<bool>,
}

// implement the trait `From<OutputSettings>` for `ValueKind`
impl From<OutputSettings> for config::ValueKind {
fn from(settings: OutputSettings) -> Self {
let mut properties = HashMap::new();
properties.insert(
"conventional_commit".to_string(),
config::Value::from(settings.conventional_commit),
);
properties.insert("lang".to_string(), config::Value::from(settings.lang));
properties.insert(
"show_per_file_summary".to_string(),
config::Value::from(settings.show_per_file_summary),
);
Self::Table(properties)
}
}
Expand Down Expand Up @@ -206,6 +226,9 @@ impl Settings {
.set_default(
"prompt",
Some(PromptSettings {
conventional_commit_prefix: Some(
PROMPT_TO_CONVENTIONAL_COMMIT_PREFIX.to_string(),
),
file_diff: Some(PROMPT_TO_SUMMARIZE_DIFF.to_string()),
commit_summary: Some(PROMPT_TO_SUMMARIZE_DIFF_SUMMARIES.to_string()),
commit_title: Some(PROMPT_TO_SUMMARIZE_DIFF_TITLE.to_string()),
Expand All @@ -215,7 +238,9 @@ impl Settings {
.set_default(
"output",
Some(OutputSettings {
conventional_commit: Some(true),
lang: Some("en".to_string()),
show_per_file_summary: Some(false),
}),
)?;

Expand Down
Loading