Skip to content

Commit

Permalink
feat: add contents of the message box to the prompt to customize gene…
Browse files Browse the repository at this point in the history
…rated content
  • Loading branch information
rickythefox committed Nov 14, 2024
1 parent a469c2c commit 9e15fc7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions src/generate-commit-msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { ProgressHandler } from './utils';
* @param {string} diff - The diff string representing changes to be committed.
* @returns {Promise<Array<{ role: string, content: string }>>} - 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({
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 6 additions & 4 deletions src/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(ConfigKeys.SYSTEM_PROMPT) ||
Expand Down Expand Up @@ -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
Expand All @@ -100,17 +101,18 @@ 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.
`
});

/**
* Retrieves the main commit prompt.
*
* @returns {Promise<Array<Object>>} - A promise that resolves to an array of prompts.
*/
export const getMainCommitPrompt = async () => {
export const getMainCommitPrompt = async (extras: string) => {
const language = ConfigurationManager.getInstance().getConfig<string>(
ConfigKeys.AI_COMMIT_LANGUAGE
);
return [INIT_MAIN_PROMPT(language)];
return [INIT_MAIN_PROMPT(language, extras)];
};

0 comments on commit 9e15fc7

Please sign in to comment.