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

Commit

Permalink
Fix tokens calculation & cleanup the file summary prompt logic (#426)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
HyunggyuJang and harjotgill authored Aug 11, 2023
1 parent 4c02adf commit 71f7e6e
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,26 +320,22 @@ ${
}

ins.filename = filename
ins.fileDiff = fileDiff

// render prompt based on inputs so far
let tokens = getTokenCount(
prompts.renderSummarizeFileDiff(ins, options.reviewSimpleChanges)
)
const summarizePrompt = prompts.renderSummarizeFileDiff(ins, options.reviewSimpleChanges)
let tokens = getTokenCount(summarizePrompt)

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

ins.fileDiff = fileDiff
tokens += fileDiff.length

// summarize content
try {
const [summarizeResp] = await lightBot.chat(
prompts.renderSummarizeFileDiff(ins, options.reviewSimpleChanges),
summarizePrompt,
{}
)

Expand Down

0 comments on commit 71f7e6e

Please sign in to comment.