mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Indicate overridden prompts
This commit is contained in:
@ -241,6 +241,13 @@
|
|||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#completion_prompt_manager #completion_prompt_manager_list .completion_prompt_manager_prompt .completion_prompt_manager_prompt_name .fa-solid.prompt-manager-overridden {
|
||||||
|
margin-left: 5px;
|
||||||
|
color: var(--SmartThemeQuoteColor);
|
||||||
|
cursor: pointer;
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
#completion_prompt_manager_footer_append_prompt {
|
#completion_prompt_manager_footer_append_prompt {
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
}
|
}
|
||||||
|
@ -104,6 +104,7 @@ class Prompt {
|
|||||||
*/
|
*/
|
||||||
class PromptCollection {
|
class PromptCollection {
|
||||||
collection = [];
|
collection = [];
|
||||||
|
overriddenPrompts = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new PromptCollection instance.
|
* Create a new PromptCollection instance.
|
||||||
@ -178,6 +179,11 @@ class PromptCollection {
|
|||||||
has(identifier) {
|
has(identifier) {
|
||||||
return this.index(identifier) !== -1;
|
return this.index(identifier) !== -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override(prompt, position) {
|
||||||
|
this.set(prompt, position);
|
||||||
|
this.overriddenPrompts.push(prompt.identifier);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PromptManager {
|
class PromptManager {
|
||||||
@ -194,6 +200,8 @@ class PromptManager {
|
|||||||
'jailbreak',
|
'jailbreak',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
this.overriddenPrompts = [];
|
||||||
|
|
||||||
this.configuration = {
|
this.configuration = {
|
||||||
version: 1,
|
version: 1,
|
||||||
prefix: '',
|
prefix: '',
|
||||||
@ -1290,7 +1298,7 @@ class PromptManager {
|
|||||||
/**
|
/**
|
||||||
* Setter for messages property
|
* Setter for messages property
|
||||||
*
|
*
|
||||||
* @param {MessageCollection} messages
|
* @param {import('./openai.js').MessageCollection} messages
|
||||||
*/
|
*/
|
||||||
setMessages(messages) {
|
setMessages(messages) {
|
||||||
this.messages = messages;
|
this.messages = messages;
|
||||||
@ -1299,19 +1307,20 @@ class PromptManager {
|
|||||||
/**
|
/**
|
||||||
* Set and process a finished chat completion object
|
* Set and process a finished chat completion object
|
||||||
*
|
*
|
||||||
* @param {ChatCompletion} chatCompletion
|
* @param {import('./openai.js').ChatCompletion} chatCompletion
|
||||||
*/
|
*/
|
||||||
setChatCompletion(chatCompletion) {
|
setChatCompletion(chatCompletion) {
|
||||||
const messages = chatCompletion.getMessages();
|
const messages = chatCompletion.getMessages();
|
||||||
|
|
||||||
this.setMessages(messages);
|
this.setMessages(messages);
|
||||||
this.populateTokenCounts(messages);
|
this.populateTokenCounts(messages);
|
||||||
|
this.overriddenPrompts = chatCompletion.getOverriddenPrompts();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Populates the token handler
|
* Populates the token handler
|
||||||
*
|
*
|
||||||
* @param {MessageCollection} messages
|
* @param {import('./openai.js').MessageCollection} messages
|
||||||
*/
|
*/
|
||||||
populateTokenCounts(messages) {
|
populateTokenCounts(messages) {
|
||||||
this.tokenHandler.resetCounts();
|
this.tokenHandler.resetCounts();
|
||||||
@ -1525,6 +1534,7 @@ class PromptManager {
|
|||||||
const isImportantPrompt = !prompt.marker && prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE && prompt.forbid_overrides;
|
const isImportantPrompt = !prompt.marker && prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE && prompt.forbid_overrides;
|
||||||
const isUserPrompt = !prompt.marker && !prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE;
|
const isUserPrompt = !prompt.marker && !prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE;
|
||||||
const isInjectionPrompt = !prompt.marker && prompt.injection_position === INJECTION_POSITION.ABSOLUTE;
|
const isInjectionPrompt = !prompt.marker && prompt.injection_position === INJECTION_POSITION.ABSOLUTE;
|
||||||
|
const isOverriddenPrompt = Array.isArray(this.overriddenPrompts) && this.overriddenPrompts.includes(prompt.identifier);
|
||||||
const importantClass = isImportantPrompt ? `${prefix}prompt_manager_important` : '';
|
const importantClass = isImportantPrompt ? `${prefix}prompt_manager_important` : '';
|
||||||
listItemHtml += `
|
listItemHtml += `
|
||||||
<li class="${prefix}prompt_manager_prompt ${draggableClass} ${enabledClass} ${markerClass} ${importantClass}" data-pm-identifier="${prompt.identifier}">
|
<li class="${prefix}prompt_manager_prompt ${draggableClass} ${enabledClass} ${markerClass} ${importantClass}" data-pm-identifier="${prompt.identifier}">
|
||||||
@ -1536,6 +1546,7 @@ class PromptManager {
|
|||||||
${isInjectionPrompt ? '<span class="fa-fw fa-solid fa-syringe" title="In-Chat Injection"></span>' : ''}
|
${isInjectionPrompt ? '<span class="fa-fw fa-solid fa-syringe" title="In-Chat Injection"></span>' : ''}
|
||||||
${this.isPromptInspectionAllowed(prompt) ? `<a class="prompt-manager-inspect-action">${encodedName}</a>` : encodedName}
|
${this.isPromptInspectionAllowed(prompt) ? `<a class="prompt-manager-inspect-action">${encodedName}</a>` : encodedName}
|
||||||
${isInjectionPrompt ? `<small class="prompt-manager-injection-depth">@ ${prompt.injection_depth}</small>` : ''}
|
${isInjectionPrompt ? `<small class="prompt-manager-injection-depth">@ ${prompt.injection_depth}</small>` : ''}
|
||||||
|
${isOverriddenPrompt ? '<small class="fa-solid fa-address-card prompt-manager-overridden" title="Pulled from a character card"></small>' : ''}
|
||||||
</span>
|
</span>
|
||||||
<span>
|
<span>
|
||||||
<span class="prompt_manager_prompt_controls">
|
<span class="prompt_manager_prompt_controls">
|
||||||
|
@ -904,6 +904,7 @@ async function populateChatCompletion(prompts, chatCompletion, { bias, quietProm
|
|||||||
addToChatCompletion('personaDescription');
|
addToChatCompletion('personaDescription');
|
||||||
|
|
||||||
// Collection of control prompts that will always be positioned last
|
// Collection of control prompts that will always be positioned last
|
||||||
|
chatCompletion.setOverriddenPrompts(prompts.overriddenPrompts);
|
||||||
const controlPrompts = new MessageCollection('controlPrompts');
|
const controlPrompts = new MessageCollection('controlPrompts');
|
||||||
|
|
||||||
const impersonateMessage = Message.fromPrompt(prompts.get('impersonate')) ?? null;
|
const impersonateMessage = Message.fromPrompt(prompts.get('impersonate')) ?? null;
|
||||||
@ -1095,7 +1096,7 @@ function preparePromptsForChatCompletion({ Scenario, charPersonality, name2, wor
|
|||||||
const mainOriginalContent = systemPrompt.content;
|
const mainOriginalContent = systemPrompt.content;
|
||||||
systemPrompt.content = systemPromptOverride;
|
systemPrompt.content = systemPromptOverride;
|
||||||
const mainReplacement = promptManager.preparePrompt(systemPrompt, mainOriginalContent);
|
const mainReplacement = promptManager.preparePrompt(systemPrompt, mainOriginalContent);
|
||||||
prompts.set(mainReplacement, prompts.index('main'));
|
prompts.override(mainReplacement, prompts.index('main'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply character-specific jailbreak
|
// Apply character-specific jailbreak
|
||||||
@ -1104,7 +1105,7 @@ function preparePromptsForChatCompletion({ Scenario, charPersonality, name2, wor
|
|||||||
const jbOriginalContent = jailbreakPrompt.content;
|
const jbOriginalContent = jailbreakPrompt.content;
|
||||||
jailbreakPrompt.content = jailbreakPromptOverride;
|
jailbreakPrompt.content = jailbreakPromptOverride;
|
||||||
const jbReplacement = promptManager.preparePrompt(jailbreakPrompt, jbOriginalContent);
|
const jbReplacement = promptManager.preparePrompt(jailbreakPrompt, jbOriginalContent);
|
||||||
prompts.set(jbReplacement, prompts.index('jailbreak'));
|
prompts.override(jbReplacement, prompts.index('jailbreak'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return prompts;
|
return prompts;
|
||||||
@ -2205,7 +2206,7 @@ class MessageCollection {
|
|||||||
* @see https://platform.openai.com/docs/guides/gpt/chat-completions-api
|
* @see https://platform.openai.com/docs/guides/gpt/chat-completions-api
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class ChatCompletion {
|
export class ChatCompletion {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Combines consecutive system messages into one if they have no name attached.
|
* Combines consecutive system messages into one if they have no name attached.
|
||||||
@ -2250,6 +2251,7 @@ class ChatCompletion {
|
|||||||
this.tokenBudget = 0;
|
this.tokenBudget = 0;
|
||||||
this.messages = new MessageCollection('root');
|
this.messages = new MessageCollection('root');
|
||||||
this.loggingEnabled = false;
|
this.loggingEnabled = false;
|
||||||
|
this.overriddenPrompts = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2524,6 +2526,18 @@ class ChatCompletion {
|
|||||||
}
|
}
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the list of overridden prompts.
|
||||||
|
* @param {string[]} list A list of prompts that were overridden.
|
||||||
|
*/
|
||||||
|
setOverriddenPrompts(list) {
|
||||||
|
this.overriddenPrompts = list;
|
||||||
|
}
|
||||||
|
|
||||||
|
getOverriddenPrompts() {
|
||||||
|
return this.overriddenPrompts ?? [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadOpenAISettings(data, settings) {
|
function loadOpenAISettings(data, settings) {
|
||||||
|
Reference in New Issue
Block a user