Reverting cleanUpMessage() functionality changes.

841f8141370f474afaa0452fd5b31b408e6fd2af

qvink <qvink@users.noreply.github.com>

1 files changed, +35 -22Ignore whitespace
public/script.js+35 -22
@@ -3563,9 +3563,10 @@ class StreamingProcessor {
3563 * @param {boolean} quietToLoud true to generate a message in system mode, false to generate a message in character mode3563 * @param {boolean} quietToLoud true to generate a message in system mode, false to generate a message in character mode
3564 * @param {string} [systemPrompt] System prompt to use. Only Instruct mode or OpenAI.3564 * @param {string} [systemPrompt] System prompt to use. Only Instruct mode or OpenAI.
3565 * @param {number} [responseLength] Maximum response length. If unset, the global default value is used.3565 * @param {number} [responseLength] Maximum response length. If unset, the global default value is used.
3566 * @param {boolean} [trimNames] Whether to allow trimming "{{user}}:" and "{{char}}:" from the response.
3566 * @returns {Promise<string>} Generated message3567 * @returns {Promise<string>} Generated message
3567 */3568 */
3568export async function generateRaw(prompt, api, instructOverride, quietToLoud, systemPrompt, responseLength) {3569export async function generateRaw(prompt, api, instructOverride, quietToLoud, systemPrompt, responseLength, trimNames = true) {
3569 if (!api) {3570 if (!api) {
3570 api = main_api;3571 api = main_api;
3571 }3572 }
@@ -3661,6 +3662,8 @@ export async function generateRaw(prompt, api, instructOverride, quietToLoud, sy
3661 isContinue: false,3662 isContinue: false,
3662 displayIncompleteSentences: true,3663 displayIncompleteSentences: true,
3663 includeUserPromptBias: false,3664 includeUserPromptBias: false,
3665 trimNames: trimNames,
3666 trimWrongNames: trimNames,
3664 });3667 });
36653668
3666 if (!message) {3669 if (!message) {
@@ -5970,10 +5973,10 @@ function extractMultiSwipes(data, type) {
5970 *5973 *
5971 * @returns {string} The formatted message5974 * @returns {string} The formatted message
5972 */5975 */
5973export function cleanUpMessage({ getMessage, isImpersonate, isContinue, displayIncompleteSentences = false, stoppingStrings = null, includeUserPromptBias = true, trimNames = true } = {}) {5976export function cleanUpMessage({ getMessage, isImpersonate, isContinue, displayIncompleteSentences = false, stoppingStrings = null, includeUserPromptBias = true, trimNames = true, trimWrongNames = true } = {}) {
5974 if (arguments.length > 0 && typeof arguments[0] !== 'object') {5977 if (arguments.length > 0 && typeof arguments[0] !== 'object') {
5975 console.trace('cleanUpMessage called with positional arguments. Please use an object instead.');5978 console.trace('cleanUpMessage called with positional arguments. Please use an object instead.');
5976 [getMessage, isImpersonate, isContinue, displayIncompleteSentences, stoppingStrings, includeUserPromptBias] = arguments;5979 [getMessage, isImpersonate, isContinue, displayIncompleteSentences, stoppingStrings, includeUserPromptBias, trimNames, trimWrongNames] = arguments;
5977 }5980 }
59785981
5979 if (!getMessage) {5982 if (!getMessage) {
@@ -6020,26 +6023,33 @@ export function cleanUpMessage({ getMessage, isImpersonate, isContinue, displayI
6020 // "trailing whitespace on newlines\nevery line of the string\nsample text"6023 // "trailing whitespace on newlines\nevery line of the string\nsample text"
6021 getMessage = getMessage.replace(/[^\S\r\n]+$/gm, '');6024 getMessage = getMessage.replace(/[^\S\r\n]+$/gm, '');
60226025
6023 // Trim instances of "{{name}}:" from the start of the message+6026 if (trimWrongNames) {
6024 if (trimNames) {6027 // If this is an impersonation, delete the entire response if it starts with "{{char}}:"
6025 let nameToTrim = isImpersonate ? name2 : name1;6028 // If this isn't an impersonation, delete the entire response if it starts with "{{user}}:"
6026 if (isImpersonate) {6029 // Also delete any trailing text that starts with the wrong name.
6027 nameToTrim = power_user.allow_name2_display ? '' : name2;6030 // This only occurs if the corresponding "power_user.allow_nameX_display" is false.
6028 } else {
6029 nameToTrim = power_user.allow_name1_display ? '' : name1;
6030 }
60316031
6032 // get text from after the name (and colon) to the end of the string6032 let wrongName = isImpersonate
6033 if (nameToTrim && getMessage.indexOf(`${nameToTrim}:`) === 0) {6033 ? (power_user.allow_name2_display ? '' : name2) // char
6034 getMessage = getMessage.substring(nameToTrim.length + 1);6034 : (power_user.allow_name1_display ? '' : name1); // user
6035 }
60366035
6037 // account for case where the name is after a newline6036 if (wrongName) {
6038 let startIndex = getMessage.indexOf(`\n${nameToTrim}:`);6037 // If the message starts with the wrong name, delete the entire response
6039 if (nameToTrim && startIndex >= 0) {6038 let startIndex = getMessage.indexOf(`${wrongName}`);
6040 getMessage = getMessage.substring(startIndex + nameToTrim.length + 2);6039 if (startIndex === 0) {
6040 getMessage = '';
6041 console.debug(`Message started with the wrong name: "${wrongName}" - response was deleted.`);
6042 }
6043
6044 // If there is trailing text starting with the wrong name, trim it off.
6045 startIndex = getMessage.indexOf(`\n${wrongName}:`);
6046 if (startIndex >= 0) {
6047 getMessage = getMessage.substring(0, startIndex);
6048 }
6049
6050 // remove any whitespace at the beginning
6051 getMessage = getMessage.trimStart();
6041 }6052 }
6042 getMessage.trimStart();
6043 }6053 }
60446054
6045 if (getMessage.indexOf('<|endoftext|>') != -1) {6055 if (getMessage.indexOf('<|endoftext|>') != -1) {
@@ -6102,9 +6112,12 @@ export function cleanUpMessage({ getMessage, isImpersonate, isContinue, displayI
6102 }6112 }
61036113
6104 if (trimNames) {6114 if (trimNames) {
6115 // If this is an impersonation, trim "{{user}}:" from the beginning
6116 // If this isn't an impersonation, trim "{{char}}:" from the beginning.
6117 // Only applied when the corresponding "power_user.allow_nameX_display" is false.
6105 const nameToTrim2 = isImpersonate6118 const nameToTrim2 = isImpersonate
6106 ? (!power_user.allow_name1_display ? name1 : '')6119 ? (!power_user.allow_name1_display ? name1 : '') // user
6107 : (!power_user.allow_name2_display ? name2 : '');6120 : (!power_user.allow_name2_display ? name2 : ''); // char
61086121
6109 if (nameToTrim2 && getMessage.startsWith(nameToTrim2 + ':')) {6122 if (nameToTrim2 && getMessage.startsWith(nameToTrim2 + ':')) {
6110 getMessage = getMessage.replace(nameToTrim2 + ':', '');6123 getMessage = getMessage.replace(nameToTrim2 + ':', '');