Skip to content

Commit

Permalink
refactor: improve prompt generation
Browse files Browse the repository at this point in the history
- Update prompt generation to include previous completions and commit type
- Improve clarity and formatting of generated prompts
  • Loading branch information
tak-bro committed Jul 15, 2024
1 parent 825dafb commit 93f28c0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"hugging face",
"anthropic",
"claude",
"claude2",
"claude3",
"gemini",
"gemini-pro",
Expand Down
6 changes: 2 additions & 4 deletions src/utils/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import createHttpsProxyAgent from 'https-proxy-agent';

import { KnownError } from './error.js';
import { createLogResponse } from './log.js';
import { generateDefaultPrompt } from './prompt.js';
import { extraPrompt, generateDefaultPrompt } from './prompt.js';

import type { CommitType } from './config.js';
import type { ClientRequest, IncomingMessage } from 'http';
Expand Down Expand Up @@ -165,7 +165,6 @@ export const generateCommitMessage = async (
) => {
try {
const systemPrompt = generateDefaultPrompt(locale, maxLength, type, prompt);

const completion = await createChatCompletion(
url,
path,
Expand All @@ -175,7 +174,7 @@ export const generateCommitMessage = async (
messages: [
{
role: 'system',
content: systemPrompt,
content: `${systemPrompt}\n${extraPrompt(completions, type)}`,
},
{
role: 'user',
Expand All @@ -188,7 +187,6 @@ export const generateCommitMessage = async (
presence_penalty: 0,
max_tokens: maxTokens,
stream: false,
n: completions,
},
timeout,
proxy
Expand Down
17 changes: 8 additions & 9 deletions src/utils/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const commitTypeFormats: Record<CommitType, string> = {
[optional footer(s)`,
};

const exampleCommitByType: Record<CommitType, string> = {
export const exampleCommitByType: Record<CommitType, string> = {
'': '',
conventional: `<type>(<optional scope>): <description>`,
gitmoji: `:<emoji>: <description>`,
Expand Down Expand Up @@ -151,15 +151,14 @@ export const generateDefaultPrompt = (locale: string, maxLength: number, type: C
`2. Format: ${commitTypeFormats[type]}`,
`3. Type: Choose the most appropriate type from the following list: ${commitTypes[type]}`,
`4. Subject line(first line):
- Maximum ${maxLength} characters
- Written in imperative mood, present tense
- No capitalization of first letter
- No period at the end`,
- Maximum ${maxLength} characters
- Written in imperative mood, present tense
- No capitalization of first letter
- No period at the end`,
`5. Body(if needed):
- Separated from subject by a blank line
- Explain what and why, not how
- Wrap at 72 characters
- Use bullet points for multiple changes`,
- Separated from subject by a blank line
- Use BULLET POINTS for multiple changes
- Explain what and why, not how`,
`6. Footer: Optional, for indicating breaking changes or referencing issues`,
`7. Scope: Optional, can be anything specifying the place of the commit change`,
`8. Description: A short summary of the code changes`,
Expand Down

0 comments on commit 93f28c0

Please sign in to comment.