Added /continue "await" arg

This commit is contained in:
Wolfsblvt 2024-07-08 18:43:55 +02:00
parent 79069b49b8
commit aad65c9273
1 changed files with 37 additions and 12 deletions

View File

@ -329,6 +329,16 @@ export function initDefaultSlashCommands() {
name: 'continue',
callback: continueChatCallback,
aliases: ['cont'],
namedArgumentList: [
new SlashCommandNamedArgument(
'await',
'Whether to await for the continued generation before continuing',
[ARGUMENT_TYPE.BOOLEAN],
false,
false,
'false',
),
],
unnamedArgumentList: [
new SlashCommandArgument(
'prompt', [ARGUMENT_TYPE.STRING], false,
@ -338,6 +348,9 @@ export function initDefaultSlashCommands() {
<div>
Continues the last message in the chat, with an optional additional prompt.
</div>
<div>
If <code>await=true</code> named argument is passed, the command will await for the continued generation before continuing.
</div>
<div>
<strong>Example:</strong>
<ul>
@ -2623,19 +2636,31 @@ async function openChat(id) {
await reloadCurrentChat();
}
function continueChatCallback(_, prompt) {
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.');
}
async function continueChatCallback(args, prompt) {
const shouldAwait = isTrueBoolean(args?.await);
// Prevent infinite recursion
$('#send_textarea').val('')[0].dispatchEvent(new Event('input', { bubbles: true }));
$('#option_continue').trigger('click', { fromSlashCommand: true, additionalPrompt: prompt });
}, 1);
const outerPromise = new Promise((resolve) => {
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('')[0].dispatchEvent(new Event('input', { bubbles: true }));
const options = prompt?.trim() ? { quiet_prompt: prompt.trim(), quietToLoud: true } : {};
await Generate('continue', options);
resolve();
}, 1);
});
if (shouldAwait) {
await outerPromise;
}
return '';
}