Smudge groups depth prompts in Join mode.

This commit is contained in:
Cohee
2023-10-26 00:39:11 +03:00
parent 8dcfe57888
commit 5cdc3d1d18
3 changed files with 82 additions and 8 deletions

View File

@@ -60,6 +60,7 @@ import {
getGroupBlock,
getGroupChatNames,
getGroupCharacterCards,
getGroupDepthPrompts,
} from "./scripts/group-chats.js";
import {
@@ -599,7 +600,7 @@ function getCurrentChatId() {
}
const talkativeness_default = 0.5;
const depth_prompt_depth_default = 4;
export const depth_prompt_depth_default = 4;
const per_page_default = 50;
var is_advanced_char_open = false;
@@ -2563,9 +2564,18 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
}
// Depth prompt (character-specific A/N)
const depthPromptText = baseChatReplace(characters[this_chid].data?.extensions?.depth_prompt?.prompt?.trim(), name1, name2) || '';
const depthPromptDepth = characters[this_chid].data?.extensions?.depth_prompt?.depth ?? depth_prompt_depth_default;
setExtensionPrompt('DEPTH_PROMPT', depthPromptText, extension_prompt_types.IN_CHAT, depthPromptDepth);
removeDepthPrompts();
const groupDepthPrompts = getGroupDepthPrompts(selected_group);
if (selected_group && Array.isArray(groupDepthPrompts) && groupDepthPrompts.length > 0) {
groupDepthPrompts.forEach((value, index) => {
setExtensionPrompt('DEPTH_PROMPT_' + index, value.text, extension_prompt_types.IN_CHAT, value.depth);
});
} else {
const depthPromptText = baseChatReplace(characters[this_chid].data?.extensions?.depth_prompt?.prompt?.trim(), name1, name2) || '';
const depthPromptDepth = characters[this_chid].data?.extensions?.depth_prompt?.depth ?? depth_prompt_depth_default;
setExtensionPrompt('DEPTH_PROMPT', depthPromptText, extension_prompt_types.IN_CHAT, depthPromptDepth);
}
// Parse example messages
if (!mesExamples.startsWith('<START>')) {
@@ -5762,6 +5772,18 @@ export function setExtensionPrompt(key, value, position, depth) {
extension_prompts[key] = { value: String(value), position: Number(position), depth: Number(depth) };
}
/**
* Removes all char A/N prompt injections from the chat.
* To clean up when switching from groups to solo and vice versa.
*/
export function removeDepthPrompts() {
for (const key of Object.keys(extension_prompts)) {
if (key.startsWith('DEPTH_PROMPT')) {
delete extension_prompts[key];
}
}
}
/**
* Adds or updates the metadata for the currently active chat.
* @param {Object} newValues An object with collection of new values to be added into the metadata.