From 4d3117104f1272812affd7c6eaa058423b8ebf35 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 14 Mar 2023 18:08:22 -0400 Subject: [PATCH] Improves AI generated commit message prompts Removes pre-release only limit on AI generated commit messages --- package.json | 6 +++--- src/commands/generateCommitMessage.ts | 21 ++++++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 4929f86..e15e7b4 100644 --- a/package.json +++ b/package.json @@ -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": [ diff --git a/src/commands/generateCommitMessage.ts b/src/commands/generateCommitMessage.ts index 73e38d7..34ad13b 100644 --- a/src/commands/generateCommitMessage.ts +++ b/src/commands/generateCommitMessage.ts @@ -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...' },