Skip to content

Commit 28271ed

Browse files
committed
Truncate prompt descriptions in generated commit messages to a maximum character limit
1 parent fe14fc0 commit 28271ed

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

apps/editor/src/commands/generate-commit-message-command/generate-commit-message-command.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ import { t } from '@/i18n'
1313
import axios from 'axios'
1414
import { PromptsForCommitMessagesUtils } from '../../utils/prompts-for-commit-messages-utils'
1515
import { simplify_prompt_symbols } from '@shared/utils/simplify-prompt-symbols'
16+
import { MAX_PROMPT_CHARS_IN_COMMIT_MESSAGE } from '@/constants/values'
17+
18+
const truncate_prompt = (text: string): string => {
19+
if (text.length <= MAX_PROMPT_CHARS_IN_COMMIT_MESSAGE) return text
20+
return text.substring(0, MAX_PROMPT_CHARS_IN_COMMIT_MESSAGE) + '...'
21+
}
1622

1723
export const generate_commit_message_command = (
1824
context: vscode.ExtensionContext
@@ -240,7 +246,8 @@ export const generate_commit_message_command = (
240246
? '\n\n' +
241247
selected_prompts
242248
.map(
243-
(p) => `- ${simplify_prompt_symbols({ prompt: p.prompt })}`
249+
(p) =>
250+
`- ${truncate_prompt(simplify_prompt_symbols({ prompt: p.prompt }))}`
244251
)
245252
.join('\n')
246253
: ''
@@ -262,7 +269,8 @@ export const generate_commit_message_command = (
262269
? '\n\n' +
263270
relevant_prompts
264271
.map(
265-
(p) => `- ${simplify_prompt_symbols({ prompt: p.prompt })}`
272+
(p) =>
273+
`- ${truncate_prompt(simplify_prompt_symbols({ prompt: p.prompt }))}`
266274
)
267275
.join('\n')
268276
: ''
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export const CHECKPOINT_DEFAULT_LIFESPAN = 24
22
export const DEFAULT_CONTEXT_SIZE_WARNING_THRESHOLD = 60000
33
export const MAX_FILE_TOKENS_FOR_COMMIT_MESSAGE = 20000
4+
export const MAX_PROMPT_CHARS_IN_COMMIT_MESSAGE = 1000

0 commit comments

Comments
 (0)