mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add buttons to manually jailbreak and purge chat on Poe
This commit is contained in:
@ -57,7 +57,7 @@ const poe_settings = {
|
||||
};
|
||||
|
||||
let auto_jailbroken = false;
|
||||
let got_reply = false;
|
||||
let messages_to_purge = 0;
|
||||
let is_get_status_poe = false;
|
||||
let is_poe_button_press = false;
|
||||
|
||||
@ -105,40 +105,82 @@ export function appendPoeAnchors(type, prompt) {
|
||||
return prompt;
|
||||
}
|
||||
|
||||
async function onPurgeChatClick() {
|
||||
toastr.info('Purging the conversation. Please wait...');
|
||||
await purgeConversation();
|
||||
toastr.success('Conversation purged! Jailbreak the bot to continue.');
|
||||
auto_jailbroken = false;
|
||||
messages_to_purge = 0;
|
||||
}
|
||||
|
||||
async function onSendJailbreakClick() {
|
||||
auto_jailbroken = false;
|
||||
toastr.info('Sending jailbreak message. Please wait...');
|
||||
await autoJailbreak();
|
||||
|
||||
if (auto_jailbroken) {
|
||||
toastr.success('Jailbreak successful!');
|
||||
} else {
|
||||
toastr.error('Jailbreak unsuccessful!');
|
||||
}
|
||||
}
|
||||
|
||||
async function autoJailbreak() {
|
||||
for (let retryNumber = 0; retryNumber < MAX_RETRIES_FOR_ACTIVATION; retryNumber++) {
|
||||
const reply = await sendMessage(substituteParams(poe_settings.jailbreak_message), false);
|
||||
|
||||
if (reply.toLowerCase().includes(poe_settings.jailbreak_response.toLowerCase())) {
|
||||
auto_jailbroken = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function generatePoe(type, finalPrompt, signal) {
|
||||
if (poe_settings.auto_purge) {
|
||||
let count_to_delete = -1;
|
||||
console.debug('Auto purge is enabled');
|
||||
let count_to_delete = 0;
|
||||
|
||||
if (auto_jailbroken && got_reply) {
|
||||
count_to_delete = 2;
|
||||
if (auto_jailbroken) {
|
||||
console.debug(`Purging ${messages_to_purge} messages`);
|
||||
count_to_delete = messages_to_purge;
|
||||
}
|
||||
else {
|
||||
console.debug('Purging all messages');
|
||||
count_to_delete = -1;
|
||||
}
|
||||
|
||||
await purgeConversation(count_to_delete);
|
||||
}
|
||||
|
||||
if (poe_settings.auto_jailbreak && !auto_jailbroken) {
|
||||
for (let retryNumber = 0; retryNumber < MAX_RETRIES_FOR_ACTIVATION; retryNumber++) {
|
||||
const reply = await sendMessage(substituteParams(poe_settings.jailbreak_message), false);
|
||||
|
||||
if (reply.toLowerCase().includes(poe_settings.jailbreak_response.toLowerCase())) {
|
||||
auto_jailbroken = true;
|
||||
break;
|
||||
}
|
||||
if (!auto_jailbroken) {
|
||||
if (poe_settings.auto_jailbreak) {
|
||||
console.debug('Attempting auto-jailbreak');
|
||||
await autoJailbreak();
|
||||
} else {
|
||||
console.debug('Auto jailbreak is disabled');
|
||||
}
|
||||
}
|
||||
else {
|
||||
auto_jailbroken = false;
|
||||
}
|
||||
|
||||
if (poe_settings.auto_jailbreak && !auto_jailbroken) {
|
||||
console.log('Could not jailbreak the bot');
|
||||
}
|
||||
|
||||
const isQuiet = type === 'quiet';
|
||||
const reply = max_context > POE_TOKEN_LENGTH
|
||||
? await sendChunkedMessage(finalPrompt, !isQuiet, signal)
|
||||
: await sendMessage(finalPrompt, !isQuiet, signal);
|
||||
got_reply = true;
|
||||
let reply = '';
|
||||
|
||||
if (max_context > POE_TOKEN_LENGTH) {
|
||||
console.debug('Prompt is too long, sending in chunks');
|
||||
const result = await sendChunkedMessage(finalPrompt, !isQuiet, signal)
|
||||
reply = result.reply;
|
||||
messages_to_purge = result.chunks + 1; // +1 for the reply
|
||||
}
|
||||
else {
|
||||
console.debug('Sending prompt in one message');
|
||||
reply = await sendMessage(finalPrompt, !isQuiet, signal);
|
||||
messages_to_purge = 2; // prompt and the reply
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
@ -165,10 +207,17 @@ async function sendChunkedMessage(finalPrompt, withStreaming, signal) {
|
||||
}
|
||||
}
|
||||
|
||||
return reply;
|
||||
return { reply: reply, chunks: promptChunks.length };
|
||||
}
|
||||
|
||||
// If count is -1, purge all messages
|
||||
// If count is 0, do nothing
|
||||
// If count is > 0, purge that many messages
|
||||
async function purgeConversation(count = -1) {
|
||||
if (count == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const body = JSON.stringify({
|
||||
bot: poe_settings.bot,
|
||||
count,
|
||||
@ -302,7 +351,7 @@ async function checkStatusPoe() {
|
||||
function setPoeOnlineStatus(value) {
|
||||
is_get_status_poe = value;
|
||||
auto_jailbroken = false;
|
||||
got_reply = false;
|
||||
messages_to_purge = 0;
|
||||
}
|
||||
|
||||
function onResponseInput() {
|
||||
@ -384,4 +433,6 @@ $('document').ready(function () {
|
||||
$('#poe_nudge_text_restore').on('click', onCharacterNudgeMessageRestoreClick);
|
||||
$('#poe_activation_response_restore').on('click', onResponseRestoreClick);
|
||||
$('#poe_activation_message_restore').on('click', onMessageRestoreClick);
|
||||
$('#poe_send_jailbreak').on('click', onSendJailbreakClick);
|
||||
$('#poe_purge_chat').on('click', onPurgeChatClick);
|
||||
});
|
||||
|
Reference in New Issue
Block a user