mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Smudge groups depth prompts in Join mode.
This commit is contained in:
@@ -60,6 +60,7 @@ import {
|
|||||||
getGroupBlock,
|
getGroupBlock,
|
||||||
getGroupChatNames,
|
getGroupChatNames,
|
||||||
getGroupCharacterCards,
|
getGroupCharacterCards,
|
||||||
|
getGroupDepthPrompts,
|
||||||
} from "./scripts/group-chats.js";
|
} from "./scripts/group-chats.js";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -599,7 +600,7 @@ function getCurrentChatId() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const talkativeness_default = 0.5;
|
const talkativeness_default = 0.5;
|
||||||
const depth_prompt_depth_default = 4;
|
export const depth_prompt_depth_default = 4;
|
||||||
const per_page_default = 50;
|
const per_page_default = 50;
|
||||||
|
|
||||||
var is_advanced_char_open = false;
|
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)
|
// Depth prompt (character-specific A/N)
|
||||||
const depthPromptText = baseChatReplace(characters[this_chid].data?.extensions?.depth_prompt?.prompt?.trim(), name1, name2) || '';
|
removeDepthPrompts();
|
||||||
const depthPromptDepth = characters[this_chid].data?.extensions?.depth_prompt?.depth ?? depth_prompt_depth_default;
|
const groupDepthPrompts = getGroupDepthPrompts(selected_group);
|
||||||
setExtensionPrompt('DEPTH_PROMPT', depthPromptText, extension_prompt_types.IN_CHAT, depthPromptDepth);
|
|
||||||
|
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
|
// Parse example messages
|
||||||
if (!mesExamples.startsWith('<START>')) {
|
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) };
|
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.
|
* 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.
|
* @param {Object} newValues An object with collection of new values to be added into the metadata.
|
||||||
|
@@ -67,6 +67,7 @@ import {
|
|||||||
isChatSaving,
|
isChatSaving,
|
||||||
setExternalAbortController,
|
setExternalAbortController,
|
||||||
baseChatReplace,
|
baseChatReplace,
|
||||||
|
depth_prompt_depth_default,
|
||||||
} from "../script.js";
|
} from "../script.js";
|
||||||
import { appendTagToList, createTagMapFromList, getTagsList, applyTagsOnCharacterSelect, tag_map, printTagFilters } from './tags.js';
|
import { appendTagToList, createTagMapFromList, getTagsList, applyTagsOnCharacterSelect, tag_map, printTagFilters } from './tags.js';
|
||||||
import { FILTER_TYPES, FilterHelper } from './filters.js';
|
import { FILTER_TYPES, FilterHelper } from './filters.js';
|
||||||
@@ -199,6 +200,53 @@ export async function getGroupChat(groupId) {
|
|||||||
eventSource.emit(event_types.CHAT_CHANGED, getCurrentChatId());
|
eventSource.emit(event_types.CHAT_CHANGED, getCurrentChatId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets depth prompts for group members.
|
||||||
|
* @param {string} groupId Group ID
|
||||||
|
* @returns {{depth: number, text: string}[]} Array of depth prompts
|
||||||
|
*/
|
||||||
|
export function getGroupDepthPrompts(groupId) {
|
||||||
|
if (!groupId) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
console.debug('getGroupDepthPrompts entered for group: ', groupId);
|
||||||
|
const group = groups.find(x => x.id === groupId);
|
||||||
|
|
||||||
|
if (!group || !Array.isArray(group.members) || !group.members.length) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (group.generation_mode === group_generation_mode.SWAP) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const depthPrompts = [];
|
||||||
|
|
||||||
|
for (const member of group.members) {
|
||||||
|
if (group.disabled_members.includes(member)) {
|
||||||
|
console.debug(`Skipping disabled group member: ${member}`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const character = characters.find(x => x.avatar === member);
|
||||||
|
|
||||||
|
if (!character) {
|
||||||
|
console.debug(`Skipping missing member: ${member}`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const depthPromptText = baseChatReplace(character.data?.extensions?.depth_prompt?.prompt?.trim(), name1, character.name) || '';
|
||||||
|
const depthPromptDepth = character.data?.extensions?.depth_prompt?.depth ?? depth_prompt_depth_default;
|
||||||
|
|
||||||
|
if (depthPromptText) {
|
||||||
|
depthPrompts.push({ text: depthPromptText, depth: depthPromptDepth });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return depthPrompts;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Combines group members info a single string. Only for groups with generation mode set to APPEND.
|
* Combines group members info a single string. Only for groups with generation mode set to APPEND.
|
||||||
* @param {string} groupId Group ID
|
* @param {string} groupId Group ID
|
||||||
|
@@ -1383,12 +1383,16 @@ async function checkWorldInfo(chat, maxContext) {
|
|||||||
// Add the depth or AN if enabled
|
// Add the depth or AN if enabled
|
||||||
// Put this code here since otherwise, the chat reference is modified
|
// Put this code here since otherwise, the chat reference is modified
|
||||||
if (extension_settings.note.allowWIScan) {
|
if (extension_settings.note.allowWIScan) {
|
||||||
let depthPrompt = getExtensionPromptByName("DEPTH_PROMPT")
|
for (const key of Object.keys(context.extensionPrompts)) {
|
||||||
if (depthPrompt) {
|
if (key.startsWith('DEPTH_PROMPT')) {
|
||||||
textToScan = `${depthPrompt}\n${textToScan}`
|
const depthPrompt = getExtensionPromptByName(key)
|
||||||
|
if (depthPrompt) {
|
||||||
|
textToScan = `${depthPrompt}\n${textToScan}`
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let anPrompt = getExtensionPromptByName(NOTE_MODULE_NAME);
|
const anPrompt = getExtensionPromptByName(NOTE_MODULE_NAME);
|
||||||
if (anPrompt) {
|
if (anPrompt) {
|
||||||
textToScan = `${anPrompt}\n${textToScan}`
|
textToScan = `${anPrompt}\n${textToScan}`
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user