Skip to content

feat: Update prompt language settings for summarization #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 22, 2023
Merged

feat: Update prompt language settings for summarization #56

merged 11 commits into from
Feb 22, 2023

Conversation

zcf0508
Copy link
Contributor

@zcf0508 zcf0508 commented Feb 16, 2023

#42

Hi, thanks for building this tool!

I'm a Chinese, so I need a configuration to set the language to use when generating the summary, like Chinese.

This is my work. And I am a novice in programming with rust, so if there are any mistakes, welcome to make suggestions.

Copy link
Owner

@zurawiki zurawiki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Left some comments.

My main question is what happens when we select an unsupported language? Can we provide a clear list of supported languages?

@zcf0508 zcf0508 requested a review from zurawiki February 18, 2023 14:05
Copy link
Owner

@zurawiki zurawiki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch. Just some remaining comments and I think we are almost there

@zcf0508
Copy link
Contributor Author

zcf0508 commented Feb 20, 2023

Hi, I have two problem that I need your help.

① First, about the enum Language. I got wrong result when I use Language::from_str(value) , and the value is the input.

#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Display, EnumString, IntoStaticStr)]
#[strum(serialize_all = "kebab-case")]
pub enum Language {
   #[strum(to_string = "English")]
   En,
   #[strum(to_string = "Simplified Chinese")]
   ZhCn,
   #[strum(to_string = "Traditional Chinese")]
   ZhTw,
   #[strum(to_string = "Japanese")]
   Ja,
}

// input `value` is `en`
let lang = Language::from_str(value).unwrap(); // thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: VariantNotFound'

// input `value` is `English`
let lang = Language::from_str(value).unwrap(); // success

I think it means that from_str could not find the result, and I have no idea about this.

② Second, about the summarize. I noticed that the generation of the summarize commit and the title commit is based on the file diff summary. So if the file diff summary is in Chinese, the summarize commit and the title commit will be wrong. My Solution is that the file diff summary do not use the output language setting.

I want to know your suggestions. It will help me.

@zurawiki
Copy link
Owner

For 1. This link might help

https://stackoverflow.com/questions/69292362/enum-to-str-str-to-enum

Look at the parse function

For two, you bring up a good point. We might need to add another prompt at the end to translate the whole commit message for non English languages. What do you think?

@zcf0508
Copy link
Contributor Author

zcf0508 commented Feb 20, 2023

Maybe we can insert a translation step here.
https://github.com/zurawiki/gptcommit/blob/main/src/actions/prepare_commit_msg.rs#L160

I'm not familiar with the prompt, but I'll give it a try.

@zurawiki zurawiki linked an issue Feb 20, 2023 that may be closed by this pull request
@zurawiki
Copy link
Owner

Try making your changes in this function. Note you'll need to rebase as I did some refactoring.

let (title, completion) = try_join!(
self.commit_title(summary_points),
self.commit_summary(summary_points)
)?;

I would add the language prompt to the title and summary prompts and then add a new prompt to translate the file-level bullet points

@zcf0508
Copy link
Contributor Author

zcf0508 commented Feb 21, 2023

Sorry, I have no idea about using try_join. I create a new function commit_tanslate to translate the result message.

src/summarize.rs Outdated
Comment on lines 79 to 81
let mut message = lines.join("\n");

message = self.commit_tanslate(&message).await?;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let mut message = lines.join("\n");
message = self.commit_tanslate(&message).await?;
let message = lines.join("\n");
let message = self.commit_tanslate(&message).await?;

You don't need the mut :)

@zurawiki
Copy link
Owner

This looks great! As for the try_join! we could be smarter about how many round trips we need from OpenAi but we should be good for now

Note that the lint job is failing in CI

Run just fix and make sure all errors are resolved

@zcf0508
Copy link
Contributor Author

zcf0508 commented Feb 22, 2023

Thanks for the review. I fixed the lint error and some typos.

@zcf0508
Copy link
Contributor Author

zcf0508 commented Feb 22, 2023

Perhaps we have a new problem.

If the user has an old configuration file, do they need to delete the old one and set it up again?

@zurawiki
Copy link
Owner

The configuration files should be forward-compatible as long as we add fields and don't change default values. Do you have instructions to repro this issue?

@zcf0508
Copy link
Contributor Author

zcf0508 commented Feb 22, 2023

I have only added the translation prompt and output.lang settings. I should have been overthinking it.

@zurawiki zurawiki merged commit 1835ac4 into zurawiki:main Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

how to generate other language ?
2 participants