Add jailbreak as a system message option

This commit is contained in:
SillyLossy
2023-03-28 21:13:52 +03:00
parent b9a767ff15
commit ca889b420a
2 changed files with 29 additions and 2 deletions

View File

@ -66,6 +66,7 @@ const oai_settings = {
main_prompt: default_main_prompt,
nsfw_prompt: default_nsfw_prompt,
openai_model: 'gpt-3.5-turbo-0301',
jailbreak_system: false,
};
let openai_setting_names;
@ -220,6 +221,11 @@ async function prepareOpenAIMessages(name2, storyString, worldInfoBefore, worldI
} else {
nsfw_toggle_prompt = "Avoid writing a NSFW/Smut reply. Creatively write around it NSFW/Smut scenarios in character.";
}
if (oai_settings.jailbreak_system) {
nsfw_toggle_prompt = '';
}
// Experimental but kinda works
if (oai_settings.enhance_definitions) {
enhance_definitions_prompt = "If you have more knowledge of " + name2 + ", add to the character's lore and personality to enhance them but keep the Character Sheet's definitions absolute.";
@ -270,6 +276,13 @@ async function prepareOpenAIMessages(name2, storyString, worldInfoBefore, worldI
total_count += start_chat_count;
}
if (oai_settings.jailbreak_system) {
const jailbreakMessage = { "role": "system", "content": `[System note: ${oai_settings.nsfw_prompt}]`};
openai_msgs.push(jailbreakMessage);
total_count += await countTokens([jailbreakMessage], true);
}
// The user wants to always have all example messages in the context
if (pin_examples) {
// first we send *all* example messages
@ -495,6 +508,7 @@ function loadOpenAISettings(data, settings) {
if (settings.wrap_in_quotes !== undefined) oai_settings.wrap_in_quotes = !!settings.wrap_in_quotes;
if (settings.nsfw_first !== undefined) oai_settings.nsfw_first = !!settings.nsfw_first;
if (settings.openai_model !== undefined) oai_settings.openai_model = settings.openai_model;
if (settings.jailbreak_system !== undefined) oai_settings.jailbreak_system = !!settings.jailbreak_system;
$('#stream_toggle').prop('checked', oai_settings.stream_openai);
@ -509,6 +523,7 @@ function loadOpenAISettings(data, settings) {
$('#enhance_definitions').prop('checked', oai_settings.enhance_definitions);
$('#wrap_in_quotes').prop('checked', oai_settings.wrap_in_quotes);
$('#nsfw_first').prop('checked', oai_settings.nsfw_first);
$('#jailbreak_system').prop('checked', oai_settings.jailbreak_system);
if (settings.main_prompt !== undefined) oai_settings.main_prompt = settings.main_prompt;
if (settings.nsfw_prompt !== undefined) oai_settings.nsfw_prompt = settings.nsfw_prompt;
@ -671,4 +686,9 @@ $(document).ready(function () {
oai_settings.nsfw_prompt = $('#nsfw_prompt_textarea').val();
saveSettingsDebounced();
});
$("#jailbreak_system").change(function () {
oai_settings.jailbreak_system = !!$(this).prop("checked");
saveSettingsDebounced();
});
});