Remove empty message looping

d99a5eba2ab2ac8b58c12442a09aa85a7adf5b2c

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

1 files changed, +4 -33Showing whitespace changes
public/script.js+4 -33
@@ -881,7 +881,6 @@ let abortController;
881881
882//css882//css
883var css_send_form_display = $('<div id=send_form></div>').css('display');883var css_send_form_display = $('<div id=send_form></div>').css('display');
884const MAX_GENERATION_LOOPS = 5;
885884
886var kobold_horde_model = '';885var kobold_horde_model = '';
887886
@@ -3342,11 +3341,11 @@ function removeLastMessage() {
3342 * @param {GenerateOptions} options Generation options3341 * @param {GenerateOptions} options Generation options
3343 * @param {boolean} dryRun Whether to actually generate a message or just assemble the prompt3342 * @param {boolean} dryRun Whether to actually generate a message or just assemble the prompt
3344 * @returns {Promise<any>} Returns a promise that resolves when the text is done generating.3343 * @returns {Promise<any>} Returns a promise that resolves when the text is done generating.
3345 * @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 }} GenerateOptions3344 * @typedef {{automatic_trigger?: boolean, force_name2?: boolean, quiet_prompt?: string, quietToLoud?: boolean, skipWIAN?: boolean, force_chid?: number, signal?: AbortSignal, quietImage?: string, quietName?: string }} GenerateOptions
3346 */3345 */
3347export async function Generate(type, { automatic_trigger, force_name2, quiet_prompt, quietToLoud, skipWIAN, force_chid, signal, quietImage, maxLoops, quietName } = {}, dryRun = false) {3346export async function Generate(type, { automatic_trigger, force_name2, quiet_prompt, quietToLoud, skipWIAN, force_chid, signal, quietImage, quietName } = {}, dryRun = false) {
3348 console.log('Generate entered');3347 console.log('Generate entered');
3349 await eventSource.emit(event_types.GENERATION_STARTED, type, { automatic_trigger, force_name2, quiet_prompt, quietToLoud, skipWIAN, force_chid, signal, quietImage, maxLoops }, dryRun);3348 await eventSource.emit(event_types.GENERATION_STARTED, type, { automatic_trigger, force_name2, quiet_prompt, quietToLoud, skipWIAN, force_chid, signal, quietImage }, dryRun);
3350 setGenerationProgress(0);3349 setGenerationProgress(0);
3351 generation_started = new Date();3350 generation_started = new Date();
33523351
@@ -3408,7 +3407,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
3408 if (selected_group && !is_group_generating) {3407 if (selected_group && !is_group_generating) {
3409 if (!dryRun) {3408 if (!dryRun) {
3410 // Returns the promise that generateGroupWrapper returns; resolves when generation is done3409 // Returns the promise that generateGroupWrapper returns; resolves when generation is done
3411 return generateGroupWrapper(false, type, { quiet_prompt, force_chid, signal: abortController.signal, quietImage, maxLoops });3410 return generateGroupWrapper(false, type, { quiet_prompt, force_chid, signal: abortController.signal, quietImage });
3412 }3411 }
34133412
3414 const characterIndexMap = new Map(characters.map((char, index) => [char.avatar, index]));3413 const characterIndexMap = new Map(characters.map((char, index) => [char.avatar, index]));
@@ -4440,7 +4439,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
4440 const displayIncomplete = type === 'quiet' && !quietToLoud;4439 const displayIncomplete = type === 'quiet' && !quietToLoud;
4441 getMessage = cleanUpMessage(getMessage, isImpersonate, isContinue, displayIncomplete);4440 getMessage = cleanUpMessage(getMessage, isImpersonate, isContinue, displayIncomplete);
44424441
4443 if (getMessage.length > 0 || data.allowEmptyResponse) {
4444 if (isImpersonate) {4442 if (isImpersonate) {
4445 $('#send_textarea').val(getMessage)[0].dispatchEvent(new Event('input', { bubbles: true }));4443 $('#send_textarea').val(getMessage)[0].dispatchEvent(new Event('input', { bubbles: true }));
4446 generatedPromptCache = '';4444 generatedPromptCache = '';
@@ -4466,28 +4464,6 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
4466 if (type !== 'quiet') {4464 if (type !== 'quiet') {
4467 playMessageSound();4465 playMessageSound();
4468 }4466 }
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 }
4479
4480 // regenerate with character speech reenforced
4481 // to make sure we leave on swipe type while also adding the name2 appendage
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;
4490 }
44914467
4492 if (power_user.auto_swipe) {4468 if (power_user.auto_swipe) {
4493 console.debug('checking for autoswipeblacklist on non-streaming message');4469 console.debug('checking for autoswipeblacklist on non-streaming message');
@@ -5259,11 +5235,6 @@ function getGenerateUrl(api) {
5259 }5235 }
5260}5236}
52615237
5262function throwCircuitBreakerError() {
5263 callPopup(`Could not extract reply in ${MAX_GENERATION_LOOPS} attempts. Try generating again`, 'text');
5264 unblockGeneration();
5265}
5266
5267function extractTitleFromData(data) {5238function extractTitleFromData(data) {
5268 if (main_api == 'koboldhorde') {5239 if (main_api == 'koboldhorde') {
5269 return data.workerName;5240 return data.workerName;