From 550d8483cc527ff2b30534702ab631e945cbfda0 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Mon, 19 Feb 2024 01:17:04 +0100 Subject: [PATCH 1/2] Extend impersonate/continue/regenerate with possible custom prompts - Use custom prompt provided via slash command arguments (similar to /sysgen and others) - Use written text from textbox, if the popout menu actions are clicked --- public/script.js | 17 ++++++++++++----- public/scripts/slash-commands.js | 4 ++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/public/script.js b/public/script.js index b9df03842..188e0900f 100644 --- a/public/script.js +++ b/public/script.js @@ -7864,9 +7864,9 @@ async function importFromURL(items, files) { } } -async function doImpersonate() { +async function doImpersonate(_, prompt) { $('#send_textarea').val(''); - $('#option_impersonate').trigger('click', { fromSlashCommand: true }); + $('#option_impersonate').trigger('click', { fromSlashCommand: true, additionalPrompt: prompt }); } async function doDeleteChat() { @@ -8682,6 +8682,13 @@ jQuery(async function () { const fromSlashCommand = customData?.fromSlashCommand || false; var id = $(this).attr('id'); + // Check whether a custom prompt was provided via custom data (for example through a slash command), otherwise fall back and use the text from the textbox, if there is any + const additionalPrompt = (customData?.additionalPrompt && customData.additionalPrompt.trim()) || (String($('#send_textarea').val()).trim() || undefined); + const buildOrFillAdditionalArgs = (args = {}) => ({ + ...args, + ...(additionalPrompt !== undefined && { quiet_prompt: additionalPrompt, quietToLoud: true }), + }); + if (id == 'option_select_chat') { if ((selected_group && !is_group_generating) || (this_chid !== undefined && !is_send_press) || fromSlashCommand) { await displayPastChats(); @@ -8717,7 +8724,7 @@ jQuery(async function () { } else { is_send_press = true; - Generate('regenerate'); + Generate('regenerate', buildOrFillAdditionalArgs()); } } } @@ -8725,14 +8732,14 @@ jQuery(async function () { else if (id == 'option_impersonate') { if (is_send_press == false || fromSlashCommand) { is_send_press = true; - Generate('impersonate'); + Generate('impersonate', buildOrFillAdditionalArgs()); } } else if (id == 'option_continue') { if (is_send_press == false || fromSlashCommand) { is_send_press = true; - Generate('continue'); + Generate('continue', buildOrFillAdditionalArgs()); } } diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index 9a4175a1e..820b43ea6 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -1168,7 +1168,7 @@ async function openChat(id) { await reloadCurrentChat(); } -function continueChatCallback() { +function continueChatCallback(_, prompt) { setTimeout(async () => { try { await waitUntilCondition(() => !is_send_press && !is_group_generating, 10000, 100); @@ -1179,7 +1179,7 @@ function continueChatCallback() { // Prevent infinite recursion $('#send_textarea').val('').trigger('input'); - $('#option_continue').trigger('click', { fromSlashCommand: true }); + $('#option_continue').trigger('click', { fromSlashCommand: true, additionalPrompt: prompt }); }, 1); return ''; From a5ee46cb2a4c0ba3aa1fea2ff3ddfb2c21753a28 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Mon, 19 Feb 2024 22:36:32 +0100 Subject: [PATCH 2/2] Only respect slash command, ignore text field --- public/script.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/script.js b/public/script.js index 188e0900f..c38eab959 100644 --- a/public/script.js +++ b/public/script.js @@ -8682,8 +8682,8 @@ jQuery(async function () { const fromSlashCommand = customData?.fromSlashCommand || false; var id = $(this).attr('id'); - // Check whether a custom prompt was provided via custom data (for example through a slash command), otherwise fall back and use the text from the textbox, if there is any - const additionalPrompt = (customData?.additionalPrompt && customData.additionalPrompt.trim()) || (String($('#send_textarea').val()).trim() || undefined); + // Check whether a custom prompt was provided via custom data (for example through a slash command) + const additionalPrompt = customData?.additionalPrompt?.trim() || undefined; const buildOrFillAdditionalArgs = (args = {}) => ({ ...args, ...(additionalPrompt !== undefined && { quiet_prompt: additionalPrompt, quietToLoud: true }),