Skip to content

Commit 865f0d6

Browse files
committed
Fix token count calculation by using Math.ceil instead of Math.floor
1 parent d5c9d4d commit 865f0d6

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export const generate_commit_message_command = (
187187
const { was_empty_stage, message_prompt } = data
188188

189189
await vscode.env.clipboard.writeText(message_prompt)
190-
const token_count = Math.floor(message_prompt.length / 4)
190+
const token_count = Math.ceil(message_prompt.length / 4)
191191
vscode.window.showInformationMessage(
192192
`Commit message prompt of about ${display_token_count(
193193
token_count

‎apps/editor/src/commands/generate-commit-message-command/utils/generate-commit-message-with-api.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import axios from 'axios'
33
import { apply_reasoning_effort } from '@/utils/apply-reasoning-effort'
44
import { dictionary } from '@shared/constants/dictionary'
55
import { make_api_request } from '@/utils/make-api-request'
6+
import { display_token_count } from '@/utils/display-token-count'
67
import { Logger } from '@shared/utils/logger'
78
import { strip_wrapping_quotes } from './strip-wrapping-quotes'
89
import { CommitMessageConfig } from './get-commit-message-config'
@@ -45,7 +46,11 @@ export const generate_commit_message_with_api = async (params: {
4546
cancel_token_source.cancel('Operation cancelled by user')
4647
})
4748

48-
progress.report({ message: 'waiting for server...' })
49+
progress.report({
50+
message: `sent ${display_token_count(
51+
Math.floor(params.message.length / 4)
52+
)} tokens...`
53+
})
4954

5055
try {
5156
const response_result = await make_api_request({

0 commit comments

Comments
 (0)