Add per-character override of JB prompts.

This commit is contained in:
Cohee
2023-06-08 23:12:58 +03:00
parent b65f8cba13
commit b8084eac65
2 changed files with 17 additions and 4 deletions

View File

@ -1900,6 +1900,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
let Scenario = baseChatReplace(scenarioText.trim(), name1, name2); let Scenario = baseChatReplace(scenarioText.trim(), name1, name2);
let mesExamples = baseChatReplace(characters[this_chid].mes_example.trim(), name1, name2); let mesExamples = baseChatReplace(characters[this_chid].mes_example.trim(), name1, name2);
let systemPrompt = baseChatReplace(characters[this_chid].data?.system_prompt?.trim(), name1, name2); let systemPrompt = baseChatReplace(characters[this_chid].data?.system_prompt?.trim(), name1, name2);
let jailbreakPrompt = baseChatReplace(characters[this_chid].data?.post_history_instructions?.trim(), name1, name2);
// Parse example messages // Parse example messages
if (!mesExamples.startsWith('<START>')) { if (!mesExamples.startsWith('<START>')) {
@ -2280,7 +2281,18 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
generate_data = getNovelGenerationData(finalPromt, this_settings, this_amount_gen); generate_data = getNovelGenerationData(finalPromt, this_settings, this_amount_gen);
} }
else if (main_api == 'openai') { else if (main_api == 'openai') {
let [prompt, counts] = await prepareOpenAIMessages(systemPrompt, name2, storyString, worldInfoBefore, worldInfoAfter, afterScenarioAnchor, promptBias, type, quiet_prompt); let [prompt, counts] = await prepareOpenAIMessages({
systemPrompt: systemPrompt,
name2: name2,
storyString: storyString,
worldInfoBefore: worldInfoBefore,
worldInfoAfter: worldInfoAfter,
extensionPrompt: afterScenarioAnchor,
bias: promptBias,
type: type,
quietPrompt: quiet_prompt,
jailbreakPrompt: jailbreakPrompt,
});
generate_data = { prompt: prompt }; generate_data = { prompt: prompt };
// counts will return false if the user has not enabled the token breakdown feature // counts will return false if the user has not enabled the token breakdown feature

View File

@ -310,7 +310,7 @@ function formatWorldInfo(value) {
return stringFormat(oai_settings.wi_format, value); return stringFormat(oai_settings.wi_format, value);
} }
async function prepareOpenAIMessages(systemPrompt, name2, storyString, worldInfoBefore, worldInfoAfter, extensionPrompt, bias, type, quietPrompt) { async function prepareOpenAIMessages({ systemPrompt, name2, storyString, worldInfoBefore, worldInfoAfter, extensionPrompt, bias, type, quietPrompt, jailbreakPrompt } = {}) {
const isImpersonate = type == "impersonate"; const isImpersonate = type == "impersonate";
let this_max_context = oai_settings.openai_max_context; let this_max_context = oai_settings.openai_max_context;
let enhance_definitions_prompt = ""; let enhance_definitions_prompt = "";
@ -374,8 +374,9 @@ async function prepareOpenAIMessages(systemPrompt, name2, storyString, worldInfo
total_count += start_chat_count; total_count += start_chat_count;
} }
if (oai_settings.jailbreak_system && oai_settings.jailbreak_prompt) { const jailbreak = power_user.prefer_character_jailbreak && jailbreakPrompt ? jailbreakPrompt : oai_settings.jailbreak_prompt;
const jailbreakMessage = { "role": "system", "content": substituteParams(oai_settings.jailbreak_prompt) }; if (oai_settings.jailbreak_system && jailbreak) {
const jailbreakMessage = { "role": "system", "content": substituteParams(jailbreak) };
openai_msgs.push(jailbreakMessage); openai_msgs.push(jailbreakMessage);
total_count += handler_instance.count([jailbreakMessage], true, 'jailbreak'); total_count += handler_instance.count([jailbreakMessage], true, 'jailbreak');