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