Remove continue prompt "clean-up" function (#4422) * Remove continue prompt "clean-up" function Fixes #4415 * Simplify generatedPromptCache handling

dec25d128899b57d1e0b57c05a701d380fcd12b1

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

Signed
1 files changed, +1 -38Ignore whitespace
public/script.js+1 -38
@@ -364,7 +364,6 @@ let settingsReady = false;
364364let currentVersion = '0.0.0';
365365export let displayVersion = 'SillyTavern';
366366
367-let generatedPromptCache = '';
368367let generation_started = new Date();
369368/** @type {import('./scripts/char-data.js').v1CharData[]} */
370369export let characters = [];
@@ -1964,7 +1963,6 @@ export function addOneMessage(mes, { type = 'normal', insertAfter = null, scroll
19641963 let avatarImg = getThumbnailUrl('persona', user_avatar);
19651964 const isSystem = mes.is_system;
19661965 const title = mes.title;
1967- generatedPromptCache = '';
19681966
19691967 //for non-user mesages
19701968 if (!mes['is_user']) {
@@ -2962,7 +2960,6 @@ class StreamingProcessor {
29622960 saveLogprobsForActiveMessage(this.messageLogprobs.filter(Boolean), this.continueMessage);
29632961 await saveChatConditional();
29642962 unblockGeneration();
2965- generatedPromptCache = '';
29662963
29672964 const isAborted = this.abortController.signal.aborted;
29682965 if (!isAborted && power_user.auto_swipe && generatedTextFiltered(text)) {
@@ -2977,7 +2974,6 @@ class StreamingProcessor {
29772974 this.isStopped = true;
29782975
29792976 this.markUIGenStopped();
2980- generatedPromptCache = '';
29812977 unblockGeneration();
29822978
29832979 const noEmitTypes = ['swipe', 'impersonate', 'continue'];
@@ -4065,7 +4061,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
40654061 is_send_press = true;
40664062 }
40674063
40684064 let generatedPromptCache += cyclePrompt || '';
40694065 if (generatedPromptCache.length == 0 || type === 'continue') {
40704066 console.debug('generating prompt');
40714067 chatString = '';
@@ -4170,26 +4166,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
41704166 return lastMesString;
41714167 }
41724168
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-
41934169 async function checkPromptSize() {
41944170 console.debug('---checking Prompt size');
41954171 setPromptString();
@@ -4278,11 +4254,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
42784254 }
42794255 }
42804256
4281- // Prune from prompt cache if it exists
4282- if (generatedPromptCache.length !== 0) {
4283- generatedPromptCache = cleanupPromptCache(generatedPromptCache);
4284- }
4285-
42864257 // Flattens the multiple prompt objects to a string.
42874258 const combine = () => {
42884259 // Right now, everything is suffixed with a newline
@@ -4423,7 +4394,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
44234394 await eventSource.emit(event_types.GENERATE_AFTER_DATA, generate_data);
44244395
44254396 if (dryRun) {
4426- generatedPromptCache = '';
44274397 return Promise.resolve();
44284398 }
44294399
@@ -4527,7 +4497,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
45274497 ToolManager.showToolCallError(invocationResult.errors);
45284498 }
45294499 unblockGeneration(type);
4530- generatedPromptCache = '';
45314500 streamingProcessor = null;
45324501 return;
45334502 }
@@ -4573,7 +4542,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
45734542 // if an error was returned in data (textgenwebui), show it and throw it
45744543 if (data.error) {
45754544 unblockGeneration(type);
4576- generatedPromptCache = '';
45774545
45784546 if (data?.response) {
45794547 toastr.error(data.response, t`API Error`, { preventDuplicates: true });
@@ -4583,7 +4551,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
45834551
45844552 if (jsonSchema) {
45854553 unblockGeneration(type);
4586- generatedPromptCache = '';
45874554 return extractJsonFromData(data);
45884555 }
45894556
@@ -4626,7 +4593,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
46264593
46274594 if (isImpersonate) {
46284595 $('#send_textarea').val(getMessage)[0].dispatchEvent(new Event('input', { bubbles: true }));
4629- generatedPromptCache = '';
46304596 await eventSource.emit(event_types.IMPERSONATE_READY, getMessage);
46314597 }
46324598 else if (type == 'quiet') {
@@ -4658,7 +4624,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
46584624 ToolManager.showToolCallError(invocationResult.errors);
46594625 }
46604626 unblockGeneration(type);
4661- generatedPromptCache = '';
46624627 return;
46634628 }
46644629
@@ -4702,8 +4667,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
47024667 toastr.error(exception.error.message, t`Text generation error`, { timeOut: 10000, extendedTimeOut: 20000 });
47034668 }
47044669
4705- generatedPromptCache = '';
4706-
47074670 unblockGeneration(type);
47084671 console.log(exception);
47094672 streamingProcessor = null;