Add toggle for names as stop strings

Closes #2556
This commit is contained in:
Cohee
2024-07-28 22:22:36 +03:00
parent cacd570af3
commit 82a633da57
3 changed files with 27 additions and 17 deletions

View File

@ -2470,26 +2470,30 @@ export function substituteParams(content, _name1, _name2, _original, _group, _re
* @returns {string[]} Array of stopping strings
*/
export function getStoppingStrings(isImpersonate, isContinue) {
const charString = `\n${name2}:`;
const userString = `\n${name1}:`;
const result = isImpersonate ? [charString] : [userString];
const result = [];
result.push(userString);
if (power_user.context.names_as_stop_strings) {
const charString = `\n${name2}:`;
const userString = `\n${name1}:`;
result.push(isImpersonate ? charString : userString);
if (isContinue && Array.isArray(chat) && chat[chat.length - 1]?.is_user) {
result.push(charString);
}
result.push(userString);
// Add other group members as the stopping strings
if (selected_group) {
const group = groups.find(x => x.id === selected_group);
if (isContinue && Array.isArray(chat) && chat[chat.length - 1]?.is_user) {
result.push(charString);
}
if (group && Array.isArray(group.members)) {
const names = group.members
.map(x => characters.find(y => y.avatar == x))
.filter(x => x && x.name && x.name !== name2)
.map(x => `\n${x.name}:`);
result.push(...names);
// Add other group members as the stopping strings
if (selected_group) {
const group = groups.find(x => x.id === selected_group);
if (group && Array.isArray(group.members)) {
const names = group.members
.map(x => characters.find(y => y.avatar == x))
.filter(x => x && x.name && x.name !== name2)
.map(x => `\n${x.name}:`);
result.push(...names);
}
}
}