mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
#300 Fix multigen issues:
1. Not working with instruct mode 2. Not working with impersonation 3. Not working with real streaming
This commit is contained in:
@ -1369,7 +1369,7 @@ function getExtensionPrompt(position = 0, depth = undefined, separator = "\n") {
|
|||||||
|
|
||||||
function baseChatReplace(value, name1, name2) {
|
function baseChatReplace(value, name1, name2) {
|
||||||
if (value !== undefined && value.length > 0) {
|
if (value !== undefined && value.length > 0) {
|
||||||
value = substituteParams(value, is_pygmalion ? "You:" : name1, name2);
|
value = substituteParams(value, is_pygmalion ? "You" : name1, name2);
|
||||||
|
|
||||||
if (power_user.collapse_newlines) {
|
if (power_user.collapse_newlines) {
|
||||||
value = collapseNewlines(value);
|
value = collapseNewlines(value);
|
||||||
@ -1386,9 +1386,10 @@ function appendToStoryString(value, prefix) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isStreamingEnabled() {
|
function isStreamingEnabled() {
|
||||||
return (main_api == 'openai' && oai_settings.stream_openai)
|
return ((main_api == 'openai' && oai_settings.stream_openai)
|
||||||
|| (main_api == 'poe' && poe_settings.streaming)
|
|| (main_api == 'poe' && poe_settings.streaming)
|
||||||
|| (main_api == 'textgenerationwebui' && textgenerationwebui_settings.streaming);
|
|| (main_api == 'textgenerationwebui' && textgenerationwebui_settings.streaming))
|
||||||
|
&& !isMultigenEnabled(); // Multigen has a quasi-streaming mode which breaks the real streaming
|
||||||
}
|
}
|
||||||
|
|
||||||
class StreamingProcessor {
|
class StreamingProcessor {
|
||||||
@ -1568,7 +1569,15 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
|
|
||||||
const isImpersonate = type == "impersonate";
|
const isImpersonate = type == "impersonate";
|
||||||
const isInstruct = power_user.instruct.enabled;
|
const isInstruct = power_user.instruct.enabled;
|
||||||
message_already_generated = isImpersonate ? `${name1}: ` : `${name2}: `;
|
|
||||||
|
// Name for the multigen prefix
|
||||||
|
const magName = isImpersonate ? (is_pygmalion ? 'You' : name1) : name2;
|
||||||
|
|
||||||
|
if (isInstruct) {
|
||||||
|
message_already_generated = formatInstructModePrompt(magName, isImpersonate);
|
||||||
|
} else {
|
||||||
|
message_already_generated = `${magName}: `;
|
||||||
|
}
|
||||||
|
|
||||||
const interruptedByCommand = processCommands($("#send_textarea").val(), type);
|
const interruptedByCommand = processCommands($("#send_textarea").val(), type);
|
||||||
|
|
||||||
@ -2270,11 +2279,14 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
hideSwipeButtons();
|
hideSwipeButtons();
|
||||||
let getMessage = await streamingProcessor.generate();
|
let getMessage = await streamingProcessor.generate();
|
||||||
|
|
||||||
|
// Cohee: Basically a dead-end code... (disabled by isStreamingEnabled)
|
||||||
|
// I wasn't able to get multigen working with real streaming
|
||||||
|
// consistently without screwing the interim prompting
|
||||||
if (isMultigenEnabled()) {
|
if (isMultigenEnabled()) {
|
||||||
tokens_already_generated += this_amount_gen; // add new gen amt to any prev gen counter..
|
tokens_already_generated += this_amount_gen;
|
||||||
message_already_generated += getMessage;
|
message_already_generated += getMessage;
|
||||||
promptBias = '';
|
promptBias = '';
|
||||||
if (!streamingProcessor.isStopped && shouldContinueMultigen(getMessage)) {
|
if (!streamingProcessor.isStopped && shouldContinueMultigen(getMessage, isImpersonate)) {
|
||||||
streamingProcessor.isFinished = false;
|
streamingProcessor.isFinished = false;
|
||||||
runGenerate(getMessage);
|
runGenerate(getMessage);
|
||||||
console.log('returning to make generate again');
|
console.log('returning to make generate again');
|
||||||
@ -2306,16 +2318,23 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
|
|
||||||
let this_mes_is_name;
|
let this_mes_is_name;
|
||||||
({ this_mes_is_name, getMessage } = extractNameFromMessage(getMessage, force_name2, isImpersonate));
|
({ this_mes_is_name, getMessage } = extractNameFromMessage(getMessage, force_name2, isImpersonate));
|
||||||
if (tokens_already_generated == 0) {
|
|
||||||
console.log("New message");
|
if (!isImpersonate) {
|
||||||
({ type, getMessage } = saveReply(type, getMessage, this_mes_is_name, title));
|
if (tokens_already_generated == 0) {
|
||||||
}
|
console.log("New message");
|
||||||
else {
|
({ type, getMessage } = saveReply(type, getMessage, this_mes_is_name, title));
|
||||||
console.log("Should append message");
|
}
|
||||||
({ type, getMessage } = saveReply('append', getMessage, this_mes_is_name, title));
|
else {
|
||||||
|
console.log("Should append message");
|
||||||
|
({ type, getMessage } = saveReply('append', getMessage, this_mes_is_name, title));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let chunk = cleanUpMessage(message_already_generated, true);
|
||||||
|
let extract = extractNameFromMessage(chunk, force_name2, isImpersonate);
|
||||||
|
$('#send_textarea').val(extract.getMessage).trigger('input');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldContinueMultigen(getMessage)) {
|
if (shouldContinueMultigen(getMessage, isImpersonate)) {
|
||||||
hideSwipeButtons();
|
hideSwipeButtons();
|
||||||
tokens_already_generated += this_amount_gen; // add new gen amt to any prev gen counter..
|
tokens_already_generated += this_amount_gen; // add new gen amt to any prev gen counter..
|
||||||
getMessage = message_already_generated;
|
getMessage = message_already_generated;
|
||||||
@ -2335,6 +2354,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
if (getMessage.length > 0) {
|
if (getMessage.length > 0) {
|
||||||
if (isImpersonate) {
|
if (isImpersonate) {
|
||||||
$('#send_textarea').val(getMessage).trigger('input');
|
$('#send_textarea').val(getMessage).trigger('input');
|
||||||
|
generatedPromtCache = "";
|
||||||
}
|
}
|
||||||
else if (type == 'quiet') {
|
else if (type == 'quiet') {
|
||||||
resolve(getMessage);
|
resolve(getMessage);
|
||||||
@ -2483,12 +2503,24 @@ function getGenerateUrl() {
|
|||||||
return generate_url;
|
return generate_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
function shouldContinueMultigen(getMessage) {
|
function shouldContinueMultigen(getMessage, isImpersonate) {
|
||||||
const nameString = is_pygmalion ? 'You:' : `${name1}:`;
|
if (power_user.instruct.enabled && power_user.instruct.stop_sequence) {
|
||||||
return message_already_generated.indexOf(nameString) === -1 && //if there is no 'You:' in the response msg
|
if (message_already_generated.indexOf(power_user.instruct.stop_sequence) !== -1) {
|
||||||
message_already_generated.indexOf('<|endoftext|>') === -1 && //if there is no <endoftext> stamp in the response msg
|
return false;
|
||||||
tokens_already_generated < parseInt(amount_gen) && //if the gen'd msg is less than the max response length..
|
}
|
||||||
getMessage.length > 0; //if we actually have gen'd text at all...
|
}
|
||||||
|
|
||||||
|
// stopping name string
|
||||||
|
const nameString = isImpersonate ? `${name2}:` : (is_pygmalion ? 'You:' : `${name1}:`);
|
||||||
|
// if there is no 'You:' in the response msg
|
||||||
|
const doesNotContainName = message_already_generated.indexOf(nameString) === -1;
|
||||||
|
//if there is no <endoftext> stamp in the response msg
|
||||||
|
const isNotEndOfText = message_already_generated.indexOf('<|endoftext|>') === -1;
|
||||||
|
//if the gen'd msg is less than the max response length..
|
||||||
|
const notReachedMax = tokens_already_generated < parseInt(amount_gen);
|
||||||
|
//if we actually have gen'd text at all...
|
||||||
|
const msgHasText = getMessage.length > 0;
|
||||||
|
return doesNotContainName && isNotEndOfText && notReachedMax && msgHasText;
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractNameFromMessage(getMessage, force_name2, isImpersonate) {
|
function extractNameFromMessage(getMessage, force_name2, isImpersonate) {
|
||||||
@ -2604,6 +2636,12 @@ function cleanUpMessage(getMessage, isImpersonate) {
|
|||||||
getMessage = getMessage.substring(0, getMessage.indexOf(power_user.instruct.stop_sequence));
|
getMessage = getMessage.substring(0, getMessage.indexOf(power_user.instruct.stop_sequence));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (power_user.instruct.enabled && power_user.instruct.input_sequence && isImpersonate) {
|
||||||
|
getMessage = getMessage.replaceAll(power_user.instruct.input_sequence, '');
|
||||||
|
}
|
||||||
|
if (power_user.instruct.enabled && power_user.instruct.output_sequence && !isImpersonate) {
|
||||||
|
getMessage = getMessage.replaceAll(power_user.instruct.output_sequence, '');
|
||||||
|
}
|
||||||
// clean-up group message from excessive generations
|
// clean-up group message from excessive generations
|
||||||
if (selected_group) {
|
if (selected_group) {
|
||||||
getMessage = cleanGroupMessage(getMessage);
|
getMessage = cleanGroupMessage(getMessage);
|
||||||
|
@ -242,6 +242,12 @@ function processReply(str) {
|
|||||||
str = str.replace(/\s+/g, ' '); // Collapse multiple whitespaces into one
|
str = str.replace(/\s+/g, ' '); // Collapse multiple whitespaces into one
|
||||||
str = str.trim();
|
str = str.trim();
|
||||||
|
|
||||||
|
str = str
|
||||||
|
.split(',') // list split by commas
|
||||||
|
.map(x => x.trim()) // trim each entry
|
||||||
|
.filter(x => x) // remove empty entries
|
||||||
|
.join(', '); // join it back with proper spacing
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user