Reverting cleanUpMessage() functionality changes.

This commit is contained in:
qvink
2025-03-22 15:52:37 -06:00
parent 82b885e5ef
commit 841f814137

View File

@@ -3563,9 +3563,10 @@ class StreamingProcessor {
* @param {boolean} quietToLoud true to generate a message in system mode, false to generate a message in character mode * @param {boolean} quietToLoud true to generate a message in system mode, false to generate a message in character mode
* @param {string} [systemPrompt] System prompt to use. Only Instruct mode or OpenAI. * @param {string} [systemPrompt] System prompt to use. Only Instruct mode or OpenAI.
* @param {number} [responseLength] Maximum response length. If unset, the global default value is used. * @param {number} [responseLength] Maximum response length. If unset, the global default value is used.
* @param {boolean} [trimNames] Whether to allow trimming "{{user}}:" and "{{char}}:" from the response.
* @returns {Promise<string>} Generated message * @returns {Promise<string>} Generated message
*/ */
export async function generateRaw(prompt, api, instructOverride, quietToLoud, systemPrompt, responseLength) { export async function generateRaw(prompt, api, instructOverride, quietToLoud, systemPrompt, responseLength, trimNames = true) {
if (!api) { if (!api) {
api = main_api; api = main_api;
} }
@@ -3661,6 +3662,8 @@ export async function generateRaw(prompt, api, instructOverride, quietToLoud, sy
isContinue: false, isContinue: false,
displayIncompleteSentences: true, displayIncompleteSentences: true,
includeUserPromptBias: false, includeUserPromptBias: false,
trimNames: trimNames,
trimWrongNames: trimNames,
}); });
if (!message) { if (!message) {
@@ -5970,10 +5973,10 @@ function extractMultiSwipes(data, type) {
* *
* @returns {string} The formatted message * @returns {string} The formatted message
*/ */
export function cleanUpMessage({ getMessage, isImpersonate, isContinue, displayIncompleteSentences = false, stoppingStrings = null, includeUserPromptBias = true, trimNames = true } = {}) { export function cleanUpMessage({ getMessage, isImpersonate, isContinue, displayIncompleteSentences = false, stoppingStrings = null, includeUserPromptBias = true, trimNames = true, trimWrongNames = true } = {}) {
if (arguments.length > 0 && typeof arguments[0] !== 'object') { if (arguments.length > 0 && typeof arguments[0] !== 'object') {
console.trace('cleanUpMessage called with positional arguments. Please use an object instead.'); console.trace('cleanUpMessage called with positional arguments. Please use an object instead.');
[getMessage, isImpersonate, isContinue, displayIncompleteSentences, stoppingStrings, includeUserPromptBias] = arguments; [getMessage, isImpersonate, isContinue, displayIncompleteSentences, stoppingStrings, includeUserPromptBias, trimNames, trimWrongNames] = arguments;
} }
if (!getMessage) { if (!getMessage) {
@@ -6020,26 +6023,33 @@ export function cleanUpMessage({ getMessage, isImpersonate, isContinue, displayI
// "trailing whitespace on newlines\nevery line of the string\nsample text" // "trailing whitespace on newlines\nevery line of the string\nsample text"
getMessage = getMessage.replace(/[^\S\r\n]+$/gm, ''); getMessage = getMessage.replace(/[^\S\r\n]+$/gm, '');
// Trim instances of "{{name}}:" from the start of the message+ if (trimWrongNames) {
if (trimNames) { // If this is an impersonation, delete the entire response if it starts with "{{char}}:"
let nameToTrim = isImpersonate ? name2 : name1; // If this isn't an impersonation, delete the entire response if it starts with "{{user}}:"
if (isImpersonate) { // Also delete any trailing text that starts with the wrong name.
nameToTrim = power_user.allow_name2_display ? '' : name2; // This only occurs if the corresponding "power_user.allow_nameX_display" is false.
} else {
nameToTrim = power_user.allow_name1_display ? '' : name1;
}
// get text from after the name (and colon) to the end of the string let wrongName = isImpersonate
if (nameToTrim && getMessage.indexOf(`${nameToTrim}:`) === 0) { ? (power_user.allow_name2_display ? '' : name2) // char
getMessage = getMessage.substring(nameToTrim.length + 1); : (power_user.allow_name1_display ? '' : name1); // user
}
// account for case where the name is after a newline if (wrongName) {
let startIndex = getMessage.indexOf(`\n${nameToTrim}:`); // If the message starts with the wrong name, delete the entire response
if (nameToTrim && startIndex >= 0) { let startIndex = getMessage.indexOf(`${wrongName}`);
getMessage = getMessage.substring(startIndex + nameToTrim.length + 2); if (startIndex === 0) {
getMessage = '';
console.debug(`Message started with the wrong name: "${wrongName}" - response was deleted.`);
}
// If there is trailing text starting with the wrong name, trim it off.
startIndex = getMessage.indexOf(`\n${wrongName}:`);
if (startIndex >= 0) {
getMessage = getMessage.substring(0, startIndex);
}
// remove any whitespace at the beginning
getMessage = getMessage.trimStart();
} }
getMessage.trimStart();
} }
if (getMessage.indexOf('<|endoftext|>') != -1) { if (getMessage.indexOf('<|endoftext|>') != -1) {
@@ -6102,9 +6112,12 @@ export function cleanUpMessage({ getMessage, isImpersonate, isContinue, displayI
} }
if (trimNames) { if (trimNames) {
// If this is an impersonation, trim "{{user}}:" from the beginning
// If this isn't an impersonation, trim "{{char}}:" from the beginning.
// Only applied when the corresponding "power_user.allow_nameX_display" is false.
const nameToTrim2 = isImpersonate const nameToTrim2 = isImpersonate
? (!power_user.allow_name1_display ? name1 : '') ? (!power_user.allow_name1_display ? name1 : '') // user
: (!power_user.allow_name2_display ? name2 : ''); : (!power_user.allow_name2_display ? name2 : ''); // char
if (nameToTrim2 && getMessage.startsWith(nameToTrim2 + ':')) { if (nameToTrim2 && getMessage.startsWith(nameToTrim2 + ':')) {
getMessage = getMessage.replace(nameToTrim2 + ':', ''); getMessage = getMessage.replace(nameToTrim2 + ':', '');