Fixes to group join examples parsing
| @@ -423,14 +423,20 @@ export function getGroupCharacterCards(groupId, characterId) { | ||
| 423 | 423 | * @param {string} value Value to replace |
| 424 | 424 | * @param {string} characterName Name of the character |
| 425 | 425 | * @param {string} fieldName Name of the field |
| 426 | + * @param {function(string): string} [preprocess] Preprocess function | |
| 426 | 427 | * @returns {string} Prepared text |
| 427 | 428 | * */ |
| 428 | 429 | function replaceAndPrepareForJoin(value, characterName, fieldName, preprocess = null) { |
| 429 | 430 | value = value.trim(); |
| 430 | 431 | if (!value) { |
| 431 | 432 | return ''; |
| 432 | 433 | } |
| 433 | 434 | |
| 435 | + // Run preprocess function | |
| 436 | + if (typeof preprocess === 'function') { | |
| 437 | + value = preprocess(value); | |
| 438 | + } | |
| 439 | + | |
| 434 | 440 | // Prepare and replace prefixes |
| 435 | 441 | const prefix = customBaseChatReplace(group.generation_mode_join_prefix, fieldName, characterName); |
| 436 | 442 | const suffix = customBaseChatReplace(group.generation_mode_join_suffix, fieldName, characterName); |
| @@ -465,7 +471,7 @@ export function getGroupCharacterCards(groupId, characterId) { | ||
| 465 | 471 | descriptions.push(replaceAndPrepareForJoin(character.description, character.name, 'Description')); |
| 466 | 472 | personalities.push(replaceAndPrepareForJoin(character.personality, character.name, 'Personality')); |
| 467 | 473 | scenarios.push(replaceAndPrepareForJoin(character.scenario, character.name, 'Scenario')); |
| 468 | 474 | mesExamplesArray.push(replaceAndPrepareForJoin(character.mes_example, character.name, 'Example Messages', (x) => !x.startsWith('<START>') ? `<START>\n${x}` : x)); |
| 469 | 475 | } |
| 470 | 476 | |
| 471 | 477 | const description = descriptions.filter(x => x.length).join('\n'); |
| @@ -33,7 +33,7 @@ import { | ||
| 33 | 33 | system_message_types, |
| 34 | 34 | this_chid, |
| 35 | 35 | } from '../script.js'; |
| 36 | 36 | import { groups, selected_group } from './group-chats.js'; |
| 37 | 37 | |
| 38 | 38 | import { |
| 39 | 39 | chatCompletionDefaultPrompts, |
| @@ -543,11 +543,18 @@ function setupChatCompletionPromptManager(openAiSettings) { | ||
| 543 | 543 | * @returns {Message[]} Array of message objects |
| 544 | 544 | */ |
| 545 | 545 | export function parseExampleIntoIndividual(messageExampleString, appendNamesForGroup = true) { |
| 546 | + const groupMembers = selected_group ? groups.find(x => x.id == selected_group)?.members : null; | |
| 547 | + const groupBotNames = Array.isArray(groupMembers) | |
| 548 | + ? groupMembers.map(x => characters.find(y => y.avatar === x)?.name).filter(x => x).map(x => `${x}:`) | |
| 549 | + : []; | |
| 550 | + | |
| 546 | 551 | let result = []; // array of msgs |
| 547 | 552 | let tmp = messageExampleString.split('\n'); |
| 548 | 553 | let cur_msg_lines = []; |
| 549 | 554 | let in_user = false; |
| 550 | 555 | let in_bot = false; |
| 556 | + let botName = name2; | |
| 557 | + | |
| 551 | 558 | // DRY my cock and balls :) |
| 552 | 559 | function add_msg(name, role, system_name) { |
| 553 | 560 | // join different newlines (we split them by \n and join by \n) |
| @@ -571,10 +578,14 @@ export function parseExampleIntoIndividual(messageExampleString, appendNamesForG | ||
| 571 | 578 | in_user = true; |
| 572 | 579 | // we were in the bot mode previously, add the message |
| 573 | 580 | if (in_bot) { |
| 574 | 581 | add_msg(name2botName, 'system', 'example_assistant'); |
| 575 | 582 | } |
| 576 | 583 | in_bot = false; |
| 577 | 584 | } else if (cur_str.startsWith(name2 + ':') || groupBotNames.some(n => cur_str.startsWith(n))) { |
| 585 | + if (!cur_str.startsWith(name2 + ':') && groupBotNames.length) { | |
| 586 | + botName = cur_str.split(':')[0]; | |
| 587 | + } | |
| 588 | + | |
| 578 | 589 | in_bot = true; |
| 579 | 590 | // we were in the user mode previously, add the message |
| 580 | 591 | if (in_user) { |
| @@ -589,7 +600,7 @@ export function parseExampleIntoIndividual(messageExampleString, appendNamesForG | ||
| 589 | 600 | if (in_user) { |
| 590 | 601 | add_msg(name1, 'system', 'example_user'); |
| 591 | 602 | } else if (in_bot) { |
| 592 | 603 | add_msg(name2botName, 'system', 'example_assistant'); |
| 593 | 604 | } |
| 594 | 605 | return result; |
| 595 | 606 | } |