Merge pull request #2494 from SillyTavern/continue-command-await-arg

Added /continue "await" arg
This commit is contained in:
Cohee 2024-07-08 20:14:08 +03:00 committed by GitHub
commit 8a154e7abf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -329,6 +329,16 @@ export function initDefaultSlashCommands() {
name: 'continue', name: 'continue',
callback: continueChatCallback, callback: continueChatCallback,
aliases: ['cont'], aliases: ['cont'],
namedArgumentList: [
new SlashCommandNamedArgument(
'await',
'Whether to await for the continued generation before proceeding',
[ARGUMENT_TYPE.BOOLEAN],
false,
false,
'false',
),
],
unnamedArgumentList: [ unnamedArgumentList: [
new SlashCommandArgument( new SlashCommandArgument(
'prompt', [ARGUMENT_TYPE.STRING], false, 'prompt', [ARGUMENT_TYPE.STRING], false,
@ -338,16 +348,19 @@ export function initDefaultSlashCommands() {
<div> <div>
Continues the last message in the chat, with an optional additional prompt. Continues the last message in the chat, with an optional additional prompt.
</div> </div>
<div>
If <code>await=true</code> named argument is passed, the command will await for the continued generation before proceeding.
</div>
<div> <div>
<strong>Example:</strong> <strong>Example:</strong>
<ul> <ul>
<li> <li>
<pre><code>/continue</code></pre> <pre><code>/continue</code></pre>
Continues the chat with no additional prompt. Continues the chat with no additional prompt and immediately proceeds to the next command.
</li> </li>
<li> <li>
<pre><code>/continue Let's explore this further...</code></pre> <pre><code>/continue await=true Let's explore this further...</code></pre>
Continues the chat with the provided prompt. Continues the chat with the provided prompt and waits for the generation to finish.
</li> </li>
</ul> </ul>
</div> </div>
@ -2623,19 +2636,35 @@ async function openChat(id) {
await reloadCurrentChat(); await reloadCurrentChat();
} }
function continueChatCallback(_, prompt) { async function continueChatCallback(args, prompt) {
setTimeout(async () => { const shouldAwait = isTrueBoolean(args?.await);
const outerPromise = new Promise(async (resolve, reject) => {
try { try {
await waitUntilCondition(() => !is_send_press && !is_group_generating, 10000, 100); await waitUntilCondition(() => !is_send_press && !is_group_generating, 10000, 100);
} catch { } catch {
console.warn('Timeout waiting for generation unlock'); console.warn('Timeout waiting for generation unlock');
toastr.warning('Cannot run /continue command while the reply is being generated.'); toastr.warning('Cannot run /continue command while the reply is being generated.');
return reject();
} }
// Prevent infinite recursion try {
$('#send_textarea').val('')[0].dispatchEvent(new Event('input', { bubbles: true })); // Prevent infinite recursion
$('#option_continue').trigger('click', { fromSlashCommand: true, additionalPrompt: prompt }); $('#send_textarea').val('')[0].dispatchEvent(new Event('input', { bubbles: true }));
}, 1);
const options = prompt?.trim() ? { quiet_prompt: prompt.trim(), quietToLoud: true } : {};
await Generate('continue', options);
resolve();
} catch (error) {
console.error('Error running /continue command:', error);
reject();
}
});
if (shouldAwait) {
await outerPromise;
}
return ''; return '';
} }