Merge pull request #2700 from SillyTavern/fix-mag Cull the usage of MAG in streaming

2294fe12e71aaea3c2378d2954537ea57f294f9e

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

Signed
1 files changed, +13 -11Showing whitespace changes
public/script.js+13 -11
@@ -2844,7 +2844,14 @@ function hideStopButton() {
28442844}
28452845
28462846class StreamingProcessor {
2847- constructor(type, force_name2, timeStarted, messageAlreadyGenerated) {
2847+ /**
2848+ * Creates a new streaming processor.
2849+ * @param {string} type Generation type
2850+ * @param {boolean} forceName2 If true, force the use of name2
2851+ * @param {Date} timeStarted Date when generation was started
2852+ * @param {string} continueMessage Previous message if the type is 'continue'
2853+ */
2854+ constructor(type, forceName2, timeStarted, continueMessage) {
28482855 this.result = '';
28492856 this.messageId = -1;
28502857 this.messageDom = null;
@@ -2854,14 +2861,14 @@ class StreamingProcessor {
28542861 /** @type {HTMLTextAreaElement} */
28552862 this.sendTextarea = document.querySelector('#send_textarea');
28562863 this.type = type;
28572864 this.force_name2 = force_name2forceName2;
28582865 this.isStopped = false;
28592866 this.isFinished = false;
28602867 this.generator = this.nullStreamingGeneration;
28612868 this.abortController = new AbortController();
28622869 this.firstMessageText = '...';
28632870 this.timeStarted = timeStarted;
2864- this.messageAlreadyGenerated = messageAlreadyGenerated;
2871+ this.continueMessage = type === 'continue' ? continueMessage : '';
28652872 this.swipes = [];
28662873 /** @type {import('./scripts/logprobs.js').TokenLogprobs[]} */
28672874 this.messageLogprobs = [];
@@ -3014,8 +3021,7 @@ class StreamingProcessor {
30143021 await eventSource.emit(event_types.IMPERSONATE_READY, text);
30153022 }
30163023
3017- const continueMsg = this.type === 'continue' ? this.messageAlreadyGenerated : undefined;
3024+ saveLogprobsForActiveMessage(this.messageLogprobs.filter(Boolean), this.continueMessage);
3018- saveLogprobsForActiveMessage(this.messageLogprobs.filter(Boolean), continueMsg);
30193025 await saveChatConditional();
30203026 unblockGeneration();
30213027 generatedPromptCache = '';
@@ -3111,7 +3117,7 @@ class StreamingProcessor {
31113117 if (logprobs) {
31123118 this.messageLogprobs.push(...(Array.isArray(logprobs) ? logprobs : [logprobs]));
31133119 }
31143120 await sw.tick(() => this.onProgressStreaming(this.messageId, this.messageAlreadyGeneratedcontinueMessage + text));
31153121 }
31163122 const seconds = (timestamps[timestamps.length - 1] - timestamps[0]) / 1000;
31173123 console.warn(`Stream stats: ${timestamps.length} tokens, ${seconds.toFixed(2)} seconds, rate: ${Number(timestamps.length / seconds).toFixed(2)} TPS`);
@@ -3304,8 +3310,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
33043310 const isInstruct = power_user.instruct.enabled && main_api !== 'openai';
33053311 const isImpersonate = type == 'impersonate';
33063312
3307- let message_already_generated = isImpersonate ? `${name1}: ` : `${name2}: `;
3308-
33093313 if (!(dryRun || type == 'regenerate' || type == 'swipe' || type == 'quiet')) {
33103314 const interruptedByCommand = await processCommands(String($('#send_textarea').val()));
33113315
@@ -3744,7 +3748,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
37443748 let oaiMessageExamples = [];
37453749
37463750 if (main_api === 'openai') {
3747- message_already_generated = '';
37483751 oaiMessages = setOpenAIMessages(coreChat);
37493752 oaiMessageExamples = setOpenAIMessageExamples(mesExamplesArray);
37503753 }
@@ -3887,7 +3890,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
38873890 cyclePrompt += oai_settings.continue_postfix;
38883891 continue_mag += oai_settings.continue_postfix;
38893892 }
3890- message_already_generated = continue_mag;
38913893 }
38923894
38933895 const originalType = type;
@@ -4314,7 +4316,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
43144316 console.debug(`pushed prompt bits to itemizedPrompts array. Length is now: ${itemizedPrompts.length}`);
43154317
43164318 if (isStreamingEnabled() && type !== 'quiet') {
43174319 streamingProcessor = new StreamingProcessor(type, force_name2, generation_started, message_already_generatedcontinue_mag);
43184320 if (isContinue) {
43194321 // Save reply does add cycle text to the prompt, so it's not needed here
43204322 streamingProcessor.firstMessageText = '';