Fix last prompt line not counted toward token limit

9010880b64c4710768b6f16cfc98cc0b10b1247e

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +5 -5Showing whitespace changes
public/script.js+5 -5
@@ -3769,10 +3769,10 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
3769 storyString,3769 storyString,
3770 afterScenarioAnchor,3770 afterScenarioAnchor,
3771 examplesString,3771 examplesString,
3772 userAlignmentMessage,
3772 chatString,3773 chatString,
3773 quiet_prompt,3774 modifyLastPromptLine(''),
3774 cyclePrompt,3775 cyclePrompt,
3775 userAlignmentMessage,
3776 ].join('').replace(/\r/gm, '');3776 ].join('').replace(/\r/gm, '');
3777 return getTokenCountAsync(encodeString, power_user.token_padding);3777 return getTokenCountAsync(encodeString, power_user.token_padding);
3778 }3778 }
@@ -3803,8 +3803,8 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
3803 }3803 }
38043804
3805 tokenCount += await getTokenCountAsync(item.replace(/\r/gm, ''));3805 tokenCount += await getTokenCountAsync(item.replace(/\r/gm, ''));
3806 chatString = item + chatString;
3807 if (tokenCount < this_max_context) {3806 if (tokenCount < this_max_context) {
3807 chatString = chatString + item;
3808 arrMes[index] = item;3808 arrMes[index] = item;
3809 lastAddedIndex = Math.max(lastAddedIndex, index);3809 lastAddedIndex = Math.max(lastAddedIndex, index);
3810 } else {3810 } else {
@@ -3830,8 +3830,8 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
3830 }3830 }
38313831
3832 tokenCount += await getTokenCountAsync(item.replace(/\r/gm, ''));3832 tokenCount += await getTokenCountAsync(item.replace(/\r/gm, ''));
3833 chatString = item + chatString;
3834 if (tokenCount < this_max_context) {3833 if (tokenCount < this_max_context) {
3834 chatString = chatString + item;
3835 arrMes[i] = item;3835 arrMes[i] = item;
3836 lastAddedIndex = Math.max(lastAddedIndex, i);3836 lastAddedIndex = Math.max(lastAddedIndex, i);
3837 } else {3837 } else {
@@ -4036,8 +4036,8 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
4036 mesExmString,4036 mesExmString,
4037 addChatsPreamble(addChatsSeparator(jointMessages)),4037 addChatsPreamble(addChatsSeparator(jointMessages)),
4038 '\n',4038 '\n',
4039 modifyLastPromptLine(''),
4039 generatedPromptCache,4040 generatedPromptCache,
4040 quiet_prompt,
4041 ].join('').replace(/\r/gm, '');4041 ].join('').replace(/\r/gm, '');
4042 let thisPromptContextSize = await getTokenCountAsync(prompt, power_user.token_padding);4042 let thisPromptContextSize = await getTokenCountAsync(prompt, power_user.token_padding);
40434043