mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-23 07:27:41 +01:00
Fixes to group join examples parsing
This commit is contained in:
parent
e49301308c
commit
2d66b7204a
@ -423,14 +423,20 @@ export function getGroupCharacterCards(groupId, characterId) {
|
||||
* @param {string} value Value to replace
|
||||
* @param {string} characterName Name of the character
|
||||
* @param {string} fieldName Name of the field
|
||||
* @param {function(string): string} [preprocess] Preprocess function
|
||||
* @returns {string} Prepared text
|
||||
* */
|
||||
function replaceAndPrepareForJoin(value, characterName, fieldName) {
|
||||
function replaceAndPrepareForJoin(value, characterName, fieldName, preprocess = null) {
|
||||
value = value.trim();
|
||||
if (!value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Run preprocess function
|
||||
if (typeof preprocess === 'function') {
|
||||
value = preprocess(value);
|
||||
}
|
||||
|
||||
// Prepare and replace prefixes
|
||||
const prefix = customBaseChatReplace(group.generation_mode_join_prefix, fieldName, characterName);
|
||||
const suffix = customBaseChatReplace(group.generation_mode_join_suffix, fieldName, characterName);
|
||||
@ -465,7 +471,7 @@ export function getGroupCharacterCards(groupId, characterId) {
|
||||
descriptions.push(replaceAndPrepareForJoin(character.description, character.name, 'Description'));
|
||||
personalities.push(replaceAndPrepareForJoin(character.personality, character.name, 'Personality'));
|
||||
scenarios.push(replaceAndPrepareForJoin(character.scenario, character.name, 'Scenario'));
|
||||
mesExamplesArray.push(replaceAndPrepareForJoin(character.mes_example, character.name, 'Example Messages'));
|
||||
mesExamplesArray.push(replaceAndPrepareForJoin(character.mes_example, character.name, 'Example Messages', (x) => !x.startsWith('<START>') ? `<START>\n${x}` : x));
|
||||
}
|
||||
|
||||
const description = descriptions.filter(x => x.length).join('\n');
|
||||
|
@ -33,7 +33,7 @@ import {
|
||||
system_message_types,
|
||||
this_chid,
|
||||
} from '../script.js';
|
||||
import { selected_group } from './group-chats.js';
|
||||
import { groups, selected_group } from './group-chats.js';
|
||||
|
||||
import {
|
||||
chatCompletionDefaultPrompts,
|
||||
@ -543,11 +543,18 @@ function setupChatCompletionPromptManager(openAiSettings) {
|
||||
* @returns {Message[]} Array of message objects
|
||||
*/
|
||||
export function parseExampleIntoIndividual(messageExampleString, appendNamesForGroup = true) {
|
||||
const groupMembers = selected_group ? groups.find(x => x.id == selected_group)?.members : null;
|
||||
const groupBotNames = Array.isArray(groupMembers)
|
||||
? groupMembers.map(x => characters.find(y => y.avatar === x)?.name).filter(x => x).map(x => `${x}:`)
|
||||
: [];
|
||||
|
||||
let result = []; // array of msgs
|
||||
let tmp = messageExampleString.split('\n');
|
||||
let cur_msg_lines = [];
|
||||
let in_user = false;
|
||||
let in_bot = false;
|
||||
let botName = name2;
|
||||
|
||||
// DRY my cock and balls :)
|
||||
function add_msg(name, role, system_name) {
|
||||
// join different newlines (we split them by \n and join by \n)
|
||||
@ -571,10 +578,14 @@ export function parseExampleIntoIndividual(messageExampleString, appendNamesForG
|
||||
in_user = true;
|
||||
// we were in the bot mode previously, add the message
|
||||
if (in_bot) {
|
||||
add_msg(name2, 'system', 'example_assistant');
|
||||
add_msg(botName, 'system', 'example_assistant');
|
||||
}
|
||||
in_bot = false;
|
||||
} else if (cur_str.startsWith(name2 + ':')) {
|
||||
} else if (cur_str.startsWith(name2 + ':') || groupBotNames.some(n => cur_str.startsWith(n))) {
|
||||
if (!cur_str.startsWith(name2 + ':') && groupBotNames.length) {
|
||||
botName = cur_str.split(':')[0];
|
||||
}
|
||||
|
||||
in_bot = true;
|
||||
// we were in the user mode previously, add the message
|
||||
if (in_user) {
|
||||
@ -589,7 +600,7 @@ export function parseExampleIntoIndividual(messageExampleString, appendNamesForG
|
||||
if (in_user) {
|
||||
add_msg(name1, 'system', 'example_user');
|
||||
} else if (in_bot) {
|
||||
add_msg(name2, 'system', 'example_assistant');
|
||||
add_msg(botName, 'system', 'example_assistant');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user