Remove continue prompt "clean-up" function (#4422) * Remove continue prompt "clean-up" function Fixes #4415 * Simplify generatedPromptCache handling
Signed| @@ -364,7 +364,6 @@ let settingsReady = false; | |||
| 364 | let currentVersion = '0.0.0'; | 364 | let currentVersion = '0.0.0'; |
| 365 | export let displayVersion = 'SillyTavern'; | 365 | export let displayVersion = 'SillyTavern'; |
| 366 | 366 | ||
| 367 | let generatedPromptCache = ''; | ||
| 368 | let generation_started = new Date(); | 367 | let generation_started = new Date(); |
| 369 | /** @type {import('./scripts/char-data.js').v1CharData[]} */ | 368 | /** @type {import('./scripts/char-data.js').v1CharData[]} */ |
| 370 | export let characters = []; | 369 | export let characters = []; |
| @@ -1964,7 +1963,6 @@ export function addOneMessage(mes, { type = 'normal', insertAfter = null, scroll | |||
| 1964 | let avatarImg = getThumbnailUrl('persona', user_avatar); | 1963 | let avatarImg = getThumbnailUrl('persona', user_avatar); |
| 1965 | const isSystem = mes.is_system; | 1964 | const isSystem = mes.is_system; |
| 1966 | const title = mes.title; | 1965 | const title = mes.title; |
| 1967 | generatedPromptCache = ''; | ||
| 1968 | 1966 | ||
| 1969 | //for non-user mesages | 1967 | //for non-user mesages |
| 1970 | if (!mes['is_user']) { | 1968 | if (!mes['is_user']) { |
| @@ -2962,7 +2960,6 @@ class StreamingProcessor { | |||
| 2962 | saveLogprobsForActiveMessage(this.messageLogprobs.filter(Boolean), this.continueMessage); | 2960 | saveLogprobsForActiveMessage(this.messageLogprobs.filter(Boolean), this.continueMessage); |
| 2963 | await saveChatConditional(); | 2961 | await saveChatConditional(); |
| 2964 | unblockGeneration(); | 2962 | unblockGeneration(); |
| 2965 | generatedPromptCache = ''; | ||
| 2966 | 2963 | ||
| 2967 | const isAborted = this.abortController.signal.aborted; | 2964 | const isAborted = this.abortController.signal.aborted; |
| 2968 | if (!isAborted && power_user.auto_swipe && generatedTextFiltered(text)) { | 2965 | if (!isAborted && power_user.auto_swipe && generatedTextFiltered(text)) { |
| @@ -2977,7 +2974,6 @@ class StreamingProcessor { | |||
| 2977 | this.isStopped = true; | 2974 | this.isStopped = true; |
| 2978 | 2975 | ||
| 2979 | this.markUIGenStopped(); | 2976 | this.markUIGenStopped(); |
| 2980 | generatedPromptCache = ''; | ||
| 2981 | unblockGeneration(); | 2977 | unblockGeneration(); |
| 2982 | 2978 | ||
| 2983 | const noEmitTypes = ['swipe', 'impersonate', 'continue']; | 2979 | const noEmitTypes = ['swipe', 'impersonate', 'continue']; |
| @@ -4065,7 +4061,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | |||
| 4065 | is_send_press = true; | 4061 | is_send_press = true; |
| 4066 | } | 4062 | } |
| 4067 | 4063 | ||
| 4068 | generatedPromptCache += cyclePrompt; | 4064 | let generatedPromptCache = cyclePrompt || ''; |
| 4069 | if (generatedPromptCache.length == 0 || type === 'continue') { | 4065 | if (generatedPromptCache.length == 0 || type === 'continue') { |
| 4070 | console.debug('generating prompt'); | 4066 | console.debug('generating prompt'); |
| 4071 | chatString = ''; | 4067 | chatString = ''; |
| @@ -4170,26 +4166,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | |||
| 4170 | return lastMesString; | 4166 | return lastMesString; |
| 4171 | } | 4167 | } |
| 4172 | 4168 | ||
| 4173 | // Clean up the already generated prompt for seamless addition | ||
| 4174 | function cleanupPromptCache(promptCache) { | ||
| 4175 | // Remove the first occurrance of character's name | ||
| 4176 | if (promptCache.trimStart().startsWith(`${name2}:`)) { | ||
| 4177 | promptCache = promptCache.replace(`${name2}:`, '').trimStart(); | ||
| 4178 | } | ||
| 4179 | |||
| 4180 | // Remove the first occurrance of prompt bias | ||
| 4181 | if (promptCache.trimStart().startsWith(promptBias)) { | ||
| 4182 | promptCache = promptCache.replace(promptBias, ''); | ||
| 4183 | } | ||
| 4184 | |||
| 4185 | // Add a space if prompt cache doesn't start with one | ||
| 4186 | if (!/^\s/.test(promptCache) && !isInstruct) { | ||
| 4187 | promptCache = ' ' + promptCache; | ||
| 4188 | } | ||
| 4189 | |||
| 4190 | return promptCache; | ||
| 4191 | } | ||
| 4192 | |||
| 4193 | async function checkPromptSize() { | 4169 | async function checkPromptSize() { |
| 4194 | console.debug('---checking Prompt size'); | 4170 | console.debug('---checking Prompt size'); |
| 4195 | setPromptString(); | 4171 | setPromptString(); |
| @@ -4278,11 +4254,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | |||
| 4278 | } | 4254 | } |
| 4279 | } | 4255 | } |
| 4280 | 4256 | ||
| 4281 | // Prune from prompt cache if it exists | ||
| 4282 | if (generatedPromptCache.length !== 0) { | ||
| 4283 | generatedPromptCache = cleanupPromptCache(generatedPromptCache); | ||
| 4284 | } | ||
| 4285 | |||
| 4286 | // Flattens the multiple prompt objects to a string. | 4257 | // Flattens the multiple prompt objects to a string. |
| 4287 | const combine = () => { | 4258 | const combine = () => { |
| 4288 | // Right now, everything is suffixed with a newline | 4259 | // Right now, everything is suffixed with a newline |
| @@ -4423,7 +4394,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | |||
| 4423 | await eventSource.emit(event_types.GENERATE_AFTER_DATA, generate_data); | 4394 | await eventSource.emit(event_types.GENERATE_AFTER_DATA, generate_data); |
| 4424 | 4395 | ||
| 4425 | if (dryRun) { | 4396 | if (dryRun) { |
| 4426 | generatedPromptCache = ''; | ||
| 4427 | return Promise.resolve(); | 4397 | return Promise.resolve(); |
| 4428 | } | 4398 | } |
| 4429 | 4399 | ||
| @@ -4527,7 +4497,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | |||
| 4527 | ToolManager.showToolCallError(invocationResult.errors); | 4497 | ToolManager.showToolCallError(invocationResult.errors); |
| 4528 | } | 4498 | } |
| 4529 | unblockGeneration(type); | 4499 | unblockGeneration(type); |
| 4530 | generatedPromptCache = ''; | ||
| 4531 | streamingProcessor = null; | 4500 | streamingProcessor = null; |
| 4532 | return; | 4501 | return; |
| 4533 | } | 4502 | } |
| @@ -4573,7 +4542,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | |||
| 4573 | // if an error was returned in data (textgenwebui), show it and throw it | 4542 | // if an error was returned in data (textgenwebui), show it and throw it |
| 4574 | if (data.error) { | 4543 | if (data.error) { |
| 4575 | unblockGeneration(type); | 4544 | unblockGeneration(type); |
| 4576 | generatedPromptCache = ''; | ||
| 4577 | 4545 | ||
| 4578 | if (data?.response) { | 4546 | if (data?.response) { |
| 4579 | toastr.error(data.response, t`API Error`, { preventDuplicates: true }); | 4547 | toastr.error(data.response, t`API Error`, { preventDuplicates: true }); |
| @@ -4583,7 +4551,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | |||
| 4583 | 4551 | ||
| 4584 | if (jsonSchema) { | 4552 | if (jsonSchema) { |
| 4585 | unblockGeneration(type); | 4553 | unblockGeneration(type); |
| 4586 | generatedPromptCache = ''; | ||
| 4587 | return extractJsonFromData(data); | 4554 | return extractJsonFromData(data); |
| 4588 | } | 4555 | } |
| 4589 | 4556 | ||
| @@ -4626,7 +4593,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | |||
| 4626 | 4593 | ||
| 4627 | if (isImpersonate) { | 4594 | if (isImpersonate) { |
| 4628 | $('#send_textarea').val(getMessage)[0].dispatchEvent(new Event('input', { bubbles: true })); | 4595 | $('#send_textarea').val(getMessage)[0].dispatchEvent(new Event('input', { bubbles: true })); |
| 4629 | generatedPromptCache = ''; | ||
| 4630 | await eventSource.emit(event_types.IMPERSONATE_READY, getMessage); | 4596 | await eventSource.emit(event_types.IMPERSONATE_READY, getMessage); |
| 4631 | } | 4597 | } |
| 4632 | else if (type == 'quiet') { | 4598 | else if (type == 'quiet') { |
| @@ -4658,7 +4624,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | |||
| 4658 | ToolManager.showToolCallError(invocationResult.errors); | 4624 | ToolManager.showToolCallError(invocationResult.errors); |
| 4659 | } | 4625 | } |
| 4660 | unblockGeneration(type); | 4626 | unblockGeneration(type); |
| 4661 | generatedPromptCache = ''; | ||
| 4662 | return; | 4627 | return; |
| 4663 | } | 4628 | } |
| 4664 | 4629 | ||
| @@ -4702,8 +4667,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | |||
| 4702 | toastr.error(exception.error.message, t`Text generation error`, { timeOut: 10000, extendedTimeOut: 20000 }); | 4667 | toastr.error(exception.error.message, t`Text generation error`, { timeOut: 10000, extendedTimeOut: 20000 }); |
| 4703 | } | 4668 | } |
| 4704 | 4669 | ||
| 4705 | generatedPromptCache = ''; | ||
| 4706 | |||
| 4707 | unblockGeneration(type); | 4670 | unblockGeneration(type); |
| 4708 | console.log(exception); | 4671 | console.log(exception); |
| 4709 | streamingProcessor = null; | 4672 | streamingProcessor = null; |