Browse Source

Improves AI generated commit message prompts

Removes pre-release only limit on AI generated commit messages
main
Eric Amodio 1 year ago
parent
commit
4d3117104f
2 changed files with 19 additions and 8 deletions
  1. +3
    -3
      package.json
  2. +16
    -5
      src/commands/generateCommitMessage.ts

+ 3
- 3
package.json View File

@ -3637,7 +3637,7 @@
},
"gitlens.experimental.generateCommitMessagePrompt": {
"type": "string",
"default": "The commit message must have a short description that is less than 50 characters long followed by a more detailed description on a new line.",
"default": "Commit messages must have a short description that is less than 50 chars followed by a newline and a more detailed description.\n- Write concisely using an informal tone and avoid specific names from the code",
"markdownDescription": "Specifies the prompt to use to tell OpenAI how to structure or format the generated commit message",
"scope": "window",
"order": 55
@ -9296,11 +9296,11 @@
},
{
"command": "gitlens.generateCommitMessage",
"when": "gitlens:prerelease"
"when": "gitlens:enabled"
},
{
"command": "gitlens.resetOpenAIKey",
"when": "gitlens:prerelease"
"when": "gitlens:enabled"
}
],
"editor/context": [

+ 16
- 5
src/commands/generateCommitMessage.ts View File

@ -116,14 +116,22 @@ export class GenerateCommitMessageCommand extends ActiveEditorCommand {
const currentMessage = scmRepo.inputBox.value;
const code = diff.diff.substring(0, maxCodeCharacters);
let customPrompt = configuration.get('experimental.generateCommitMessagePrompt');
if (!customPrompt.endsWith('.')) {
customPrompt += '.';
}
const data: OpenAIChatCompletionRequest = {
model: 'gpt-3.5-turbo',
messages: [
{
role: 'system',
content: `You are a highly skilled software engineer and are tasked with writing, in an informal tone, a concise but meaningful commit message summarizing the changes you made to a codebase. ${configuration.get(
'experimental.generateCommitMessagePrompt',
)} Don't repeat yourself and don't make anything up. Avoid specific names from the code. Avoid phrases like "this commit", "this change", etc.`,
content:
"You are an AI programming assistant tasked with writing a meaningful commit message by summarizing code changes.\n\n- Follow the user's instructions carefully & to the letter!\n- Don't repeat yourself or make anything up!\n- Minimize any other prose.",
},
{
role: 'user',
content: `${customPrompt}\n- Avoid phrases like "this commit", "this change", etc.`,
},
],
};
@ -131,10 +139,13 @@ export class GenerateCommitMessageCommand extends ActiveEditorCommand {
if (currentMessage) {
data.messages.push({
role: 'user',
content: `Use the following additional context to craft the commit message: ${currentMessage}`,
content: `Use "${currentMessage}" to help craft the commit message.`,
});
}
data.messages.push({ role: 'user', content: code });
data.messages.push({
role: 'user',
content: `Write a meaningful commit message for the following code changes:\n\n${code}`,
});
await window.withProgress(
{ location: ProgressLocation.Notification, title: 'Generating commit message...' },

Loading…
Cancel
Save