Merge branch 'staging' of https://github.com/Cohee1207/SillyTavern into staging
This commit is contained in:
commit
2befd69c31
|
@ -20,6 +20,7 @@ import {
|
|||
isMancer,
|
||||
isAphrodite,
|
||||
textgen_types,
|
||||
textgenerationwebui_banned_in_macros,
|
||||
} from "./scripts/textgen-settings.js";
|
||||
|
||||
import {
|
||||
|
@ -1757,9 +1758,37 @@ function substituteParams(content, _name1, _name2, _original, _group) {
|
|||
});
|
||||
content = randomReplace(content);
|
||||
content = diceRollReplace(content);
|
||||
content = bannedWordsReplace(content);
|
||||
return content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces banned words in macros with an empty string.
|
||||
* Adds them to textgenerationwebui ban list.
|
||||
* @param {string} inText Text to replace banned words in
|
||||
* @returns {string} Text without the "banned" macro
|
||||
*/
|
||||
function bannedWordsReplace(inText) {
|
||||
if (!inText) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const banPattern = /{{banned "(.*)"}}/gi;
|
||||
|
||||
if (main_api == 'textgenerationwebui') {
|
||||
const bans = inText.matchAll(banPattern);
|
||||
if (bans) {
|
||||
for (const banCase of bans) {
|
||||
console.log("Found banned words in macros: " + banCase[1]);
|
||||
textgenerationwebui_banned_in_macros.push(banCase[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inText = inText.replaceAll(banPattern, "");
|
||||
return inText;
|
||||
}
|
||||
|
||||
function getTimeSinceLastMessage() {
|
||||
const now = moment();
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ System-wide Replacement Macros:
|
|||
<li><tt>{{time}}</tt> - the current time</li>
|
||||
<li><tt>{{date}}</tt> - the current date</li>
|
||||
<li><tt>{{bias "text here"}}</tt> - sets a behavioral bias for the AI until the next user input. Quotes around the text are important.</li>
|
||||
<li><tt>{{banned "text here"}}</tt> - dynamically add text in the quotes to banned words sequences, if Text Generation WebUI backend used. Do nothing for others backends. Can be used anywhere (Character description, WI, AN, etc.) Quotes around the text are important.</li>
|
||||
<li><tt>{{idle_duration}}</tt> - the time since the last user message was sent</li>
|
||||
<li><tt>{{random:(args)}}</tt> - returns a random item from the list. (ex: {{random:1,2,3,4}} will return 1 of the 4 numbers at random. Works with text lists too.</li>
|
||||
<li><tt>{{roll:(formula)}}</tt> - rolls a dice. (ex: {{roll:1d6}} will roll a 6-sided dice and return a number between 1 and 6)</li>
|
||||
|
|
|
@ -65,6 +65,8 @@ const textgenerationwebui_settings = {
|
|||
type: textgen_types.OOBA,
|
||||
};
|
||||
|
||||
export let textgenerationwebui_banned_in_macros = [];
|
||||
|
||||
export let textgenerationwebui_presets = [];
|
||||
export let textgenerationwebui_preset_names = [];
|
||||
|
||||
|
@ -136,19 +138,31 @@ function formatTextGenURL(value, use_mancer) {
|
|||
}
|
||||
|
||||
function convertPresets(presets) {
|
||||
return Array.isArray(presets) ? presets.map(JSON.parse) : [];
|
||||
return Array.isArray(presets) ? presets.map((p) => JSON.parse(p)) : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string} String with comma-separated banned token IDs
|
||||
*/
|
||||
function getCustomTokenBans() {
|
||||
if (!textgenerationwebui_settings.banned_tokens) {
|
||||
if (!textgenerationwebui_settings.banned_tokens && !textgenerationwebui_banned_in_macros.length) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const sequences = textgenerationwebui_settings.banned_tokens.split('\n');
|
||||
const result = [];
|
||||
const sequences = textgenerationwebui_settings.banned_tokens
|
||||
.split('\n')
|
||||
.concat(textgenerationwebui_banned_in_macros)
|
||||
.filter(x => x.length > 0)
|
||||
.filter(onlyUnique);
|
||||
|
||||
//debug
|
||||
if (textgenerationwebui_banned_in_macros.length) {
|
||||
console.log("=== Found banned word sequences in the macros:", textgenerationwebui_banned_in_macros, "Resulting array of banned sequences (will be used this generation turn):", sequences);
|
||||
}
|
||||
|
||||
//clean old temporary bans found in macros before, for the next generation turn.
|
||||
textgenerationwebui_banned_in_macros = [];
|
||||
|
||||
for (const line of sequences) {
|
||||
// Raw token ids, JSON serialized
|
||||
|
@ -309,7 +323,7 @@ async function generateTextGenWithStreaming(generate_data, signal) {
|
|||
streamingUrl = api_server_textgenerationwebui.replace("http", "ws") + "/v1/stream";
|
||||
}
|
||||
|
||||
if (isAphrodite()){
|
||||
if (isAphrodite()) {
|
||||
streamingUrl = api_server_textgenerationwebui;
|
||||
}
|
||||
|
||||
|
@ -342,7 +356,7 @@ async function generateTextGenWithStreaming(generate_data, signal) {
|
|||
|
||||
try {
|
||||
const { results } = JSON.parse(event);
|
||||
|
||||
|
||||
if (Array.isArray(results) && results.length > 0) {
|
||||
getMessage = results[0].text;
|
||||
yield getMessage;
|
||||
|
@ -361,11 +375,11 @@ async function generateTextGenWithStreaming(generate_data, signal) {
|
|||
} else {
|
||||
|
||||
getMessage += response;
|
||||
|
||||
|
||||
if (done) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
yield getMessage;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue