Fix /trigger and /continue auto-execution
This commit is contained in:
parent
64a3564892
commit
6e09e45651
|
@ -2505,7 +2505,7 @@ class StreamingProcessor {
|
||||||
$('#send_textarea').val('').trigger('input');
|
$('#send_textarea').val('').trigger('input');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
await saveReply(this.type, text);
|
await saveReply(this.type, text, true);
|
||||||
messageId = count_view_mes - 1;
|
messageId = count_view_mes - 1;
|
||||||
this.showMessageButtons(messageId);
|
this.showMessageButtons(messageId);
|
||||||
}
|
}
|
||||||
|
@ -3748,10 +3748,10 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
||||||
else {
|
else {
|
||||||
// Without streaming we'll be having a full message on continuation. Treat it as a last chunk.
|
// Without streaming we'll be having a full message on continuation. Treat it as a last chunk.
|
||||||
if (originalType !== 'continue') {
|
if (originalType !== 'continue') {
|
||||||
({ type, getMessage } = await saveReply(type, getMessage, true, title));
|
({ type, getMessage } = await saveReply(type, getMessage, false, title));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
({ type, getMessage } = await saveReply('appendFinal', getMessage, true, title));
|
({ type, getMessage } = await saveReply('appendFinal', getMessage, false, title));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
activateSendButtons();
|
activateSendButtons();
|
||||||
|
@ -4468,7 +4468,7 @@ function cleanUpMessage(getMessage, isImpersonate, isContinue, displayIncomplete
|
||||||
return getMessage;
|
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 ||
|
if (type != 'append' && type != 'continue' && type != 'appendFinal' && chat.length && (chat[chat.length - 1]['swipe_id'] === undefined ||
|
||||||
chat[chat.length - 1]['is_user'])) {
|
chat[chat.length - 1]['is_user'])) {
|
||||||
type = 'normal';
|
type = 'normal';
|
||||||
|
@ -4572,9 +4572,10 @@ async function saveReply(type, getMessage, _, title) {
|
||||||
|
|
||||||
saveImageToMessage(img, chat[chat.length - 1]);
|
saveImageToMessage(img, chat[chat.length - 1]);
|
||||||
const chat_id = (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]);
|
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];
|
const item = chat[chat.length - 1];
|
||||||
|
|
|
@ -272,7 +272,7 @@ async function performQuickReply(prompt, index) {
|
||||||
// the prompt starts with '/' - execute slash commands natively
|
// the prompt starts with '/' - execute slash commands natively
|
||||||
if (prompt.startsWith('/')) {
|
if (prompt.startsWith('/')) {
|
||||||
const result = await executeSlashCommands(newText);
|
const result = await executeSlashCommands(newText);
|
||||||
return result?.pipe;
|
return typeof result === 'object' ? result?.pipe : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
newText = substituteParams(newText);
|
newText = substituteParams(newText);
|
||||||
|
|
|
@ -971,28 +971,31 @@ async function addGroupMemberCallback(_, arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function triggerGenerationCallback(_, arg) {
|
async function triggerGenerationCallback(_, arg) {
|
||||||
try {
|
setTimeout(async () => {
|
||||||
await waitUntilCondition(() => !is_send_press && !is_group_generating, 10000, 100);
|
try {
|
||||||
} catch {
|
await waitUntilCondition(() => !is_send_press && !is_group_generating, 10000, 100);
|
||||||
console.warn('Timeout waiting for generation unlock');
|
} catch {
|
||||||
toastr.warning('Cannot run /trigger command while the reply is being generated.');
|
console.warn('Timeout waiting for generation unlock');
|
||||||
return '';
|
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(() => 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 '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1086,18 +1089,20 @@ async function openChat(id) {
|
||||||
await reloadCurrentChat();
|
await reloadCurrentChat();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function continueChatCallback() {
|
function continueChatCallback() {
|
||||||
try {
|
setTimeout(async () => {
|
||||||
await waitUntilCondition(() => !is_send_press && !is_group_generating, 10000, 100);
|
try {
|
||||||
} catch {
|
await waitUntilCondition(() => !is_send_press && !is_group_generating, 10000, 100);
|
||||||
console.warn('Timeout waiting for generation unlock');
|
} catch {
|
||||||
toastr.warning('Cannot run /continue command while the reply is being generated.');
|
console.warn('Timeout waiting for generation unlock');
|
||||||
return '';
|
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 '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue