mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Apply character specific prompt overrides
Jailbreak and main
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
import {DraggablePromptListModule as DraggableList} from "./DraggableList.js";
|
import {DraggablePromptListModule as DraggableList} from "./DraggableList.js";
|
||||||
import {eventSource, substituteParams} from "../script.js";
|
import {event_types, eventSource, substituteParams} from "../script.js";
|
||||||
import {IdentifierNotFoundError, TokenHandler} from "./openai.js";
|
import {IdentifierNotFoundError, TokenHandler} from "./openai.js";
|
||||||
|
|
||||||
class Prompt {
|
class Prompt {
|
||||||
@ -35,6 +35,14 @@ class PromptCollection {
|
|||||||
this.collection.push(...prompts);
|
this.collection.push(...prompts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set(prompt, position) {
|
||||||
|
if(!(prompt instanceof Prompt)) {
|
||||||
|
throw new Error('Only Prompt instances can be added to PromptCollection');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.collection[position] = prompt;
|
||||||
|
}
|
||||||
|
|
||||||
get(identifier) {
|
get(identifier) {
|
||||||
const index = this.index(identifier);
|
const index = this.index(identifier);
|
||||||
if (0 > index) return null;
|
if (0 > index) return null;
|
||||||
@ -66,6 +74,9 @@ function PromptManagerModule() {
|
|||||||
this.tokenHandler = null;
|
this.tokenHandler = null;
|
||||||
this.error = null;
|
this.error = null;
|
||||||
|
|
||||||
|
this.tryGenerate = () => { };
|
||||||
|
this.saveServiceSettings = () => { };
|
||||||
|
|
||||||
this.handleToggle = () => { };
|
this.handleToggle = () => { };
|
||||||
this.handleEdit = () => { };
|
this.handleEdit = () => { };
|
||||||
this.handleDetach = () => { };
|
this.handleDetach = () => { };
|
||||||
@ -73,8 +84,6 @@ function PromptManagerModule() {
|
|||||||
this.handleNewPrompt = () => { };
|
this.handleNewPrompt = () => { };
|
||||||
this.handleDeletePrompt = () => { };
|
this.handleDeletePrompt = () => { };
|
||||||
this.handleAppendPrompt = () => { };
|
this.handleAppendPrompt = () => { };
|
||||||
this.saveServiceSettings = () => { };
|
|
||||||
this.tryGenerate = () => { };
|
|
||||||
this.handleAdvancedSettingsToggle = () => { };
|
this.handleAdvancedSettingsToggle = () => { };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,6 +202,24 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
|
|||||||
this.saveServiceSettings().then(() => this.render());
|
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;
|
||||||
|
if (systemPromptOverride) {
|
||||||
|
const override = prompts.get('main');
|
||||||
|
override.content = systemPromptOverride;
|
||||||
|
prompts.set(override, prompts.index('main'));
|
||||||
|
}
|
||||||
|
|
||||||
|
const jailbreakPromptOverride = this.activeCharacter.data.system_prompt ?? null;
|
||||||
|
if (jailbreakPromptOverride) {
|
||||||
|
const override = prompts.get('jailbreak');
|
||||||
|
override.content = jailbreakPromptOverride;
|
||||||
|
prompts.set(override, prompts.index('jailbreak'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Trigger re-render when token settings are changed
|
||||||
document.getElementById('openai_max_context').addEventListener('change', (event) => {
|
document.getElementById('openai_max_context').addEventListener('change', (event) => {
|
||||||
if (this.activeCharacter) this.render();
|
if (this.activeCharacter) this.render();
|
||||||
});
|
});
|
||||||
|
@ -575,6 +575,7 @@ async function prepareOpenAIMessages({
|
|||||||
try {
|
try {
|
||||||
populateChatCompletion(prompts, chatCompletion, {bias, quietPrompt, type});
|
populateChatCompletion(prompts, chatCompletion, {bias, quietPrompt, type});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
toastr.error('An error occurred while counting tokens.')
|
||||||
if (error instanceof TokenBudgetExceededError) {
|
if (error instanceof TokenBudgetExceededError) {
|
||||||
chatCompletion.log('Token budget exceeded.');
|
chatCompletion.log('Token budget exceeded.');
|
||||||
promptManager.error = 'Not enough free tokens for mandatory prompts. Raise your token Limit or disable custom prompts.';
|
promptManager.error = 'Not enough free tokens for mandatory prompts. Raise your token Limit or disable custom prompts.';
|
||||||
|
@ -208,6 +208,18 @@ table.responsiveTable {
|
|||||||
padding: 0.25em;
|
padding: 0.25em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.text_warning {
|
||||||
|
color: var(--orangered);
|
||||||
|
}
|
||||||
|
|
||||||
|
.text_danger {
|
||||||
|
color: var(--fullred);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tooltip {
|
||||||
|
cursor: help;
|
||||||
|
}
|
||||||
|
|
||||||
.mes_text p {
|
.mes_text p {
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
@ -5491,3 +5503,4 @@ body.waifuMode .zoomed_avatar {
|
|||||||
line-height: 14px;
|
line-height: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user