mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Fix character JB / prompt + Original
This commit is contained in:
@ -1769,7 +1769,6 @@ function scrollChatToBottom() {
|
|||||||
function substituteParams(content, _name1, _name2, _original, _group) {
|
function substituteParams(content, _name1, _name2, _original, _group) {
|
||||||
_name1 = _name1 ?? name1;
|
_name1 = _name1 ?? name1;
|
||||||
_name2 = _name2 ?? name2;
|
_name2 = _name2 ?? name2;
|
||||||
_original = _original || '';
|
|
||||||
_group = _group ?? name2;
|
_group = _group ?? name2;
|
||||||
|
|
||||||
if (!content) {
|
if (!content) {
|
||||||
@ -2126,6 +2125,8 @@ function baseChatReplace(value, name1, name2) {
|
|||||||
if (power_user.collapse_newlines) {
|
if (power_user.collapse_newlines) {
|
||||||
value = collapseNewlines(value);
|
value = collapseNewlines(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value = value.replace(/\r/g, '');
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@ -2528,8 +2529,8 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
let charPersonality = baseChatReplace(characters[this_chid].personality.trim(), name1, name2);
|
let charPersonality = baseChatReplace(characters[this_chid].personality.trim(), name1, name2);
|
||||||
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 = power_user.prefer_character_prompt ? baseChatReplace(characters[this_chid].data?.system_prompt?.trim(), name1, name2) : '';
|
||||||
let jailbreakPrompt = baseChatReplace(characters[this_chid].data?.post_history_instructions?.trim(), name1, name2);
|
let jailbreakPrompt = power_user.prefer_character_jailbreak ? 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>')) {
|
||||||
@ -2982,8 +2983,9 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
bias: promptBias,
|
bias: promptBias,
|
||||||
type: type,
|
type: type,
|
||||||
quietPrompt: quiet_prompt,
|
quietPrompt: quiet_prompt,
|
||||||
jailbreakPrompt: jailbreakPrompt,
|
|
||||||
cyclePrompt: cyclePrompt,
|
cyclePrompt: cyclePrompt,
|
||||||
|
systemPromptOverride: systemPrompt,
|
||||||
|
jailbreakPromptOverride: jailbreakPrompt,
|
||||||
}, dryRun);
|
}, dryRun);
|
||||||
generate_data = { prompt: prompt };
|
generate_data = { prompt: prompt };
|
||||||
|
|
||||||
|
@ -699,7 +699,7 @@ function populateChatCompletion(prompts, chatCompletion, { bias, quietPrompt, ty
|
|||||||
*
|
*
|
||||||
* @returns {Object} prompts - The prepared and merged system and user-defined prompts.
|
* @returns {Object} prompts - The prepared and merged system and user-defined prompts.
|
||||||
*/
|
*/
|
||||||
function preparePromptsForChatCompletion(Scenario, charPersonality, name2, worldInfoBefore, worldInfoAfter, charDescription, quietPrompt, bias, extensionPrompts) {
|
function preparePromptsForChatCompletion(Scenario, charPersonality, name2, worldInfoBefore, worldInfoAfter, charDescription, quietPrompt, bias, extensionPrompts, systemPromptOverride, jailbreakPromptOverride) {
|
||||||
const scenarioText = Scenario ? `[Circumstances and context of the dialogue: ${Scenario}]` : '';
|
const scenarioText = Scenario ? `[Circumstances and context of the dialogue: ${Scenario}]` : '';
|
||||||
const charPersonalityText = charPersonality ? `[${name2}'s personality: ${charPersonality}]` : '';
|
const charPersonalityText = charPersonality ? `[${name2}'s personality: ${charPersonality}]` : '';
|
||||||
|
|
||||||
@ -752,7 +752,6 @@ function preparePromptsForChatCompletion(Scenario, charPersonality, name2, world
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Apply character-specific main prompt
|
// Apply character-specific main prompt
|
||||||
const systemPromptOverride = promptManager.activeCharacter.data?.system_prompt ?? null;
|
|
||||||
const systemPrompt = prompts.get('main') ?? null;
|
const systemPrompt = prompts.get('main') ?? null;
|
||||||
if (systemPromptOverride && systemPrompt) {
|
if (systemPromptOverride && systemPrompt) {
|
||||||
const mainOriginalContent = systemPrompt.content;
|
const mainOriginalContent = systemPrompt.content;
|
||||||
@ -762,7 +761,6 @@ function preparePromptsForChatCompletion(Scenario, charPersonality, name2, world
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply character-specific jailbreak
|
// Apply character-specific jailbreak
|
||||||
const jailbreakPromptOverride = promptManager.activeCharacter.data?.post_history_instructions ?? null;
|
|
||||||
const jailbreakPrompt = prompts.get('jailbreak') ?? null;
|
const jailbreakPrompt = prompts.get('jailbreak') ?? null;
|
||||||
if (jailbreakPromptOverride && jailbreakPrompt) {
|
if (jailbreakPromptOverride && jailbreakPrompt) {
|
||||||
const jbOriginalContent = jailbreakPrompt.content;
|
const jbOriginalContent = jailbreakPrompt.content;
|
||||||
@ -806,7 +804,9 @@ function prepareOpenAIMessages({
|
|||||||
type,
|
type,
|
||||||
quietPrompt,
|
quietPrompt,
|
||||||
extensionPrompts,
|
extensionPrompts,
|
||||||
cyclePrompt
|
cyclePrompt,
|
||||||
|
systemPromptOverride,
|
||||||
|
jailbreakPromptOverride,
|
||||||
} = {}, dryRun) {
|
} = {}, dryRun) {
|
||||||
// Without a character selected, there is no way to accurately calculate tokens
|
// Without a character selected, there is no way to accurately calculate tokens
|
||||||
if (!promptManager.activeCharacter && dryRun) return [null, false];
|
if (!promptManager.activeCharacter && dryRun) return [null, false];
|
||||||
@ -819,7 +819,7 @@ function prepareOpenAIMessages({
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Merge markers and ordered user prompts with system prompts
|
// Merge markers and ordered user prompts with system prompts
|
||||||
const prompts = preparePromptsForChatCompletion(Scenario, charPersonality, name2, worldInfoBefore, worldInfoAfter, charDescription, quietPrompt, bias, extensionPrompts);
|
const prompts = preparePromptsForChatCompletion(Scenario, charPersonality, name2, worldInfoBefore, worldInfoAfter, charDescription, quietPrompt, bias, extensionPrompts, systemPromptOverride, jailbreakPromptOverride);
|
||||||
|
|
||||||
// Fill the chat completion with as much context as the budget allows
|
// Fill the chat completion with as much context as the budget allows
|
||||||
populateChatCompletion(prompts, chatCompletion, { bias, quietPrompt, type, cyclePrompt });
|
populateChatCompletion(prompts, chatCompletion, { bias, quietPrompt, type, cyclePrompt });
|
||||||
|
Reference in New Issue
Block a user