From 9e15fc79f82a9a033c144aec9af89662018f1fc6 Mon Sep 17 00:00:00 2001 From: Richard Ginzburg Date: Thu, 14 Nov 2024 11:35:22 +0100 Subject: [PATCH 1/2] feat: add contents of the message box to the prompt to customize generated content --- package-lock.json | 4 ++-- src/generate-commit-msg.ts | 7 ++++--- src/prompts.ts | 10 ++++++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index dbb1da5..4fcf413 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ai-commit", - "version": "0.0.5", + "version": "0.0.8", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ai-commit", - "version": "0.0.5", + "version": "0.0.8", "license": "MIT", "dependencies": { "fs-extra": "^11.0.4", diff --git a/src/generate-commit-msg.ts b/src/generate-commit-msg.ts index 02f16e9..390d321 100644 --- a/src/generate-commit-msg.ts +++ b/src/generate-commit-msg.ts @@ -13,8 +13,8 @@ import { ProgressHandler } from './utils'; * @param {string} diff - The diff string representing changes to be committed. * @returns {Promise>} - A promise that resolves to an array of messages for the chat completion. */ -const generateCommitMessageChatCompletionPrompt = async (diff: string) => { - const INIT_MESSAGES_PROMPT = await getMainCommitPrompt(); +const generateCommitMessageChatCompletionPrompt = async (diff: string, extras: string) => { + const INIT_MESSAGES_PROMPT = await getMainCommitPrompt(extras); const chatContextAsCompletionRequest = [...INIT_MESSAGES_PROMPT]; chatContextAsCompletionRequest.push({ @@ -85,7 +85,8 @@ export async function generateCommitMsg(arg) { } progress.report({ message: 'Analyzing changes...' }); - const messages = await generateCommitMessageChatCompletionPrompt(diff); + const extras = scmInputBox.value; + const messages = await generateCommitMessageChatCompletionPrompt(diff, extras); progress.report({ message: 'Generating commit message...' }); try { diff --git a/src/prompts.ts b/src/prompts.ts index e720f2a..13559b8 100644 --- a/src/prompts.ts +++ b/src/prompts.ts @@ -6,7 +6,7 @@ import { ConfigKeys, ConfigurationManager } from './config'; * @param {string} language - The language to be used in the prompt. * @returns {Object} - The main prompt object containing role and content. */ -const INIT_MAIN_PROMPT = (language: string) => ({ +const INIT_MAIN_PROMPT = (language: string, extras: string) => ({ role: 'system', content: ConfigurationManager.getInstance().getConfig(ConfigKeys.SYSTEM_PROMPT) || @@ -78,6 +78,7 @@ You will act as a git commit message generator. When receiving a git diff, you w 3. NO additional text or explanations 4. NO questions or comments 5. NO formatting instructions or metadata +${extras ? `6. VERY IMPORTANT! ${extras}` : ''} ## Examples @@ -100,7 +101,8 @@ OUTPUT: - rename port variable to uppercase (PORT) to follow constant naming convention - add environment variable port support for flexible deployment -Remember: All output MUST be in ${language} language. You are to act as a pure commit message generator. Your response should contain NOTHING but the commit message itself.` +Remember: All output MUST be in ${language} language. You are to act as a pure commit message generator. Your response should contain NOTHING but the commit message itself. +` }); /** @@ -108,9 +110,9 @@ Remember: All output MUST be in ${language} language. You are to act as a pure c * * @returns {Promise>} - A promise that resolves to an array of prompts. */ -export const getMainCommitPrompt = async () => { +export const getMainCommitPrompt = async (extras: string) => { const language = ConfigurationManager.getInstance().getConfig( ConfigKeys.AI_COMMIT_LANGUAGE ); - return [INIT_MAIN_PROMPT(language)]; + return [INIT_MAIN_PROMPT(language, extras)]; }; From 829de047117e775d1f4846c8e41b8a01a3093b4e Mon Sep 17 00:00:00 2001 From: Richard Ginzburg Date: Thu, 14 Nov 2024 11:51:51 +0100 Subject: [PATCH 2/2] docs: updare readme --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a675c4b..a3d3abe 100644 --- a/README.md +++ b/README.md @@ -46,8 +46,9 @@ Use Azure/OpenAI API to review Git changes, generate conventional commit message 1. Ensure that you have installed and enabled the "AI Commit" extension. 2. In VSCode settings, locate the "ai-commit" configuration options and configure them as needed. 3. Make changes in your project and add the changes to the staging area (git add). -4. Next to the commit message input box in the "Source Control" panel, click the "AI Commit" icon button. After clicking, the extension will generate a commit message and populate it in the input box. -5. Review the generated commit message, and if you are satisfied, proceed to commit your changes. +4. Optionally supply any additional context to the AI by adding text to the commit message input box in the "Source Control" panel. +5. Next to the commit message input box in the "Source Control" panel, click the "AI Commit" icon button. After clicking, the extension will generate a commit message and populate it in the input box. +6. Review the generated commit message, and if you are satisfied, proceed to commit your changes. > **Note**\ > If the code exceeds the maximum token length, consider adding it to the staging area in batches.