Replace macros in DRY sequence breakers

9215dfd0c6d74e2b15cba11e5a64796c42e34146

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

1 files changed, +29 -1Showing whitespace changes
public/scripts/textgen-settings.js+29 -1
@@ -1064,6 +1064,34 @@ function getLogprobsNumber() {
1064 return 10;1064 return 10;
1065}1065}
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 */
1072function 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
1067export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate, isContinue, cfgValues, type) {1095export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate, isContinue, cfgValues, type) {
1068 const canMultiSwipe = !isContinue && !isImpersonate && type !== 'quiet';1096 const canMultiSwipe = !isContinue && !isImpersonate && type !== 'quiet';
1069 const dynatemp = isDynamicTemperatureSupported();1097 const dynatemp = isDynamicTemperatureSupported();
@@ -1103,7 +1131,7 @@ export function getTextGenGenerationData(finalPrompt, maxTokens, isImpersonate,
1103 'dry_allowed_length': settings.dry_allowed_length,1131 'dry_allowed_length': settings.dry_allowed_length,
1104 'dry_multiplier': settings.dry_multiplier,1132 'dry_multiplier': settings.dry_multiplier,
1105 'dry_base': settings.dry_base,1133 'dry_base': settings.dry_base,
1106 'dry_sequence_breakers': settings.dry_sequence_breakers,1134 'dry_sequence_breakers': replaceMacrosInList(settings.dry_sequence_breakers),
1107 'dry_penalty_last_n': settings.dry_penalty_last_n,1135 'dry_penalty_last_n': settings.dry_penalty_last_n,
1108 'max_tokens_second': settings.max_tokens_second,1136 'max_tokens_second': settings.max_tokens_second,
1109 'sampler_priority': settings.type === OOBA ? settings.sampler_priority : undefined,1137 'sampler_priority': settings.type === OOBA ? settings.sampler_priority : undefined,