Move main and jailbreak override from manager into openai script.

Makes the code clearer and easier to understand
This commit is contained in:
maver 2023-07-20 19:17:47 +02:00
parent 075c0c29f0
commit 9d6cf017d2
2 changed files with 16 additions and 17 deletions

View File

@ -472,23 +472,6 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
this.saveServiceSettings().then(() => this.render());
});
// Apply character specific overrides for prompts
eventSource.on(event_types.OAI_BEFORE_CHATCOMPLETION, (prompts) => {
const systemPromptOverride = this.activeCharacter.data?.system_prompt ?? null;
const systemPrompt = prompts.get('main') ?? null;
if (systemPromptOverride) {
systemPrompt.content = systemPromptOverride;
prompts.set(systemPrompt, prompts.index('main'));
}
const jailbreakPromptOverride = this.activeCharacter.data?.post_history_instructions ?? null;
const jailbreakPrompt = prompts.get('jailbreak') ?? null;
if (jailbreakPromptOverride && jailbreakPrompt) {
jailbreakPrompt.content = jailbreakPromptOverride;
prompts.set(jailbreakPrompt, prompts.index('jailbreak'));
}
});
// Trigger re-render when token settings are changed
document.getElementById('openai_max_context').addEventListener('change', (event) => {
this.serviceSettings.openai_max_context = event.target.value;

View File

@ -682,6 +682,22 @@ function preparePromptsForChatCompletion(Scenario, charPersonality, name2, world
else prompts.add(newPrompt);
});
// Apply character-specific main prompt
const systemPromptOverride = promptManager.activeCharacter.data?.system_prompt ?? null;
const systemPrompt = prompts.get('main') ?? null;
if (systemPromptOverride) {
systemPrompt.content = systemPromptOverride;
prompts.set(systemPrompt, prompts.index('main'));
}
// Apply character-specific jailbreak
const jailbreakPromptOverride = promptManager.activeCharacter.data?.post_history_instructions ?? null;
const jailbreakPrompt = prompts.get('jailbreak') ?? null;
if (jailbreakPromptOverride && jailbreakPrompt) {
jailbreakPrompt.content = jailbreakPromptOverride;
prompts.set(jailbreakPrompt, prompts.index('jailbreak'));
}
// Replace {{original}} placeholder for supported prompts
const originalReplacements = {
main: default_main_prompt,