Spec v2: {{original}} macro for prompt overrides.

This commit is contained in:
Cohee
2023-06-22 23:24:22 +03:00
parent c096a55697
commit 1672824416
4 changed files with 15 additions and 6 deletions

View File

@ -2670,11 +2670,11 @@
<div class="inline-drawer-content"> <div class="inline-drawer-content">
<div> <div>
<h4>System Prompt</h4> <h4>System Prompt</h4>
<textarea id="system_prompt_textarea" name="system_prompt" placeholder="(Overrides the main prompt for Chat Completion and/or system prompt for Instruct Mode if not empty)" form="form_create" class="text_pole" autocomplete="off" rows="3" maxlength="20000"></textarea> <textarea id="system_prompt_textarea" name="system_prompt" placeholder="(Overrides the main prompt for Chat Completion and/or system prompt for Instruct Mode if not empty. Use {{original}} macro to insert the original prompt.)" form="form_create" class="text_pole" autocomplete="off" rows="3" maxlength="20000"></textarea>
</div> </div>
<div> <div>
<h4>Post History Instructions</h4> <h4>Post History Instructions</h4>
<textarea id="post_history_instructions_textarea" name="post_history_instructions" placeholder="(Overrides the default jailbreak for Chat Completion if not empty)" form="form_create" class="text_pole" autocomplete="off" rows="3" maxlength="20000"></textarea> <textarea id="post_history_instructions_textarea" name="post_history_instructions" placeholder="(Overrides the default jailbreak for Chat Completion if not empty. Use {{original}} macro to insert the original jailbreak.)" form="form_create" class="text_pole" autocomplete="off" rows="3" maxlength="20000"></textarea>
</div> </div>
</div> </div>
</div> </div>

View File

@ -1377,13 +1377,20 @@ function scrollChatToBottom() {
} }
} }
function substituteParams(content, _name1, _name2) { function substituteParams(content, _name1, _name2, _original) {
_name1 = _name1 ?? name1; _name1 = _name1 ?? name1;
_name2 = _name2 ?? name2; _name2 = _name2 ?? name2;
if (!content) { if (!content) {
return '' return ''
} }
// Replace {{original}} with the original message
// Note: only replace the first instance of {{original}}
// This will hopefully prevent the abuse
if (_original) {
content = content.replace(/{{original}}/i, _original);
}
content = content.replace(/{{user}}/gi, _name1); content = content.replace(/{{user}}/gi, _name1);
content = content.replace(/{{char}}/gi, _name2); content = content.replace(/{{char}}/gi, _name2);
content = content.replace(/<USER>/gi, _name1); content = content.replace(/<USER>/gi, _name1);

View File

@ -338,7 +338,7 @@ async function prepareOpenAIMessages({ systemPrompt, name2, storyString, worldIn
let whole_prompt = getSystemPrompt(systemPrompt, nsfw_toggle_prompt, enhance_definitions_prompt, wiBefore, storyString, wiAfter, extensionPrompt, isImpersonate); let whole_prompt = getSystemPrompt(systemPrompt, nsfw_toggle_prompt, enhance_definitions_prompt, wiBefore, storyString, wiAfter, extensionPrompt, isImpersonate);
// Join by a space and replace placeholders with real user/char names // Join by a space and replace placeholders with real user/char names
storyString = substituteParams(whole_prompt.join("\n")).replace(/\r/gm, '').trim(); storyString = substituteParams(whole_prompt.join("\n"), name1, name2, oai_settings.main_prompt).replace(/\r/gm, '').trim();
let prompt_msg = { "role": "system", "content": storyString } let prompt_msg = { "role": "system", "content": storyString }
let examples_tosend = []; let examples_tosend = [];
@ -387,7 +387,7 @@ async function prepareOpenAIMessages({ systemPrompt, name2, storyString, worldIn
const jailbreak = power_user.prefer_character_jailbreak && jailbreakPrompt ? jailbreakPrompt : oai_settings.jailbreak_prompt; const jailbreak = power_user.prefer_character_jailbreak && jailbreakPrompt ? jailbreakPrompt : oai_settings.jailbreak_prompt;
if (oai_settings.jailbreak_system && jailbreak) { if (oai_settings.jailbreak_system && jailbreak) {
const jailbreakMessage = { "role": "system", "content": substituteParams(jailbreak) }; const jailbreakMessage = { "role": "system", "content": substituteParams(jailbreak, name1, name2, oai_settings.jailbreak_prompt) };
openai_msgs.push(jailbreakMessage); openai_msgs.push(jailbreakMessage);
total_count += handler_instance.count([jailbreakMessage], true, 'jailbreak'); total_count += handler_instance.count([jailbreakMessage], true, 'jailbreak');

View File

@ -12,6 +12,8 @@ import {
eventSource, eventSource,
event_types, event_types,
getCurrentChatId, getCurrentChatId,
name1,
name2,
} from "../script.js"; } from "../script.js";
import { favsToHotswap } from "./RossAscends-mods.js"; import { favsToHotswap } from "./RossAscends-mods.js";
import { import {
@ -723,7 +725,7 @@ export function formatInstructStoryString(story, systemPrompt) {
// If the character has a custom system prompt AND user has it preferred, use that instead of the default // If the character has a custom system prompt AND user has it preferred, use that instead of the default
systemPrompt = power_user.prefer_character_prompt && systemPrompt ? systemPrompt : power_user.instruct.system_prompt; systemPrompt = power_user.prefer_character_prompt && systemPrompt ? systemPrompt : power_user.instruct.system_prompt;
const sequence = power_user.instruct.system_sequence || ''; const sequence = power_user.instruct.system_sequence || '';
const prompt = substituteParams(systemPrompt) || ''; const prompt = substituteParams(systemPrompt, name1, name2, power_user.instruct.system_prompt) || '';
const separator = power_user.instruct.wrap ? '\n' : ''; const separator = power_user.instruct.wrap ? '\n' : '';
const textArray = [sequence, prompt + '\n' + story]; const textArray = [sequence, prompt + '\n' + story];
const text = textArray.filter(x => x).join(separator); const text = textArray.filter(x => x).join(separator);