Reverting cleanUpMessage() functionality changes.
| @@ -3563,9 +3563,10 @@ class StreamingProcessor { | ||
| 3563 | 3563 | * @param {boolean} quietToLoud true to generate a message in system mode, false to generate a message in character mode |
| 3564 | 3564 | * @param {string} [systemPrompt] System prompt to use. Only Instruct mode or OpenAI. |
| 3565 | 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 | 3567 | * @returns {Promise<string>} Generated message |
| 3567 | 3568 | */ |
| 3568 | 3569 | export async function generateRaw(prompt, api, instructOverride, quietToLoud, systemPrompt, responseLength, trimNames = true) { |
| 3569 | 3570 | if (!api) { |
| 3570 | 3571 | api = main_api; |
| 3571 | 3572 | } |
| @@ -3661,6 +3662,8 @@ export async function generateRaw(prompt, api, instructOverride, quietToLoud, sy | ||
| 3661 | 3662 | isContinue: false, |
| 3662 | 3663 | displayIncompleteSentences: true, |
| 3663 | 3664 | includeUserPromptBias: false, |
| 3665 | + trimNames: trimNames, | |
| 3666 | + trimWrongNames: trimNames, | |
| 3664 | 3667 | }); |
| 3665 | 3668 | |
| 3666 | 3669 | if (!message) { |
| @@ -5970,10 +5973,10 @@ function extractMultiSwipes(data, type) { | ||
| 5970 | 5973 | * |
| 5971 | 5974 | * @returns {string} The formatted message |
| 5972 | 5975 | */ |
| 5973 | 5976 | export function cleanUpMessage({ getMessage, isImpersonate, isContinue, displayIncompleteSentences = false, stoppingStrings = null, includeUserPromptBias = true, trimNames = true, trimWrongNames = true } = {}) { |
| 5974 | 5977 | if (arguments.length > 0 && typeof arguments[0] !== 'object') { |
| 5975 | 5978 | console.trace('cleanUpMessage called with positional arguments. Please use an object instead.'); |
| 5976 | 5979 | [getMessage, isImpersonate, isContinue, displayIncompleteSentences, stoppingStrings, includeUserPromptBias, trimNames, trimWrongNames] = arguments; |
| 5977 | 5980 | } |
| 5978 | 5981 | |
| 5979 | 5982 | if (!getMessage) { |
| @@ -6020,26 +6023,33 @@ export function cleanUpMessage({ getMessage, isImpersonate, isContinue, displayI | ||
| 6020 | 6023 | // "trailing whitespace on newlines\nevery line of the string\nsample text" |
| 6021 | 6024 | getMessage = getMessage.replace(/[^\S\r\n]+$/gm, ''); |
| 6022 | 6025 | |
| 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 | - } | |
| 6031 | 6031 | |
| 6032 | - // get text from after the name (and colon) to the end of the string | |
| 6032 | + 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 | - } | |
| 6036 | 6035 | |
| 6037 | - // account for case where the name is after a newline | |
| 6036 | + 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 | } |
| 6044 | 6054 | |
| 6045 | 6055 | if (getMessage.indexOf('<|endoftext|>') != -1) { |
| @@ -6102,9 +6112,12 @@ export function cleanUpMessage({ getMessage, isImpersonate, isContinue, displayI | ||
| 6102 | 6112 | } |
| 6103 | 6113 | |
| 6104 | 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 | 6118 | const nameToTrim2 = isImpersonate |
| 6106 | 6119 | ? (!power_user.allow_name1_display ? name1 : '') // user |
| 6107 | 6120 | : (!power_user.allow_name2_display ? name2 : ''); // char |
| 6108 | 6121 | |
| 6109 | 6122 | if (nameToTrim2 && getMessage.startsWith(nameToTrim2 + ':')) { |
| 6110 | 6123 | getMessage = getMessage.replace(nameToTrim2 + ':', ''); |