Skip to content
This repository was archived by the owner on Mar 6, 2024. It is now read-only.

Commit 71f7e6e

Browse files
Fix tokens calculation & cleanup the file summary prompt logic (#426)
Previously, the `tokens` calculation was incorrect. With this PR, now it is correctly calculated & reuse the instantiated prompt for readability and efficiency. <!-- This is an auto-generated comment: release notes by OSS CodeRabbit --> ### Summary by CodeRabbit ``` **Bug fix:** - Fixed the incorrect calculation of `tokens` in `src/review.ts`. - Improved code readability and efficiency by reusing instantiated prompt. - Removed diff tokens check, now only checking if token count exceeds limit. - Files exceeding token limit are now skipped and logged in `summariesFailed`. > 🎉 Code's been tweaked, bugs have been fixed, 🐛 > Efficiency improved, with no tricks. 🎩✨ > Tokens counted right, no more plight, 🧮 > Celebrate this PR, it's quite a sight! 🥳🎊 ``` <!-- end of auto-generated comment: release notes by OSS CodeRabbit --> Co-authored-by: Harjot Gill <[email protected]>
1 parent 4c02adf commit 71f7e6e

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/review.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -320,26 +320,22 @@ ${
320320
}
321321

322322
ins.filename = filename
323+
ins.fileDiff = fileDiff
323324

324325
// render prompt based on inputs so far
325-
let tokens = getTokenCount(
326-
prompts.renderSummarizeFileDiff(ins, options.reviewSimpleChanges)
327-
)
326+
const summarizePrompt = prompts.renderSummarizeFileDiff(ins, options.reviewSimpleChanges)
327+
let tokens = getTokenCount(summarizePrompt)
328328

329-
const diffTokens = getTokenCount(fileDiff)
330-
if (tokens + diffTokens > options.lightTokenLimits.requestTokens) {
329+
if (tokens > options.lightTokenLimits.requestTokens) {
331330
info(`summarize: diff tokens exceeds limit, skip ${filename}`)
332331
summariesFailed.push(`${filename} (diff tokens exceeds limit)`)
333332
return null
334333
}
335334

336-
ins.fileDiff = fileDiff
337-
tokens += fileDiff.length
338-
339335
// summarize content
340336
try {
341337
const [summarizeResp] = await lightBot.chat(
342-
prompts.renderSummarizeFileDiff(ins, options.reviewSimpleChanges),
338+
summarizePrompt,
343339
{}
344340
)
345341

0 commit comments

Comments
 (0)