mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'staging' into sysprompt-divorce
This commit is contained in:
@@ -427,12 +427,13 @@ class PromptManager {
|
||||
|
||||
document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_name').value = prompt.name;
|
||||
document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_role').value = 'system';
|
||||
document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_prompt').value = prompt.content;
|
||||
document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_prompt').value = prompt.content ?? '';
|
||||
document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_position').value = prompt.injection_position ?? 0;
|
||||
document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_depth').value = prompt.injection_depth ?? DEFAULT_DEPTH;
|
||||
document.getElementById(this.configuration.prefix + 'prompt_manager_depth_block').style.visibility = prompt.injection_position === INJECTION_POSITION.ABSOLUTE ? 'visible' : 'hidden';
|
||||
document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_forbid_overrides').checked = prompt.forbid_overrides ?? false;
|
||||
document.getElementById(this.configuration.prefix + 'prompt_manager_forbid_overrides_block').style.visibility = this.overridablePrompts.includes(prompt.identifier) ? 'visible' : 'hidden';
|
||||
document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_prompt').disabled = prompt.marker ?? false;
|
||||
|
||||
if (!this.systemPrompts.includes(promptId)) {
|
||||
document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_position').removeAttribute('disabled');
|
||||
@@ -920,7 +921,15 @@ class PromptManager {
|
||||
* @returns {boolean} True if the prompt can be edited, false otherwise.
|
||||
*/
|
||||
isPromptEditAllowed(prompt) {
|
||||
return !prompt.marker;
|
||||
const forceEditPrompts = [
|
||||
'charDescription',
|
||||
'charPersonality',
|
||||
'scenario',
|
||||
'personaDescription',
|
||||
'worldInfoBefore',
|
||||
'worldInfoAfter',
|
||||
];
|
||||
return forceEditPrompts.includes(prompt.identifier) || !prompt.marker;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -929,7 +938,17 @@ class PromptManager {
|
||||
* @returns {boolean} True if the prompt can be deleted, false otherwise.
|
||||
*/
|
||||
isPromptToggleAllowed(prompt) {
|
||||
const forceTogglePrompts = ['charDescription', 'charPersonality', 'scenario', 'personaDescription', 'worldInfoBefore', 'worldInfoAfter', 'main', 'chatHistory', 'dialogueExamples'];
|
||||
const forceTogglePrompts = [
|
||||
'charDescription',
|
||||
'charPersonality',
|
||||
'scenario',
|
||||
'personaDescription',
|
||||
'worldInfoBefore',
|
||||
'worldInfoAfter',
|
||||
'main',
|
||||
'chatHistory',
|
||||
'dialogueExamples',
|
||||
];
|
||||
return prompt.marker && !forceTogglePrompts.includes(prompt.identifier) ? false : !this.configuration.toggleDisabled.includes(prompt.identifier);
|
||||
}
|
||||
|
||||
@@ -1182,8 +1201,9 @@ class PromptManager {
|
||||
const forbidOverridesBlock = document.getElementById(this.configuration.prefix + 'prompt_manager_forbid_overrides_block');
|
||||
|
||||
nameField.value = prompt.name ?? '';
|
||||
roleField.value = prompt.role ?? '';
|
||||
roleField.value = prompt.role ?? 'system';
|
||||
promptField.value = prompt.content ?? '';
|
||||
promptField.disabled = prompt.marker ?? false;
|
||||
injectionPositionField.value = prompt.injection_position ?? INJECTION_POSITION.RELATIVE;
|
||||
injectionDepthField.value = prompt.injection_depth ?? DEFAULT_DEPTH;
|
||||
injectionDepthBlock.style.visibility = prompt.injection_position === INJECTION_POSITION.ABSOLUTE ? 'visible' : 'hidden';
|
||||
@@ -1279,6 +1299,7 @@ class PromptManager {
|
||||
nameField.value = '';
|
||||
roleField.selectedIndex = 0;
|
||||
promptField.value = '';
|
||||
promptField.disabled = false;
|
||||
injectionPositionField.selectedIndex = 0;
|
||||
injectionPositionField.removeAttribute('disabled');
|
||||
injectionDepthField.value = DEFAULT_DEPTH;
|
||||
|
@@ -970,6 +970,12 @@ async function populateChatCompletion(prompts, chatCompletion, { bias, quietProm
|
||||
}
|
||||
|
||||
const prompt = prompts.get(source);
|
||||
|
||||
if (prompt.injection_position === INJECTION_POSITION.ABSOLUTE) {
|
||||
promptManager.log(`Skipping prompt ${source} because it is an absolute prompt`);
|
||||
return;
|
||||
}
|
||||
|
||||
const index = target ? prompts.index(target) : prompts.index(source);
|
||||
const collection = new MessageCollection(source);
|
||||
collection.add(Message.fromPrompt(prompt));
|
||||
@@ -1014,8 +1020,8 @@ async function populateChatCompletion(prompts, chatCompletion, { bias, quietProm
|
||||
acc.push(prompt.identifier);
|
||||
return acc;
|
||||
}, []);
|
||||
const userAbsolutePrompts = prompts.collection
|
||||
.filter((prompt) => false === prompt.system_prompt && prompt.injection_position === INJECTION_POSITION.ABSOLUTE)
|
||||
const absolutePrompts = prompts.collection
|
||||
.filter((prompt) => prompt.injection_position === INJECTION_POSITION.ABSOLUTE)
|
||||
.reduce((acc, prompt) => {
|
||||
acc.push(prompt);
|
||||
return acc;
|
||||
@@ -1080,7 +1086,7 @@ async function populateChatCompletion(prompts, chatCompletion, { bias, quietProm
|
||||
}
|
||||
|
||||
// Add in-chat injections
|
||||
messages = populationInjectionPrompts(userAbsolutePrompts, messages);
|
||||
messages = populationInjectionPrompts(absolutePrompts, messages);
|
||||
|
||||
// Decide whether dialogue examples should always be added
|
||||
if (power_user.pin_examples) {
|
||||
@@ -1217,6 +1223,18 @@ function preparePromptsForChatCompletion({ Scenario, charPersonality, name2, wor
|
||||
|
||||
// Merge system prompts with prompt manager prompts
|
||||
systemPrompts.forEach(prompt => {
|
||||
const collectionPrompt = prompts.get(prompt.identifier);
|
||||
|
||||
// Apply system prompt role/depth overrides if they set in the prompt manager
|
||||
if (collectionPrompt) {
|
||||
// In-Chat / Relative
|
||||
prompt.injection_position = collectionPrompt.injection_position ?? prompt.injection_position;
|
||||
// Depth for In-Chat
|
||||
prompt.injection_depth = collectionPrompt.injection_depth ?? prompt.injection_depth;
|
||||
// Role (system, user, assistant)
|
||||
prompt.role = collectionPrompt.role ?? prompt.role;
|
||||
}
|
||||
|
||||
const newPrompt = promptManager.preparePrompt(prompt);
|
||||
const markerIndex = prompts.index(prompt.identifier);
|
||||
|
||||
|
@@ -30,6 +30,7 @@ export const tokenizers = {
|
||||
JAMBA: 14,
|
||||
QWEN2: 15,
|
||||
COMMAND_R: 16,
|
||||
NEMO: 17,
|
||||
BEST_MATCH: 99,
|
||||
};
|
||||
|
||||
@@ -43,6 +44,7 @@ export const ENCODE_TOKENIZERS = [
|
||||
tokenizers.JAMBA,
|
||||
tokenizers.QWEN2,
|
||||
tokenizers.COMMAND_R,
|
||||
tokenizers.NEMO,
|
||||
// uncomment when NovelAI releases Kayra and Clio weights, lol
|
||||
//tokenizers.NERD,
|
||||
//tokenizers.NERD2,
|
||||
@@ -121,6 +123,11 @@ const TOKENIZER_URLS = {
|
||||
decode: '/api/tokenizers/command-r/decode',
|
||||
count: '/api/tokenizers/command-r/encode',
|
||||
},
|
||||
[tokenizers.NEMO]: {
|
||||
encode: '/api/tokenizers/nemo/encode',
|
||||
decode: '/api/tokenizers/nemo/decode',
|
||||
count: '/api/tokenizers/nemo/encode',
|
||||
},
|
||||
[tokenizers.API_TEXTGENERATIONWEBUI]: {
|
||||
encode: '/api/tokenizers/remote/textgenerationwebui/encode',
|
||||
count: '/api/tokenizers/remote/textgenerationwebui/encode',
|
||||
@@ -535,6 +542,7 @@ export function getTokenizerModel() {
|
||||
const jambaTokenizer = 'jamba';
|
||||
const qwen2Tokenizer = 'qwen2';
|
||||
const commandRTokenizer = 'command-r';
|
||||
const nemoTokenizer = 'nemo';
|
||||
|
||||
// Assuming no one would use it for different models.. right?
|
||||
if (oai_settings.chat_completion_source == chat_completion_sources.SCALE) {
|
||||
@@ -628,6 +636,9 @@ export function getTokenizerModel() {
|
||||
}
|
||||
|
||||
if (oai_settings.chat_completion_source == chat_completion_sources.MISTRALAI) {
|
||||
if (oai_settings.mistralai_model.includes('nemo') || oai_settings.mistralai_model.includes('pixtral')) {
|
||||
return nemoTokenizer;
|
||||
}
|
||||
return mistralTokenizer;
|
||||
}
|
||||
|
||||
|
@@ -4134,10 +4134,10 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
|
||||
|
||||
switch (entry.position) {
|
||||
case world_info_position.before:
|
||||
WIBeforeEntries.unshift(substituteParams(content));
|
||||
WIBeforeEntries.unshift(content);
|
||||
break;
|
||||
case world_info_position.after:
|
||||
WIAfterEntries.unshift(substituteParams(content));
|
||||
WIAfterEntries.unshift(content);
|
||||
break;
|
||||
case world_info_position.EMTop:
|
||||
EMEntries.unshift(
|
||||
|
Reference in New Issue
Block a user