Fix potential infinite loop

This commit is contained in:
Webifi 2023-08-15 23:48:49 -05:00
parent a08d8bcd54
commit 86f427f62f
1 changed files with 2 additions and 2 deletions

View File

@ -364,8 +364,8 @@ export class ChatRequest {
let promptSummarySize = countMessageTokens(summaryRequest, model, chat) let promptSummarySize = countMessageTokens(summaryRequest, model, chat)
// Make sure there is enough room to generate the summary, and try to make sure // Make sure there is enough room to generate the summary, and try to make sure
// the last prompt is a user prompt as that seems to work better for summaries // the last prompt is a user prompt as that seems to work better for summaries
while ((topSize + reductionPoolSize + promptSummarySize + maxSummaryTokens) >= maxTokens || while (rw.length > 2 && ((topSize + reductionPoolSize + promptSummarySize + maxSummaryTokens) >= maxTokens ||
(reductionPoolSize >= 100 && rw[rw.length - 1]?.role !== 'user')) { (reductionPoolSize >= 100 && rw[rw.length - 1]?.role !== 'user'))) {
bottom.unshift(rw.pop() as Message) bottom.unshift(rw.pop() as Message)
reductionPoolSize = countPromptTokens(rw, model, chat) reductionPoolSize = countPromptTokens(rw, model, chat)
maxSummaryTokens = getSS() maxSummaryTokens = getSS()