Remove empty message looping

d99a5eba2ab2ac8b58c12442a09aa85a7adf5b2c

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

1 files changed, +27 -56Ignore whitespace
public/script.js+27 -56
@@ -881,7 +881,6 @@ let abortController;
881881
882882//css
883883var css_send_form_display = $('<div id=send_form></div>').css('display');
884-const MAX_GENERATION_LOOPS = 5;
885884
886885var kobold_horde_model = '';
887886
@@ -2864,10 +2863,10 @@ export function isStreamingEnabled() {
28642863 const noStreamSources = [chat_completion_sources.SCALE];
28652864 return (
28662865 (main_api == 'openai' &&
28672866 oai_settings.stream_openai &&
28682867 !noStreamSources.includes(oai_settings.chat_completion_source) &&
28692868 !(oai_settings.chat_completion_source == chat_completion_sources.OPENAI && oai_settings.openai_model.startsWith('o1-')) &&
28702869 !(oai_settings.chat_completion_source == chat_completion_sources.MAKERSUITE && oai_settings.google_model.includes('bison')))
28712870 || (main_api == 'kobold' && kai_settings.streaming_kobold && kai_flags.can_use_streaming)
28722871 || (main_api == 'novel' && nai_settings.streaming_novel)
28732872 || (main_api == 'textgenerationwebui' && textgen_settings.streaming));
@@ -3342,11 +3341,11 @@ function removeLastMessage() {
33423341 * @param {GenerateOptions} options Generation options
33433342 * @param {boolean} dryRun Whether to actually generate a message or just assemble the prompt
33443343 * @returns {Promise<any>} Returns a promise that resolves when the text is done generating.
33453344 * @typedef {{automatic_trigger?: boolean, force_name2?: boolean, quiet_prompt?: string, quietToLoud?: boolean, skipWIAN?: boolean, force_chid?: number, signal?: AbortSignal, quietImage?: string, maxLoops?: number, quietName?: string }} GenerateOptions
33463345 */
33473346export async function Generate(type, { automatic_trigger, force_name2, quiet_prompt, quietToLoud, skipWIAN, force_chid, signal, quietImage, maxLoops, quietName } = {}, dryRun = false) {
33483347 console.log('Generate entered');
33493348 await eventSource.emit(event_types.GENERATION_STARTED, type, { automatic_trigger, force_name2, quiet_prompt, quietToLoud, skipWIAN, force_chid, signal, quietImage, maxLoops }, dryRun);
33503349 setGenerationProgress(0);
33513350 generation_started = new Date();
33523351
@@ -3408,7 +3407,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
34083407 if (selected_group && !is_group_generating) {
34093408 if (!dryRun) {
34103409 // Returns the promise that generateGroupWrapper returns; resolves when generation is done
34113410 return generateGroupWrapper(false, type, { quiet_prompt, force_chid, signal: abortController.signal, quietImage, maxLoops });
34123411 }
34133412
34143413 const characterIndexMap = new Map(characters.map((char, index) => [char.avatar, index]));
@@ -4440,53 +4439,30 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
44404439 const displayIncomplete = type === 'quiet' && !quietToLoud;
44414440 getMessage = cleanUpMessage(getMessage, isImpersonate, isContinue, displayIncomplete);
44424441
4443- if (getMessage.length > 0 || data.allowEmptyResponse) {
4442+ if (isImpersonate) {
4444- if (isImpersonate) {
4443+ $('#send_textarea').val(getMessage)[0].dispatchEvent(new Event('input', { bubbles: true }));
4445- $('#send_textarea').val(getMessage)[0].dispatchEvent(new Event('input', { bubbles: true }));
4444+ generatedPromptCache = '';
4446- generatedPromptCache = '';
4445+ await eventSource.emit(event_types.IMPERSONATE_READY, getMessage);
4447- await eventSource.emit(event_types.IMPERSONATE_READY, getMessage);
4446+ }
4448- }
4447+ else if (type == 'quiet') {
4449- else if (type == 'quiet') {
4448+ unblockGeneration(type);
4450- unblockGeneration(type);
4449+ return getMessage;
4451- return getMessage;
4450+ }
4451+ else {
4452+ // Without streaming we'll be having a full message on continuation. Treat it as a last chunk.
4453+ if (originalType !== 'continue') {
4454+ ({ type, getMessage } = await saveReply(type, getMessage, false, title, swipes));
44524455 }
44534456 else {
4454- // Without streaming we'll be having a full message on continuation. Treat it as a last chunk.
4457+ ({ type, getMessage } = await saveReply('appendFinal', getMessage, false, title, swipes));
4455- if (originalType !== 'continue') {
4456- ({ type, getMessage } = await saveReply(type, getMessage, false, title, swipes));
4457- }
4458- else {
4459- ({ type, getMessage } = await saveReply('appendFinal', getMessage, false, title, swipes));
4460- }
4461-
4462- // This relies on `saveReply` having been called to add the message to the chat, so it must be last.
4463- parseAndSaveLogprobs(data, continue_mag);
44644458 }
44654459
4466- if (type !== 'quiet') {
4460+ // This relies on `saveReply` having been called to add the message to the chat, so it must be last.
4467- playMessageSound();
4461+ parseAndSaveLogprobs(data, continue_mag);
44684462 }
4469- } else {
4470- // If maxLoops is not passed in (e.g. first time generating), set it to MAX_GENERATION_LOOPS
4471- maxLoops ??= MAX_GENERATION_LOOPS;
4472-
4473- if (maxLoops === 0) {
4474- if (type !== 'quiet') {
4475- throwCircuitBreakerError();
4476- }
4477- throw new Error('Generate circuit breaker interruption');
4478- }
44794463
4480- // regenerate with character speech reenforced
4464+ if (type !== 'quiet') {
4481- // to make sure we leave on swipe type while also adding the name2 appendage
4465+ playMessageSound();
4482- await delay(1000);
4483- // A message was already deleted on regeneration, so instead treat is as a normal gen
4484- if (type === 'regenerate') {
4485- type = 'normal';
4486- }
4487- // The first await is for waiting for the generate to start. The second one is waiting for it to finish
4488- const result = await await Generate(type, { automatic_trigger, force_name2: true, quiet_prompt, quietToLoud, skipWIAN, force_chid, signal, quietImage, quietName, maxLoops: maxLoops - 1 });
4489- return result;
44904466 }
44914467
44924468 if (power_user.auto_swipe) {
@@ -5259,11 +5235,6 @@ function getGenerateUrl(api) {
52595235 }
52605236}
52615237
5262-function throwCircuitBreakerError() {
5263- callPopup(`Could not extract reply in ${MAX_GENERATION_LOOPS} attempts. Try generating again`, 'text');
5264- unblockGeneration();
5265-}
5266-
52675238function extractTitleFromData(data) {
52685239 if (main_api == 'koboldhorde') {
52695240 return data.workerName;