mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'staging' into support-multiple-expressions
This commit is contained in:
@ -253,6 +253,15 @@ let power_user = {
|
||||
content: 'Write {{char}}\'s next reply in a fictional chat between {{char}} and {{user}}.',
|
||||
},
|
||||
|
||||
reasoning: {
|
||||
auto_parse: false,
|
||||
add_to_prompts: false,
|
||||
prefix: '<think>\n',
|
||||
suffix: '\n</think>',
|
||||
separator: '\n\n',
|
||||
max_additions: 1,
|
||||
},
|
||||
|
||||
personas: {},
|
||||
default_persona: null,
|
||||
persona_descriptions: {},
|
||||
@ -2909,6 +2918,46 @@ export function flushEphemeralStoppingStrings() {
|
||||
EPHEMERAL_STOPPING_STRINGS.splice(0, EPHEMERAL_STOPPING_STRINGS.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the generated text should be filtered based on the auto-swipe settings.
|
||||
* @param {string} text The text to check
|
||||
* @returns {boolean} If the generated text should be filtered
|
||||
*/
|
||||
export function generatedTextFiltered(text) {
|
||||
/**
|
||||
* Checks if the given text contains any of the blacklisted words.
|
||||
* @param {string} text The text to check
|
||||
* @param {string[]} blacklist The list of blacklisted words
|
||||
* @param {number} threshold The number of blacklisted words that need to be present to trigger the check
|
||||
* @returns {boolean} Whether the text contains blacklisted words
|
||||
*/
|
||||
function containsBlacklistedWords(text, blacklist, threshold) {
|
||||
const regex = new RegExp(`\\b(${blacklist.join('|')})\\b`, 'gi');
|
||||
const matches = text.match(regex) || [];
|
||||
return matches.length >= threshold;
|
||||
}
|
||||
|
||||
// Make sure a generated text is non-empty
|
||||
// Otherwise we might get in a loop with a broken API
|
||||
text = text.trim();
|
||||
if (text.length > 0) {
|
||||
if (power_user.auto_swipe_minimum_length) {
|
||||
if (text.length < power_user.auto_swipe_minimum_length) {
|
||||
console.log('Generated text size too small');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (power_user.auto_swipe_blacklist.length && power_user.auto_swipe_blacklist_threshold) {
|
||||
if (containsBlacklistedWords(text, power_user.auto_swipe_blacklist, power_user.auto_swipe_blacklist_threshold)) {
|
||||
console.log('Generated text has blacklisted words');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the custom stopping strings from the power user settings.
|
||||
* @param {number | undefined} limit Number of strings to return. If 0 or undefined, returns all strings.
|
||||
@ -3880,9 +3929,9 @@ $(document).ready(() => {
|
||||
helpString: 'Start a new chat with a random character. If an argument is provided, only considers characters that have the specified tag.',
|
||||
}));
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||
name: 'delmode',
|
||||
name: 'del',
|
||||
callback: doDelMode,
|
||||
aliases: ['del'],
|
||||
aliases: ['delete', 'delmode'],
|
||||
unnamedArgumentList: [
|
||||
new SlashCommandArgument(
|
||||
'optional number', [ARGUMENT_TYPE.NUMBER], false,
|
||||
@ -4065,4 +4114,45 @@ $(document).ready(() => {
|
||||
],
|
||||
helpString: 'activates a movingUI preset by name',
|
||||
}));
|
||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||
name: 'stop-strings',
|
||||
aliases: ['stopping-strings', 'custom-stopping-strings', 'custom-stop-strings'],
|
||||
helpString: `
|
||||
<div>
|
||||
Sets a list of custom stopping strings. Gets the list if no value is provided.
|
||||
</div>
|
||||
<div>
|
||||
<strong>Examples:</strong>
|
||||
</div>
|
||||
<ul>
|
||||
<li>Value must be a JSON-serialized array: <pre><code class="language-stscript">/stop-strings ["goodbye", "farewell"]</code></pre></li>
|
||||
<li>Pipe characters must be escaped with a backslash: <pre><code class="language-stscript">/stop-strings ["left\\|right"]</code></pre></li>
|
||||
</ul>
|
||||
`,
|
||||
returns: ARGUMENT_TYPE.LIST,
|
||||
unnamedArgumentList: [
|
||||
SlashCommandArgument.fromProps({
|
||||
description: 'list of strings',
|
||||
typeList: [ARGUMENT_TYPE.LIST],
|
||||
acceptsMultiple: false,
|
||||
isRequired: false,
|
||||
}),
|
||||
],
|
||||
callback: (_, value) => {
|
||||
if (String(value ?? '').trim()) {
|
||||
const parsedValue = ((x) => { try { return JSON.parse(x.toString()); } catch { return null; } })(value);
|
||||
if (!parsedValue || !Array.isArray(parsedValue)) {
|
||||
throw new Error('Invalid list format. The value must be a JSON-serialized array of strings.');
|
||||
}
|
||||
parsedValue.forEach((item, index) => {
|
||||
parsedValue[index] = String(item);
|
||||
});
|
||||
power_user.custom_stopping_strings = JSON.stringify(parsedValue);
|
||||
$('#custom_stopping_strings').val(power_user.custom_stopping_strings);
|
||||
saveSettingsDebounced();
|
||||
}
|
||||
|
||||
return power_user.custom_stopping_strings;
|
||||
},
|
||||
}));
|
||||
});
|
||||
|
Reference in New Issue
Block a user