Replace macros in DRY sequence breakers

9215dfd0c6d74e2b15cba11e5a64796c42e34146

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +29 -1Ignore whitespace
public/scripts/textgen-settings.js+29 -1
@@ -1064,6 +1064,34 @@ function getLogprobsNumber() {
10641064 return 10;
10651065}
10661066
1067+/**
1068+ * Replaces {{macro}} in a comma-separated or serialized JSON array string.
1069+ * @param {string} str Input string
1070+ * @returns {string} Output string
1071+ */
1072+function replaceMacrosInList(str) {
1073+ if (!str || typeof str !== 'string') {
1074+ return str;
1075+ }
1076+
1077+ try {
1078+ const array = JSON.parse(str);
1079+ if (!Array.isArray(array)) {
1080+ throw new Error('Not an array');
1081+ }
1082+ for (let i = 0; i < array.length; i++) {
1083+ array[i] = substituteParams(array[i]);
1084+ }
1085+ return JSON.stringify(array);
1086+ } catch {
1087+ const array = str.split(',');
1088+ for (let i = 0; i < array.length; i++) {
1089+ array[i] = substituteParams(array[i]);
1090+ }
1091+ return array.join(',');
1092+ }
1093+}
1094+
10671095export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate, isContinue, cfgValues, type) {
10681096 const canMultiSwipe = !isContinue && !isImpersonate && type !== 'quiet';
10691097 const dynatemp = isDynamicTemperatureSupported();
@@ -1103,7 +1131,7 @@ export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate,
11031131 'dry_allowed_length': settings.dry_allowed_length,
11041132 'dry_multiplier': settings.dry_multiplier,
11051133 'dry_base': settings.dry_base,
11061134 'dry_sequence_breakers': replaceMacrosInList(settings.dry_sequence_breakers),
11071135 'dry_penalty_last_n': settings.dry_penalty_last_n,
11081136 'max_tokens_second': settings.max_tokens_second,
11091137 'sampler_priority': settings.type === OOBA ? settings.sampler_priority : undefined,