Fix /trigger and /continue auto-execution

This commit is contained in:
Cohee 2023-12-02 22:34:46 +02:00
parent 64a3564892
commit 6e09e45651
3 changed files with 44 additions and 38 deletions

View File

@ -2505,7 +2505,7 @@ class StreamingProcessor {
$('#send_textarea').val('').trigger('input');
}
else {
await saveReply(this.type, text);
await saveReply(this.type, text, true);
messageId = count_view_mes - 1;
this.showMessageButtons(messageId);
}
@ -3748,10 +3748,10 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
else {
// Without streaming we'll be having a full message on continuation. Treat it as a last chunk.
if (originalType !== 'continue') {
({ type, getMessage } = await saveReply(type, getMessage, true, title));
({ type, getMessage } = await saveReply(type, getMessage, false, title));
}
else {
({ type, getMessage } = await saveReply('appendFinal', getMessage, true, title));
({ type, getMessage } = await saveReply('appendFinal', getMessage, false, title));
}
}
activateSendButtons();
@ -4468,7 +4468,7 @@ function cleanUpMessage(getMessage, isImpersonate, isContinue, displayIncomplete
return getMessage;
}
async function saveReply(type, getMessage, _, title) {
async function saveReply(type, getMessage, fromStreaming, title) {
if (type != 'append' && type != 'continue' && type != 'appendFinal' && chat.length && (chat[chat.length - 1]['swipe_id'] === undefined ||
chat[chat.length - 1]['is_user'])) {
type = 'normal';
@ -4572,9 +4572,10 @@ async function saveReply(type, getMessage, _, title) {
saveImageToMessage(img, chat[chat.length - 1]);
const chat_id = (chat.length - 1);
await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id);
!fromStreaming && await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id);
addOneMessage(chat[chat_id]);
await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, chat_id);
!fromStreaming && await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, chat_id);
}
const item = chat[chat.length - 1];

View File

@ -272,7 +272,7 @@ async function performQuickReply(prompt, index) {
// the prompt starts with '/' - execute slash commands natively
if (prompt.startsWith('/')) {
const result = await executeSlashCommands(newText);
return result?.pipe;
return typeof result === 'object' ? result?.pipe : '';
}
newText = substituteParams(newText);

View File

@ -971,28 +971,31 @@ async function addGroupMemberCallback(_, arg) {
}
async function triggerGenerationCallback(_, arg) {
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 '';
}
// Prevent generate recursion
$('#send_textarea').val('').trigger('input');
let chid = undefined;
if (selected_group && arg) {
chid = findGroupMemberId(arg);
if (chid === undefined) {
console.warn(`WARN: No group member found for argument ${arg}`);
setTimeout(async () => {
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 '';
}
}
setTimeout(() => Generate('normal', { force_chid: chid }), 100);
// Prevent generate recursion
$('#send_textarea').val('').trigger('input');
let chid = undefined;
if (selected_group && arg) {
chid = findGroupMemberId(arg);
if (chid === undefined) {
console.warn(`WARN: No group member found for argument ${arg}`);
}
}
setTimeout(() => Generate('normal', { force_chid: chid }), 100);
}, 1);
return '';
}
@ -1086,18 +1089,20 @@ async function openChat(id) {
await reloadCurrentChat();
}
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 '';
}
function continueChatCallback() {
setTimeout(async () => {
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.');
}
// Prevent infinite recursion
$('#send_textarea').val('').trigger('input');
$('#option_continue').trigger('click', { fromSlashCommand: true });
}, 1);
// Prevent infinite recursion
$('#send_textarea').val('').trigger('input');
$('#option_continue').trigger('click', { fromSlashCommand: true });
return '';
}