Wait for generation unlock before running continue or trigger

This commit is contained in:
Cohee 2023-12-02 20:12:36 +02:00
parent a06f1e8ad6
commit a28c23d295
2 changed files with 20 additions and 4 deletions

View File

@ -4335,6 +4335,10 @@ function extractMessageFromData(data) {
}
function cleanUpMessage(getMessage, isImpersonate, isContinue, displayIncompleteSentences = false) {
if (!getMessage) {
return '';
}
// Add the prompt bias before anything else
if (
power_user.user_prompt_bias &&

View File

@ -40,7 +40,7 @@ import { addEphemeralStoppingString, chat_styles, flushEphemeralStoppingStrings,
import { autoSelectPersona } from "./personas.js";
import { getContext, saveMetadataDebounced } from "./extensions.js";
import { hideChatMessage, unhideChatMessage } from "./chats.js";
import { delay, isFalseBoolean, isTrueBoolean, stringToRange, trimToEndSentence, trimToStartSentence } from "./utils.js";
import { delay, isFalseBoolean, isTrueBoolean, stringToRange, trimToEndSentence, trimToStartSentence, waitUntilCondition } from "./utils.js";
import { registerVariableCommands, resolveVariable } from "./variables.js";
import { decodeTextTokens, getFriendlyTokenizerName, getTextTokens, getTokenCount } from "./tokenizers.js";
export {
@ -971,8 +971,11 @@ async function addGroupMemberCallback(_, arg) {
}
async function triggerGenerationCallback(_, arg) {
if (is_send_press || is_group_generating) {
toastr.warning("Cannot run trigger command while the reply is being generated.");
try {
await waitUntilCondition(() => !is_send_press && !is_group_generating, 10000, 100);
} catch {
console.warn('Timeout waiting for generation unlock');
toastr.warning("Cannot run /trigger command while the reply is being generated.");
return '';
}
@ -1083,10 +1086,19 @@ async function openChat(id) {
await reloadCurrentChat();
}
function continueChatCallback() {
async function continueChatCallback() {
try {
await waitUntilCondition(() => !is_send_press && !is_group_generating, 10000, 100);
} catch {
console.warn('Timeout waiting for generation unlock');
toastr.warning("Cannot run /continue command while the reply is being generated.");
return '';
}
// Prevent infinite recursion
$('#send_textarea').val('').trigger('input');
$('#option_continue').trigger('click', { fromSlashCommand: true });
return '';
}
export async function generateSystemMessage(_, prompt) {