Merge pull request #1840 from Wolfsblvt/slash-commands-menu-actions-allow-custom-prompts

Extend impersonate/continue/regenerate with possible custom prompts (via slash commands and popup menu)
This commit is contained in:
Cohee 2024-02-20 02:26:41 +02:00 committed by GitHub
commit 79ba026486
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 7 deletions

View File

@ -7873,9 +7873,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() {
@ -8691,6 +8691,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)
const additionalPrompt = customData?.additionalPrompt?.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();
@ -8726,7 +8733,7 @@ jQuery(async function () {
}
else {
is_send_press = true;
Generate('regenerate');
Generate('regenerate', buildOrFillAdditionalArgs());
}
}
}
@ -8734,14 +8741,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());
}
}

View File

@ -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 '';