mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Fix macros replacement in custom stop strings for OAI
This commit is contained in:
@ -1616,7 +1616,7 @@ function setAvgBG() {
|
||||
|
||||
/**
|
||||
* Gets the custom stopping strings from the power user settings.
|
||||
* @param {number | undefined} limit Number of strings to return. If undefined, returns all strings.
|
||||
* @param {number | undefined} limit Number of strings to return. If 0 or undefined, returns all strings.
|
||||
* @returns {string[]} An array of custom stopping strings
|
||||
*/
|
||||
export function getCustomStoppingStrings(limit = undefined) {
|
||||
@ -1627,15 +1627,27 @@ export function getCustomStoppingStrings(limit = undefined) {
|
||||
}
|
||||
|
||||
// Parse the JSON string
|
||||
const strings = JSON.parse(power_user.custom_stopping_strings);
|
||||
let strings = JSON.parse(power_user.custom_stopping_strings);
|
||||
|
||||
// Make sure it's an array
|
||||
if (!Array.isArray(strings)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Make sure all the elements are strings. Apply the limit.
|
||||
return strings.filter((s) => typeof s === 'string').slice(0, limit);
|
||||
// Make sure all the elements are strings.
|
||||
strings = strings.filter((s) => typeof s === 'string');
|
||||
|
||||
// Substitute params if necessary
|
||||
if (power_user.custom_stopping_strings_macro) {
|
||||
strings = strings.map(x => substituteParams(x));
|
||||
}
|
||||
|
||||
// Apply the limit. If limit is 0, return all strings.
|
||||
if (limit > 0) {
|
||||
strings = strings.slice(0, limit);
|
||||
}
|
||||
|
||||
return strings;
|
||||
} catch (error) {
|
||||
// If there's an error, return an empty array
|
||||
console.warn('Error parsing custom stopping strings:', error);
|
||||
|
Reference in New Issue
Block a user