mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'staging' into qr-rewrite
This commit is contained in:
@@ -4274,6 +4274,7 @@
|
|||||||
<small class="textAlignCenter">Logic</small>
|
<small class="textAlignCenter">Logic</small>
|
||||||
<select name="entryLogicType" class="widthFitContent margin0">
|
<select name="entryLogicType" class="widthFitContent margin0">
|
||||||
<option value="0">AND ANY</option>
|
<option value="0">AND ANY</option>
|
||||||
|
<option value="3">AND ALL</option>
|
||||||
<option value="1">NOT ALL</option>
|
<option value="1">NOT ALL</option>
|
||||||
<option value="2">NOT ANY</option>
|
<option value="2">NOT ANY</option>
|
||||||
</select>
|
</select>
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { callPopup, cancelTtsPlay, eventSource, event_types, name2, saveSettingsDebounced } from '../../../script.js';
|
import { callPopup, cancelTtsPlay, eventSource, event_types, name2, saveSettingsDebounced } from '../../../script.js';
|
||||||
import { ModuleWorkerWrapper, doExtrasFetch, extension_settings, getApiUrl, getContext, modules } from '../../extensions.js';
|
import { ModuleWorkerWrapper, doExtrasFetch, extension_settings, getApiUrl, getContext, modules } from '../../extensions.js';
|
||||||
import { delay, escapeRegex, getStringHash } from '../../utils.js';
|
import { delay, escapeRegex, getStringHash, onlyUnique } from '../../utils.js';
|
||||||
import { EdgeTtsProvider } from './edge.js';
|
import { EdgeTtsProvider } from './edge.js';
|
||||||
import { ElevenLabsTtsProvider } from './elevenlabs.js';
|
import { ElevenLabsTtsProvider } from './elevenlabs.js';
|
||||||
import { SileroTtsProvider } from './silerotts.js';
|
import { SileroTtsProvider } from './silerotts.js';
|
||||||
@@ -463,13 +463,25 @@ function saveLastValues() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function tts(text, voiceId, char) {
|
async function tts(text, voiceId, char) {
|
||||||
let response = await ttsProvider.generateTts(text, voiceId);
|
async function processResponse(response) {
|
||||||
|
|
||||||
// RVC injection
|
// RVC injection
|
||||||
if (extension_settings.rvc.enabled && typeof window['rvcVoiceConversion'] === 'function')
|
if (extension_settings.rvc.enabled && typeof window['rvcVoiceConversion'] === 'function')
|
||||||
response = await window['rvcVoiceConversion'](response, char, text);
|
response = await window['rvcVoiceConversion'](response, char, text);
|
||||||
|
|
||||||
addAudioJob(response);
|
await addAudioJob(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
let response = await ttsProvider.generateTts(text, voiceId);
|
||||||
|
|
||||||
|
// If async generator, process every chunk as it comes in
|
||||||
|
if (typeof response[Symbol.asyncIterator] === 'function') {
|
||||||
|
for await (const chunk of response) {
|
||||||
|
await processResponse(chunk);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await processResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
completeTtsJob();
|
completeTtsJob();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -733,7 +745,7 @@ function getCharacters(unrestricted) {
|
|||||||
if (unrestricted) {
|
if (unrestricted) {
|
||||||
const names = context.characters.map(char => char.name);
|
const names = context.characters.map(char => char.name);
|
||||||
names.unshift(DEFAULT_VOICE_MARKER);
|
names.unshift(DEFAULT_VOICE_MARKER);
|
||||||
return names;
|
return names.filter(onlyUnique);
|
||||||
}
|
}
|
||||||
|
|
||||||
let characters = [];
|
let characters = [];
|
||||||
@@ -748,14 +760,13 @@ function getCharacters(unrestricted) {
|
|||||||
characters.push(context.name1);
|
characters.push(context.name1);
|
||||||
const group = context.groups.find(group => context.groupId == group.id);
|
const group = context.groups.find(group => context.groupId == group.id);
|
||||||
for (let member of group.members) {
|
for (let member of group.members) {
|
||||||
// Remove suffix
|
const character = context.characters.find(char => char.avatar == member);
|
||||||
if (member.endsWith('.png')) {
|
if (character) {
|
||||||
member = member.slice(0, -4);
|
characters.push(character.name);
|
||||||
}
|
|
||||||
characters.push(member);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return characters;
|
}
|
||||||
|
return characters.filter(onlyUnique);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sanitizeId(input) {
|
function sanitizeId(input) {
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import { getRequestHeaders, callPopup } from '../../../script.js';
|
import { getRequestHeaders, callPopup } from '../../../script.js';
|
||||||
|
import { splitRecursive } from '../../utils.js';
|
||||||
import { getPreviewString, saveTtsProviderSettings } from './index.js';
|
import { getPreviewString, saveTtsProviderSettings } from './index.js';
|
||||||
import { initVoiceMap } from './index.js';
|
import { initVoiceMap } from './index.js';
|
||||||
|
|
||||||
@@ -52,7 +53,7 @@ class NovelTtsProvider {
|
|||||||
|
|
||||||
|
|
||||||
// Add a new Novel custom voice to provider
|
// Add a new Novel custom voice to provider
|
||||||
async addCustomVoice(){
|
async addCustomVoice() {
|
||||||
const voiceName = await callPopup('<h3>Custom Voice name:</h3>', 'input');
|
const voiceName = await callPopup('<h3>Custom Voice name:</h3>', 'input');
|
||||||
this.settings.customVoices.push(voiceName);
|
this.settings.customVoices.push(voiceName);
|
||||||
this.populateCustomVoices();
|
this.populateCustomVoices();
|
||||||
@@ -74,7 +75,7 @@ class NovelTtsProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the UI dropdown list of voices in provider
|
// Create the UI dropdown list of voices in provider
|
||||||
populateCustomVoices(){
|
populateCustomVoices() {
|
||||||
let voiceSelect = $('#tts-novel-custom-voices-select');
|
let voiceSelect = $('#tts-novel-custom-voices-select');
|
||||||
voiceSelect.empty();
|
voiceSelect.empty();
|
||||||
this.settings.customVoices.forEach(voice => {
|
this.settings.customVoices.forEach(voice => {
|
||||||
@@ -88,7 +89,7 @@ class NovelTtsProvider {
|
|||||||
console.info('Using default TTS Provider settings');
|
console.info('Using default TTS Provider settings');
|
||||||
}
|
}
|
||||||
$('#tts-novel-custom-voices-add').on('click', () => (this.addCustomVoice()));
|
$('#tts-novel-custom-voices-add').on('click', () => (this.addCustomVoice()));
|
||||||
$('#tts-novel-custom-voices-delete').on('click',() => (this.deleteCustomVoice()));
|
$('#tts-novel-custom-voices-delete').on('click', () => (this.deleteCustomVoice()));
|
||||||
|
|
||||||
// Only accept keys defined in defaultSettings
|
// Only accept keys defined in defaultSettings
|
||||||
this.settings = this.defaultSettings;
|
this.settings = this.defaultSettings;
|
||||||
@@ -108,7 +109,7 @@ class NovelTtsProvider {
|
|||||||
|
|
||||||
// Perform a simple readiness check by trying to fetch voiceIds
|
// Perform a simple readiness check by trying to fetch voiceIds
|
||||||
// Doesnt really do much for Novel, not seeing a good way to test this at the moment.
|
// Doesnt really do much for Novel, not seeing a good way to test this at the moment.
|
||||||
async checkReady(){
|
async checkReady() {
|
||||||
await this.fetchTtsVoiceObjects();
|
await this.fetchTtsVoiceObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,14 +180,17 @@ class NovelTtsProvider {
|
|||||||
this.audioElement.play();
|
this.audioElement.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchTtsGeneration(inputText, voiceId) {
|
async* fetchTtsGeneration(inputText, voiceId) {
|
||||||
|
const MAX_LENGTH = 1000;
|
||||||
console.info(`Generating new TTS for voice_id ${voiceId}`);
|
console.info(`Generating new TTS for voice_id ${voiceId}`);
|
||||||
|
const chunks = splitRecursive(inputText, MAX_LENGTH);
|
||||||
|
for (const chunk of chunks) {
|
||||||
const response = await fetch('/api/novelai/generate-voice',
|
const response = await fetch('/api/novelai/generate-voice',
|
||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: getRequestHeaders(),
|
headers: getRequestHeaders(),
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
'text': inputText,
|
'text': chunk,
|
||||||
'voice': voiceId,
|
'voice': voiceId,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
@@ -195,6 +199,7 @@ class NovelTtsProvider {
|
|||||||
toastr.error(response.statusText, 'TTS Generation Failed');
|
toastr.error(response.statusText, 'TTS Generation Failed');
|
||||||
throw new Error(`HTTP ${response.status}: ${await response.text()}`);
|
throw new Error(`HTTP ${response.status}: ${await response.text()}`);
|
||||||
}
|
}
|
||||||
return response;
|
yield response;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -39,6 +39,7 @@ const world_info_logic = {
|
|||||||
AND_ANY: 0,
|
AND_ANY: 0,
|
||||||
NOT_ALL: 1,
|
NOT_ALL: 1,
|
||||||
NOT_ANY: 2,
|
NOT_ANY: 2,
|
||||||
|
AND_ALL: 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
let world_info = {};
|
let world_info = {};
|
||||||
@@ -1789,6 +1790,7 @@ async function checkWorldInfo(chat, maxContext) {
|
|||||||
) {
|
) {
|
||||||
console.debug(`WI UID:${entry.uid} found. Checking logic: ${entry.selectiveLogic}`);
|
console.debug(`WI UID:${entry.uid} found. Checking logic: ${entry.selectiveLogic}`);
|
||||||
let hasAnyMatch = false;
|
let hasAnyMatch = false;
|
||||||
|
let hasAllMatch = true;
|
||||||
secondary: for (let keysecondary of entry.keysecondary) {
|
secondary: for (let keysecondary of entry.keysecondary) {
|
||||||
const secondarySubstituted = substituteParams(keysecondary);
|
const secondarySubstituted = substituteParams(keysecondary);
|
||||||
const hasSecondaryMatch = secondarySubstituted && matchKeys(textToScan, secondarySubstituted.trim());
|
const hasSecondaryMatch = secondarySubstituted && matchKeys(textToScan, secondarySubstituted.trim());
|
||||||
@@ -1798,6 +1800,10 @@ async function checkWorldInfo(chat, maxContext) {
|
|||||||
hasAnyMatch = true;
|
hasAnyMatch = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!hasSecondaryMatch) {
|
||||||
|
hasAllMatch = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Simplified AND ANY / NOT ALL if statement. (Proper fix for PR#1356 by Bronya)
|
// Simplified AND ANY / NOT ALL if statement. (Proper fix for PR#1356 by Bronya)
|
||||||
// If AND ANY logic and the main checks pass OR if NOT ALL logic and the main checks do not pass
|
// If AND ANY logic and the main checks pass OR if NOT ALL logic and the main checks do not pass
|
||||||
if ((selectiveLogic === world_info_logic.AND_ANY && hasSecondaryMatch) || (selectiveLogic === world_info_logic.NOT_ALL && !hasSecondaryMatch)) {
|
if ((selectiveLogic === world_info_logic.AND_ANY && hasSecondaryMatch) || (selectiveLogic === world_info_logic.NOT_ALL && !hasSecondaryMatch)) {
|
||||||
@@ -1817,6 +1823,12 @@ async function checkWorldInfo(chat, maxContext) {
|
|||||||
console.debug(`(NOT ANY Check) Activating WI Entry ${entry.uid}, no secondary keywords found.`);
|
console.debug(`(NOT ANY Check) Activating WI Entry ${entry.uid}, no secondary keywords found.`);
|
||||||
activatedNow.add(entry);
|
activatedNow.add(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle AND ALL logic
|
||||||
|
if (selectiveLogic === world_info_logic.AND_ALL && hasAllMatch) {
|
||||||
|
console.debug(`(AND ALL Check) Activating WI Entry ${entry.uid}, all secondary keywords found.`);
|
||||||
|
activatedNow.add(entry);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Handle cases where secondary is empty
|
// Handle cases where secondary is empty
|
||||||
console.debug(`WI UID ${entry.uid}: Activated without filter logic.`);
|
console.debug(`WI UID ${entry.uid}: Activated without filter logic.`);
|
||||||
|
@@ -342,7 +342,9 @@ router.post('/generate-voice', jsonParser, async (request, response) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
return response.sendStatus(result.status);
|
const errorText = await result.text();
|
||||||
|
console.log('NovelAI returned an error.', result.statusText, errorText);
|
||||||
|
return response.sendStatus(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
const chunks = await readAllChunks(result.body);
|
const chunks = await readAllChunks(result.body);
|
||||||
|
Reference in New Issue
Block a user