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:
@ -550,6 +550,18 @@
|
||||
</div>
|
||||
</div>
|
||||
<div id="range_block_poe">
|
||||
<div>
|
||||
Use "Unlocked Context" to enable chunked generation.
|
||||
It extends the context window in exchange for reply generation speed.
|
||||
</div>
|
||||
<div class="flex-container spaceEvenly">
|
||||
<div id="poe_send_jailbreak" class="menu_button widthFitContent" title="Attempts to automatically jailbreak the bot">
|
||||
Send Jailbreak
|
||||
</div>
|
||||
<div id="poe_purge_chat" class="menu_button widthFitContent" title="Purges the chat history on Poe site">
|
||||
Purge Poe Chat
|
||||
</div>
|
||||
</div>
|
||||
<div class="range-block">
|
||||
<label for="poe_streaming" class="checkbox_label widthFreeExpand">
|
||||
<input id="poe_streaming" type="checkbox" />
|
||||
|
@ -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,18 +105,27 @@ export function appendPoeAnchors(type, prompt) {
|
||||
return prompt;
|
||||
}
|
||||
|
||||
async function generatePoe(type, finalPrompt, signal) {
|
||||
if (poe_settings.auto_purge) {
|
||||
let count_to_delete = -1;
|
||||
|
||||
if (auto_jailbroken && got_reply) {
|
||||
count_to_delete = 2;
|
||||
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;
|
||||
}
|
||||
|
||||
await purgeConversation(count_to_delete);
|
||||
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!');
|
||||
}
|
||||
}
|
||||
|
||||
if (poe_settings.auto_jailbreak && !auto_jailbroken) {
|
||||
async function autoJailbreak() {
|
||||
for (let retryNumber = 0; retryNumber < MAX_RETRIES_FOR_ACTIVATION; retryNumber++) {
|
||||
const reply = await sendMessage(substituteParams(poe_settings.jailbreak_message), false);
|
||||
|
||||
@ -126,8 +135,31 @@ async function generatePoe(type, finalPrompt, signal) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function generatePoe(type, finalPrompt, signal) {
|
||||
if (poe_settings.auto_purge) {
|
||||
console.debug('Auto purge is enabled');
|
||||
let count_to_delete = 0;
|
||||
|
||||
if (auto_jailbroken) {
|
||||
console.debug(`Purging ${messages_to_purge} messages`);
|
||||
count_to_delete = messages_to_purge;
|
||||
}
|
||||
else {
|
||||
auto_jailbroken = false;
|
||||
console.debug('Purging all messages');
|
||||
count_to_delete = -1;
|
||||
}
|
||||
|
||||
await purgeConversation(count_to_delete);
|
||||
}
|
||||
|
||||
if (!auto_jailbroken) {
|
||||
if (poe_settings.auto_jailbreak) {
|
||||
console.debug('Attempting auto-jailbreak');
|
||||
await autoJailbreak();
|
||||
} else {
|
||||
console.debug('Auto jailbreak is disabled');
|
||||
}
|
||||
}
|
||||
|
||||
if (poe_settings.auto_jailbreak && !auto_jailbroken) {
|
||||
@ -135,10 +167,20 @@ async function generatePoe(type, finalPrompt, signal) {
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
|
@ -4150,6 +4150,10 @@ body.waifuMode #avatar_zoom_popup {
|
||||
height: fit-content;
|
||||
}
|
||||
|
||||
.widthFitContent {
|
||||
width: fit-content;
|
||||
}
|
||||
|
||||
.flexGap5 {
|
||||
gap: 5px;
|
||||
}
|
||||
|
@ -2193,7 +2193,12 @@ app.post('/purge_poe', jsonParser, async (request, response) => {
|
||||
|
||||
try {
|
||||
const client = await getPoeClient(token, true);
|
||||
if (count > 0) {
|
||||
await client.purge_conversation(bot, count);
|
||||
}
|
||||
else {
|
||||
await client.send_chat_break(bot);
|
||||
}
|
||||
client.disconnect_ws();
|
||||
|
||||
return response.send({ "ok": true });
|
||||
|
Reference in New Issue
Block a user