Bläddra i källkod

Improves AI generated commit message prompts

Removes pre-release only limit on AI generated commit messages
main
Eric Amodio 1 år sedan
förälder
incheckning
4d3117104f
2 ändrade filer med 19 tillägg och 8 borttagningar
  1. +3
    -3
      package.json
  2. +16
    -5
      src/commands/generateCommitMessage.ts

+ 3
- 3
package.json Visa fil

@ -3637,7 +3637,7 @@
}, },
"gitlens.experimental.generateCommitMessagePrompt": { "gitlens.experimental.generateCommitMessagePrompt": {
"type": "string", "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", "markdownDescription": "Specifies the prompt to use to tell OpenAI how to structure or format the generated commit message",
"scope": "window", "scope": "window",
"order": 55 "order": 55
@ -9296,11 +9296,11 @@
}, },
{ {
"command": "gitlens.generateCommitMessage", "command": "gitlens.generateCommitMessage",
"when": "gitlens:prerelease"
"when": "gitlens:enabled"
}, },
{ {
"command": "gitlens.resetOpenAIKey", "command": "gitlens.resetOpenAIKey",
"when": "gitlens:prerelease"
"when": "gitlens:enabled"
} }
], ],
"editor/context": [ "editor/context": [

+ 16
- 5
src/commands/generateCommitMessage.ts Visa fil

@ -116,14 +116,22 @@ export class GenerateCommitMessageCommand extends ActiveEditorCommand {
const currentMessage = scmRepo.inputBox.value; const currentMessage = scmRepo.inputBox.value;
const code = diff.diff.substring(0, maxCodeCharacters); const code = diff.diff.substring(0, maxCodeCharacters);
let customPrompt = configuration.get('experimental.generateCommitMessagePrompt');
if (!customPrompt.endsWith('.')) {
customPrompt += '.';
}
const data: OpenAIChatCompletionRequest = { const data: OpenAIChatCompletionRequest = {
model: 'gpt-3.5-turbo', model: 'gpt-3.5-turbo',
messages: [ messages: [
{ {
role: 'system', 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) { if (currentMessage) {
data.messages.push({ data.messages.push({
role: 'user', 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( await window.withProgress(
{ location: ProgressLocation.Notification, title: 'Generating commit message...' }, { location: ProgressLocation.Notification, title: 'Generating commit message...' },

Laddar…
Avbryt
Spara