Disallow multiple {{original}} macro substitutions

This commit is contained in:
Cohee 2024-01-29 00:58:29 +02:00
parent a9464daffa
commit 5f1e290bda
2 changed files with 10 additions and 3 deletions

View File

@ -2147,7 +2147,15 @@ function substituteParams(content, _name1, _name2, _original, _group, _replaceCh
const environment = {};
if (typeof _original === 'string') {
environment.original = _original;
let originalSubstituted = false;
environment.original = () => {
if (originalSubstituted) {
return '';
}
originalSubstituted = true;
return _original;
};
}
if (_replaceCharacterCard) {

View File

@ -221,8 +221,7 @@ export function evaluateMacros(content, env) {
if (!Object.hasOwn(env, varName)) continue;
const param = env[varName];
const paramValue = typeof param === 'function' ? param() : param;
content = content.replace(new RegExp(`{{${varName}}}`, 'gi'), paramValue);
content = content.replace(new RegExp(`{{${varName}}}`, 'gi'), param);
}
content = content.replace(/{{maxPrompt}}/gi, () => String(getMaxContextSize()));