mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Fixes to group join examples parsing
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user