mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2024-12-12 09:26:33 +01:00
Fix unknown relative extension injects not working in Chat Completion
This commit is contained in:
parent
07ac2460e2
commit
345bae4fc0
@ -72,7 +72,7 @@ const registerPromptManagerMigration = () => {
|
||||
* Represents a prompt.
|
||||
*/
|
||||
class Prompt {
|
||||
identifier; role; content; name; system_prompt; position; injection_position; injection_depth; forbid_overrides;
|
||||
identifier; role; content; name; system_prompt; position; injection_position; injection_depth; forbid_overrides; extension;
|
||||
|
||||
/**
|
||||
* Create a new Prompt instance.
|
||||
@ -87,8 +87,9 @@ class Prompt {
|
||||
* @param {number} param0.injection_position - The insert position of the prompt.
|
||||
* @param {number} param0.injection_depth - The depth of the prompt in the chat.
|
||||
* @param {boolean} param0.forbid_overrides - Indicates if the prompt should not be overridden.
|
||||
* @param {boolean} param0.extension - Prompt is added by an extension.
|
||||
*/
|
||||
constructor({ identifier, role, content, name, system_prompt, position, injection_depth, injection_position, forbid_overrides } = {}) {
|
||||
constructor({ identifier, role, content, name, system_prompt, position, injection_depth, injection_position, forbid_overrides, extension } = {}) {
|
||||
this.identifier = identifier;
|
||||
this.role = role;
|
||||
this.content = content;
|
||||
@ -98,6 +99,7 @@ class Prompt {
|
||||
this.injection_depth = injection_depth;
|
||||
this.injection_position = injection_position;
|
||||
this.forbid_overrides = forbid_overrides;
|
||||
this.extension = extension ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1082,6 +1082,11 @@ async function populateChatCompletion(prompts, chatCompletion, { bias, quietProm
|
||||
}
|
||||
}
|
||||
|
||||
// Other relative extension prompts
|
||||
for (const prompt of prompts.collection.filter(p => p.extension && p.position)) {
|
||||
chatCompletion.insert(Message.fromPrompt(prompt), 'main', prompt.position);
|
||||
}
|
||||
|
||||
// Add in-chat injections
|
||||
messages = populationInjectionPrompts(userAbsolutePrompts, messages);
|
||||
|
||||
@ -1187,6 +1192,35 @@ function preparePromptsForChatCompletion({ Scenario, charPersonality, name2, wor
|
||||
systemPrompts.push({ role: 'system', content: power_user.persona_description, identifier: 'personaDescription' });
|
||||
}
|
||||
|
||||
const knownExtensionPrompts = [
|
||||
'1_memory',
|
||||
'2_floating_prompt',
|
||||
'3_vectors',
|
||||
'4_vectors_data_bank',
|
||||
'chromadb',
|
||||
'PERSONA_DESCRIPTION',
|
||||
'QUIET_PROMPT',
|
||||
'DEPTH_PROMPT',
|
||||
];
|
||||
|
||||
// Anything that is not a known extension prompt
|
||||
for (const key in extensionPrompts) {
|
||||
if (Object.hasOwn(extensionPrompts, key)) {
|
||||
const prompt = extensionPrompts[key];
|
||||
if (knownExtensionPrompts.includes(key)) continue;
|
||||
if (!extensionPrompts[key].value) continue;
|
||||
if (![extension_prompt_types.BEFORE_PROMPT, extension_prompt_types.IN_PROMPT].includes(prompt.position)) continue;
|
||||
|
||||
systemPrompts.push({
|
||||
identifier: key.replace(/\W/g, '_'),
|
||||
position: getPromptPosition(prompt.position),
|
||||
role: getPromptRole(prompt.role),
|
||||
content: prompt.value,
|
||||
extension: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// This is the prompt order defined by the user
|
||||
const prompts = promptManager.getPromptCollection();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user