Replace multigen with auto-continue

This commit is contained in:
Cohee
2023-09-15 21:34:41 +03:00
parent eaca6ddaf0
commit d34f7d3e1a
8 changed files with 120 additions and 241 deletions

View File

@ -75,9 +75,6 @@
"always_force_name2": true, "always_force_name2": true,
"user_prompt_bias": "", "user_prompt_bias": "",
"show_user_prompt_bias": true, "show_user_prompt_bias": true,
"multigen": false,
"multigen_first_chunk": 50,
"multigen_next_chunks": 30,
"markdown_escape_strings": "", "markdown_escape_strings": "",
"fast_ui_mode": false, "fast_ui_mode": false,
"avatar_style": 0, "avatar_style": 0,

View File

@ -158,9 +158,6 @@
"Disabled for all models": "对所有模型禁用", "Disabled for all models": "对所有模型禁用",
"Automatic (based on model name)": "自动(基于型号名称)", "Automatic (based on model name)": "自动(基于型号名称)",
"Enabled for all models": "所有模型启用", "Enabled for all models": "所有模型启用",
"Multigen": "Multigen",
"First chunk (tokens)": "第一个区块Tokens",
"Next chunks (tokens)": "接下来的区块Tokens",
"Anchors Order": "锚点顺序", "Anchors Order": "锚点顺序",
"Character then Style": "字符然后样式", "Character then Style": "字符然后样式",
"Style then Character": "样式然后字符", "Style then Character": "样式然后字符",
@ -710,9 +707,6 @@
"Disabled for all models": "すべてのモデルで無効", "Disabled for all models": "すべてのモデルで無効",
"Automatic (based on model name)": "自動(モデル名に基づく)", "Automatic (based on model name)": "自動(モデル名に基づく)",
"Enabled for all models": "すべてのモデルで有効", "Enabled for all models": "すべてのモデルで有効",
"Multigen": "マルチジェン",
"First chunk (tokens)": "最初のチャンク(トークン)",
"Next chunks (tokens)": "次のチャンク(トークン)",
"Anchors Order": "アンカーオーダー", "Anchors Order": "アンカーオーダー",
"Character then Style": "キャラクター、次にスタイル", "Character then Style": "キャラクター、次にスタイル",
"Style then Character": "スタイル、次にキャラクター", "Style then Character": "スタイル、次にキャラクター",
@ -1264,9 +1258,6 @@
"Disabled for all models": "모든 모델에 비활성화", "Disabled for all models": "모든 모델에 비활성화",
"Automatic (based on model name)": "모델 서식 자동탐지", "Automatic (based on model name)": "모델 서식 자동탐지",
"Enabled for all models": "모든 모델에 활성화", "Enabled for all models": "모든 모델에 활성화",
"Multigen": "다수답변 생성",
"First chunk (tokens)": "첫 말뭉치(토큰수)",
"Next chunks (tokens)": "다음 말뭉치(토큰수)",
"Anchors Order": "Anchors Order", "Anchors Order": "Anchors Order",
"Character then Style": "캐릭터 다음 스타일", "Character then Style": "캐릭터 다음 스타일",
"Style then Character": "스타일 다음 캐릭터", "Style then Character": "스타일 다음 캐릭터",
@ -1873,9 +1864,6 @@
"Disabled for all models": "Выключено для всех моделей", "Disabled for all models": "Выключено для всех моделей",
"Automatic (based on model name)": "Автоматически (выбор по названию модели)", "Automatic (based on model name)": "Автоматически (выбор по названию модели)",
"Enabled for all models": "Включить для всех моделей", "Enabled for all models": "Включить для всех моделей",
"Multigen": "Мултиген",
"First chunk (tokens)": "Первый отрезок (в токенах)",
"Next chunks (tokens)": "Следующий отрезок (в токенах)",
"Anchors Order": "Порядок Anchors", "Anchors Order": "Порядок Anchors",
"Character then Style": "Персонаж после Стиля", "Character then Style": "Персонаж после Стиля",
"Style then Character": "Стиль после Персонажа", "Style then Character": "Стиль после Персонажа",
@ -2450,9 +2438,6 @@
"Disabled for all models": "Disabilita per tutti i modelli", "Disabled for all models": "Disabilita per tutti i modelli",
"Automatic (based on model name)": "Automatico (basato sul nome del modello)", "Automatic (based on model name)": "Automatico (basato sul nome del modello)",
"Enabled for all models": "Abilita per tutti i modelli", "Enabled for all models": "Abilita per tutti i modelli",
"Multigen": "Multigen",
"First chunk (tokens)": "Primo pacchetto in Token",
"Next chunks (tokens)": "Pacchetto successivo in Token",
"Anchors Order": "Anchors Order", "Anchors Order": "Anchors Order",
"Character then Style": "Prima il personaggio, successivamente lo stile", "Character then Style": "Prima il personaggio, successivamente lo stile",
"Style then Character": "Prima lo stile, successivamente il personaggio", "Style then Character": "Prima lo stile, successivamente il personaggio",
@ -3128,9 +3113,6 @@
"Disabled for all models": "Uitgeschakeld voor alle modellen", "Disabled for all models": "Uitgeschakeld voor alle modellen",
"Automatic (based on model name)": "Automatisch (op basis van modelnaam)", "Automatic (based on model name)": "Automatisch (op basis van modelnaam)",
"Enabled for all models": "Ingeschakeld voor alle modellen", "Enabled for all models": "Ingeschakeld voor alle modellen",
"Multigen": "Multigen",
"First chunk (tokens)": "Eerste stuk (tokens)",
"Next chunks (tokens)": "Volgende stukken (tokens)",
"Anchors Order": "Ankersvolgorde", "Anchors Order": "Ankersvolgorde",
"Character then Style": "Personage dan Stijl", "Character then Style": "Personage dan Stijl",
"Style then Character": "Stijl dan Personage", "Style then Character": "Stijl dan Personage",

View File

@ -2474,25 +2474,27 @@
</div> </div>
<div data-newbie-hidden> <div data-newbie-hidden>
<h4> <h4>
<span data-i18n="Multigen">Multigen</span> <span data-i18n="Auto-Continue">Auto-Continue</span>
<a href="https://docs.sillytavern.app/usage/core-concepts/advancedformatting/#multigen" class="notes-link" target="_blank">
<span class="note-link-span">?</span>
</a>
</h4> </h4>
<label class="checkbox_label" for="multigen"> <div class="flex-container">
<input id="multigen" type="checkbox" /> <label class="checkbox_label" for="auto_continue_enabled">
<input id="auto_continue_enabled" type="checkbox" />
<span data-i18n="Enabled"> <span data-i18n="Enabled">
Enabled Enabled
</span> </span>
</label> </label>
<div class="multigen_settings_block"> <label class="checkbox_label" for="auto_continue_allow_chat_completions">
<label for="multigen_1st_chunk"> <input id="auto_continue_allow_chat_completions" type="checkbox" />
<small><span data-i18n="First chunk (tokens)">First chunk (tokens)</span></small> <span data-i18n="Allow for Chat Completion APIs">
<input id="multigen_first_chunk" type="number" class="text_pole textarea_compact" min="1" max="512" /> Allow for Chat Completion APIs
</span>
</label> </label>
<label for="multigen_next_chunk"> </div>
<small><span data-i18n="Next chunks (tokens)">Next chunks (tokens)</span></small>
<input id="multigen_next_chunks" type="number" class="text_pole textarea_compact" min="1" max="512" /> <div class="auto_continue_settings_block">
<label for="auto_continue_target_length">
<span data-i18n="Target length (tokens)">Target length (tokens)</span>
<input id="auto_continue_target_length" type="number" class="text_pole textarea_compact" min="0" max="1024" />
</label> </label>
</div> </div>
</div> </div>

View File

@ -287,7 +287,7 @@ export const event_types = {
USER_MESSAGE_RENDERED: 'user_message_rendered', USER_MESSAGE_RENDERED: 'user_message_rendered',
CHARACTER_MESSAGE_RENDERED: 'character_message_rendered', CHARACTER_MESSAGE_RENDERED: 'character_message_rendered',
FORCE_SET_BACKGROUND: 'force_set_background', FORCE_SET_BACKGROUND: 'force_set_background',
CHAT_DELETED : 'chat_deleted', CHAT_DELETED: 'chat_deleted',
GROUP_CHAT_DELETED: 'group_chat_deleted', GROUP_CHAT_DELETED: 'group_chat_deleted',
} }
@ -662,9 +662,7 @@ export let user_avatar = "you.png";
export var amount_gen = 80; //default max length of AI generated responses export var amount_gen = 80; //default max length of AI generated responses
var max_context = 2048; var max_context = 2048;
var tokens_already_generated = 0;
var message_already_generated = ""; var message_already_generated = "";
var cycle_count_generation = 0;
var swipes = true; var swipes = true;
let extension_prompts = {}; let extension_prompts = {};
@ -1158,7 +1156,7 @@ function showMoreMessages() {
console.debug('Inserting messages before', messageId, 'count', count, 'chat length', chat.length); console.debug('Inserting messages before', messageId, 'count', count, 'chat length', chat.length);
const prevHeight = $('#chat').prop('scrollHeight'); const prevHeight = $('#chat').prop('scrollHeight');
while(messageId > 0 && count > 0) { while (messageId > 0 && count > 0) {
count--; count--;
messageId--; messageId--;
addOneMessage(chat[messageId], { insertBefore: messageId + 1, scroll: false, forceId: messageId }); addOneMessage(chat[messageId], { insertBefore: messageId + 1, scroll: false, forceId: messageId });
@ -2060,8 +2058,7 @@ function isStreamingEnabled() {
return ((main_api == 'openai' && oai_settings.stream_openai && oai_settings.chat_completion_source !== chat_completion_sources.SCALE && oai_settings.chat_completion_source !== chat_completion_sources.AI21) return ((main_api == 'openai' && oai_settings.stream_openai && oai_settings.chat_completion_source !== chat_completion_sources.SCALE && oai_settings.chat_completion_source !== chat_completion_sources.AI21)
|| (main_api == 'kobold' && kai_settings.streaming_kobold && kai_flags.can_use_streaming) || (main_api == 'kobold' && kai_settings.streaming_kobold && kai_flags.can_use_streaming)
|| (main_api == 'novel' && nai_settings.streaming_novel) || (main_api == 'novel' && nai_settings.streaming_novel)
|| (main_api == 'textgenerationwebui' && textgenerationwebui_settings.streaming)) || (main_api == 'textgenerationwebui' && textgenerationwebui_settings.streaming));
&& !isMultigenEnabled(); // Multigen has a quasi-streaming mode which breaks the real streaming
} }
function showStopButton() { function showStopButton() {
@ -2311,7 +2308,6 @@ class StreamingProcessor {
async function Generate(type, { automatic_trigger, force_name2, resolve, reject, quiet_prompt, force_chid, signal } = {}, dryRun = false) { async function Generate(type, { automatic_trigger, force_name2, resolve, reject, quiet_prompt, force_chid, signal } = {}, dryRun = false) {
//console.log('Generate entered'); //console.log('Generate entered');
setGenerationProgress(0); setGenerationProgress(0);
tokens_already_generated = 0;
generation_started = new Date(); generation_started = new Date();
// Don't recreate abort controller if signal is passed // Don't recreate abort controller if signal is passed
@ -2324,17 +2320,6 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
const isImpersonate = type == "impersonate"; const isImpersonate = type == "impersonate";
message_already_generated = isImpersonate ? `${name1}: ` : `${name2}: `; message_already_generated = isImpersonate ? `${name1}: ` : `${name2}: `;
// Name for the multigen prefix
const magName = isImpersonate ? name1 : name2;
if (isInstruct) {
message_already_generated = formatInstructModePrompt(magName, isImpersonate, '', name1, name2);
} else {
message_already_generated = `${magName}: `;
}
// To trim after multigen ended
const magFirst = message_already_generated;
const interruptedByCommand = processCommands($("#send_textarea").val(), type); const interruptedByCommand = processCommands($("#send_textarea").val(), type);
@ -2356,12 +2341,6 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
return; return;
} }
if (main_api == 'kobold' && kai_settings.streaming_kobold && power_user.multigen) {
toastr.error('Multigen is not supported with Kobold streaming enabled. Disable streaming in "AI Response Configuration" or multigen in "Advanced Formatting" to proceed.', undefined, { timeOut: 10000, preventDuplicates: true, });
is_send_press = false;
return;
}
if (isHordeGenerationNotAllowed()) { if (isHordeGenerationNotAllowed()) {
is_send_press = false; is_send_press = false;
return; return;
@ -2605,7 +2584,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
const storyString = renderStoryString(storyStringParams); const storyString = renderStoryString(storyStringParams);
if (main_api === 'openai') { if (main_api === 'openai') {
message_already_generated = ''; // OpenAI doesn't have multigen message_already_generated = '';
setOpenAIMessages(coreChat); setOpenAIMessages(coreChat);
setOpenAIMessageExamples(mesExamplesArray); setOpenAIMessageExamples(mesExamplesArray);
} }
@ -2699,10 +2678,8 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
// Save reply does add cycle text to the prompt, so it's not needed here // Save reply does add cycle text to the prompt, so it's not needed here
streamingProcessor && (streamingProcessor.firstMessageText = ''); streamingProcessor && (streamingProcessor.firstMessageText = '');
message_already_generated = continue_mag; message_already_generated = continue_mag;
tokens_already_generated = 1; // Multigen copium
} }
// Multigen rewrites the type and I don't know why
const originalType = type; const originalType = type;
runGenerate(cyclePrompt); runGenerate(cyclePrompt);
@ -2761,13 +2738,13 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
} }
// Get instruct mode line // Get instruct mode line
if (isInstruct && tokens_already_generated === 0) { if (isInstruct && !isContinue) {
const name = isImpersonate ? name1 : name2; const name = isImpersonate ? name1 : name2;
lastMesString += formatInstructModePrompt(name, isImpersonate, promptBias, name1, name2); lastMesString += formatInstructModePrompt(name, isImpersonate, promptBias, name1, name2);
} }
// Get non-instruct impersonation line // Get non-instruct impersonation line
if (!isInstruct && isImpersonate && tokens_already_generated === 0) { if (!isInstruct && isImpersonate && !isContinue) {
const name = name1; const name = name1;
if (!lastMesString.endsWith('\n')) { if (!lastMesString.endsWith('\n')) {
lastMesString += '\n'; lastMesString += '\n';
@ -2777,7 +2754,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
// Add character's name // Add character's name
// Force name append on continue // Force name append on continue
if (!isInstruct && force_name2 && (tokens_already_generated === 0 || isContinue)) { if (!isInstruct && force_name2) {
if (!lastMesString.endsWith('\n')) { if (!lastMesString.endsWith('\n')) {
lastMesString += '\n'; lastMesString += '\n';
} }
@ -2890,15 +2867,13 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
}); });
// TODO: Move zero-depth anchor append to work like CFG and bias appends // TODO: Move zero-depth anchor append to work like CFG and bias appends
if (zeroDepthAnchor && zeroDepthAnchor.length) { if (zeroDepthAnchor?.length && !isContinue) {
if (!isMultigenEnabled() || tokens_already_generated == 0) {
console.log(/\s/.test(finalMesSend[finalMesSend.length - 1].message.slice(-1))) console.log(/\s/.test(finalMesSend[finalMesSend.length - 1].message.slice(-1)))
finalMesSend[finalMesSend.length - 1].message += finalMesSend[finalMesSend.length - 1].message +=
/\s/.test(finalMesSend[finalMesSend.length - 1].message.slice(-1)) /\s/.test(finalMesSend[finalMesSend.length - 1].message.slice(-1))
? zeroDepthAnchor ? zeroDepthAnchor
: `${zeroDepthAnchor}`; : `${zeroDepthAnchor}`;
} }
}
let cfgPrompt = {}; let cfgPrompt = {};
if (cfgGuidanceScale && cfgGuidanceScale?.value !== 1) { if (cfgGuidanceScale && cfgGuidanceScale?.value !== 1) {
@ -2919,7 +2894,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
// Add prompt bias after everything else // Add prompt bias after everything else
// Always run with continue // Always run with continue
if (!isInstruct && !isImpersonate && (tokens_already_generated === 0 || isContinue)) { if (!isInstruct && !isImpersonate) {
if (promptBias.trim().length !== 0) { if (promptBias.trim().length !== 0) {
finalMesSend[finalMesSend.length - 1].message += finalMesSend[finalMesSend.length - 1].message +=
/\s/.test(finalMesSend[finalMesSend.length - 1].message.slice(-1)) /\s/.test(finalMesSend[finalMesSend.length - 1].message.slice(-1))
@ -2968,11 +2943,6 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
let this_amount_gen = Number(amount_gen); // how many tokens the AI will be requested to generate let this_amount_gen = Number(amount_gen); // how many tokens the AI will be requested to generate
let this_settings = koboldai_settings[koboldai_setting_names[preset_settings]]; let this_settings = koboldai_settings[koboldai_setting_names[preset_settings]];
if (isMultigenEnabled() && type !== 'quiet') {
// if nothing has been generated yet..
this_amount_gen = getMultigenAmount();
}
let thisPromptBits = []; let thisPromptBits = [];
// TODO: Make this a switch // TODO: Make this a switch
@ -3123,6 +3093,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
if (isStreamingEnabled() && type !== 'quiet') { if (isStreamingEnabled() && type !== 'quiet') {
hideSwipeButtons(); hideSwipeButtons();
let getMessage = await streamingProcessor.generate(); let getMessage = await streamingProcessor.generate();
let messageChunk = extractNameFromMessage(cleanUpMessage(getMessage, isImpersonate, isContinue, false), force_name2, isImpersonate).getMessage;
if (isContinue) { if (isContinue) {
getMessage = continue_mag + getMessage; getMessage = continue_mag + getMessage;
@ -3131,10 +3102,13 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
if (streamingProcessor && !streamingProcessor.isStopped && streamingProcessor.isFinished) { if (streamingProcessor && !streamingProcessor.isStopped && streamingProcessor.isFinished) {
await streamingProcessor.onFinishStreaming(streamingProcessor.messageId, getMessage); await streamingProcessor.onFinishStreaming(streamingProcessor.messageId, getMessage);
streamingProcessor = null; streamingProcessor = null;
triggerAutoContinue(messageChunk, isImpersonate);
} }
} }
async function onSuccess(data) { async function onSuccess(data) {
let messageChunk = '';
if (data.error == 'dryRun') { if (data.error == 'dryRun') {
generatedPromptCache = ''; generatedPromptCache = '';
resolve(); resolve();
@ -3147,49 +3121,6 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
let title = extractTitleFromData(data); let title = extractTitleFromData(data);
kobold_horde_model = title; kobold_horde_model = title;
// to make it continue generating so long as it's under max_amount and hasn't signaled
// an end to the character's response via typing "You:" or adding "<endoftext>"
if (isMultigenEnabled() && type !== 'quiet') {
message_already_generated += getMessage;
promptBias = '';
let this_mes_is_name;
({ this_mes_is_name, getMessage } = extractNameFromMessage(getMessage, force_name2, isImpersonate));
if (!isImpersonate) {
if (tokens_already_generated == 0) {
console.debug("New message");
({ type, getMessage } = await saveReply(type, getMessage, this_mes_is_name, title));
}
else {
console.debug("Should append message");
({ type, getMessage } = await saveReply('append', getMessage, this_mes_is_name, title));
}
} else {
let chunk = cleanUpMessage(message_already_generated, true, isContinue, true);
let extract = extractNameFromMessage(chunk, force_name2, isImpersonate);
$('#send_textarea').val(extract.getMessage).trigger('input');
}
if (shouldContinueMultigen(getMessage, isImpersonate, isInstruct)) {
hideSwipeButtons();
tokens_already_generated += this_amount_gen; // add new gen amt to any prev gen counter..
getMessage = message_already_generated;
// if any tokens left to generate
if (getMultigenAmount() > 0) {
runGenerate(getMessage);
console.debug('returning to make generate again');
return;
}
}
tokens_already_generated = 0;
generatedPromptCache = "";
const substringStart = originalType !== 'continue' ? magFirst.length : 0;
getMessage = message_already_generated.substring(substringStart);
}
if (isContinue) { if (isContinue) {
getMessage = continue_mag + getMessage; getMessage = continue_mag + getMessage;
} }
@ -3210,8 +3141,8 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
resolve(getMessage); resolve(getMessage);
} }
else { else {
// Without streaming we'll be having a full message on continuation. Treat it as a multigen last chunk. // Without streaming we'll be having a full message on continuation. Treat it as a last chunk.
if (!isMultigenEnabled() && originalType !== 'continue') { if (originalType !== 'continue') {
({ type, getMessage } = await saveReply(type, getMessage, this_mes_is_name, title)); ({ type, getMessage } = await saveReply(type, getMessage, this_mes_is_name, title));
} }
else { else {
@ -3265,6 +3196,8 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
return return
} }
} }
messageChunk = getMessage;
} else { } else {
generatedPromptCache = ''; generatedPromptCache = '';
activateSendButtons(); activateSendButtons();
@ -3290,6 +3223,8 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
if (type !== 'quiet') { if (type !== 'quiet') {
resolve(); resolve();
} }
triggerAutoContinue(messageChunk, isImpersonate);
}; };
function onError(exception) { function onError(exception) {
@ -3320,6 +3255,55 @@ function getNextMessageId(type) {
return type == 'swipe' ? Number(count_view_mes - 1) : Number(count_view_mes); return type == 'swipe' ? Number(count_view_mes - 1) : Number(count_view_mes);
} }
/**
*
* @param {string} messageChunk
* @param {boolean} isImpersonate
* @returns {void}
*/
export function triggerAutoContinue(messageChunk, isImpersonate) {
if (selected_group) {
console.debug('Auto-continue is disabled for group chat');
return;
}
if (power_user.auto_continue.enabled && !is_send_press) {
if (power_user.auto_continue.target_length <= 0) {
console.debug('Auto-continue target length is 0, not triggering auto-continue');
return;
}
if (main_api === 'openai' && !power_user.auto_continue.allow_chat_completions){
console.debug('Auto-continue for OpenAI is disabled by user.');
return;
}
if (isImpersonate) {
console.debug('Continue for impersonation is not implemented yet');
return;
}
const USABLE_LENGTH = 5;
if (messageChunk.trim().length > USABLE_LENGTH && chat.length) {
const lastMessage = chat[chat.length - 1];
const messageLength = getTokenCount(lastMessage.mes);
const shouldAutoContinue = messageLength < power_user.auto_continue.target_length;
if (shouldAutoContinue) {
console.debug(`Triggering auto-continue. Message tokens: ${messageLength}. Target tokens: ${power_user.auto_continue.target_length}`);
$("#option_continue").trigger('click');
} else {
console.debug(`Not triggering auto-continue. Message tokens: ${messageLength}. Target tokens: ${power_user.auto_continue.target_length}`);
return;
}
} else {
console.debug('Last generated chunk was empty, not triggering auto-continue');
return;
}
}
}
export function getBiasStrings(textareaText, type) { export function getBiasStrings(textareaText, type) {
if (type == 'impersonate' || type == 'continue') { if (type == 'impersonate' || type == 'continue') {
return { messageBias: '', promptBias: '', isUserPromptBias: false }; return { messageBias: '', promptBias: '', isUserPromptBias: false };
@ -3497,35 +3481,6 @@ function appendZeroDepthAnchor(force_name2, zeroDepthAnchor, finalPrompt) {
return finalPrompt; return finalPrompt;
} }
function getMultigenAmount() {
let this_amount_gen = Number(amount_gen);
if (tokens_already_generated === 0) {
// if the max gen setting is > 50...(
if (Number(amount_gen) >= power_user.multigen_first_chunk) {
// then only try to make 50 this cycle..
this_amount_gen = power_user.multigen_first_chunk;
}
else {
// otherwise, make as much as the max amount request.
this_amount_gen = Number(amount_gen);
}
}
// if we already received some generated text...
else {
// if the remaining tokens to be made is less than next potential cycle count
if (Number(amount_gen) - tokens_already_generated < power_user.multigen_next_chunks) {
// subtract already generated amount from the desired max gen amount
this_amount_gen = Number(amount_gen) - tokens_already_generated;
}
else {
// otherwise make the standard cycle amount (first 50, and 30 after that)
this_amount_gen = power_user.multigen_next_chunks;
}
}
return this_amount_gen;
}
async function DupeChar() { async function DupeChar() {
if (!this_chid) { if (!this_chid) {
toastr.warning('You must first select a character to duplicate!') toastr.warning('You must first select a character to duplicate!')
@ -3749,26 +3704,6 @@ function getGenerateUrl() {
return generate_url; return generate_url;
} }
function shouldContinueMultigen(getMessage, isImpersonate, isInstruct) {
if (isInstruct && power_user.instruct.stop_sequence) {
if (message_already_generated.indexOf(power_user.instruct.stop_sequence) !== -1) {
return false;
}
}
// stopping name string
const nameString = isImpersonate ? `${name2}:` : `${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 < Number(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) {
const nameToTrim = isImpersonate ? name1 : name2; const nameToTrim = isImpersonate ? name1 : name2;
let this_mes_is_name = true; let this_mes_is_name = true;
@ -3866,7 +3801,7 @@ function cleanUpMessage(getMessage, isImpersonate, isContinue, displayIncomplete
if (nameToTrim && getMessage.indexOf(`${nameToTrim}:`) == 0) { if (nameToTrim && getMessage.indexOf(`${nameToTrim}:`) == 0) {
getMessage = getMessage.substr(0, getMessage.indexOf(`${nameToTrim}:`)); getMessage = getMessage.substr(0, getMessage.indexOf(`${nameToTrim}:`));
} }
if (nameToTrim && getMessage.indexOf(`\n${nameToTrim}:`) > 0) { if (nameToTrim && getMessage.indexOf(`\n${nameToTrim}:`) >= 0) {
getMessage = getMessage.substr(0, getMessage.indexOf(`\n${nameToTrim}:`)); getMessage = getMessage.substr(0, getMessage.indexOf(`\n${nameToTrim}:`));
} }
if (getMessage.indexOf('<|endoftext|>') != -1) { if (getMessage.indexOf('<|endoftext|>') != -1) {
@ -4125,10 +4060,6 @@ function extractImageFromMessage(getMessage) {
return { getMessage, image, title }; return { getMessage, image, title };
} }
export function isMultigenEnabled() {
return power_user.multigen && (main_api == 'textgenerationwebui' || main_api == 'kobold' || main_api == 'koboldhorde' || main_api == 'novel');
}
export function activateSendButtons() { export function activateSendButtons() {
is_send_press = false; is_send_press = false;
$("#send_but").removeClass("displayNone"); $("#send_but").removeClass("displayNone");
@ -6563,13 +6494,6 @@ const swipe_right = () => {
return; return;
} }
// if (chat.length == 1) {
// if (chat[0]['swipe_id'] !== undefined && chat[0]['swipe_id'] == chat[0]['swipes'].length - 1) {
// toastr.info('Add more alternative greetings to swipe through', 'That\'s all for now');
// return;
// }
// }
const swipe_duration = 200; const swipe_duration = 200;
const swipe_range = 700; const swipe_range = 700;
//console.log(swipe_range); //console.log(swipe_range);

View File

@ -1,4 +1,4 @@
import { callPopup, cancelTtsPlay, eventSource, event_types, isMultigenEnabled, is_send_press, saveSettingsDebounced } from '../../../script.js' import { callPopup, cancelTtsPlay, eventSource, event_types, 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 { escapeRegex, getStringHash } from '../../utils.js' import { escapeRegex, getStringHash } from '../../utils.js'
import { EdgeTtsProvider } from './edge.js' import { EdgeTtsProvider } from './edge.js'
@ -117,11 +117,6 @@ async function moduleWorker() {
return return
} }
// Multigen message is currently being generated
if (is_send_press && isMultigenEnabled()) {
return;
}
// Chat changed // Chat changed
if ( if (
context.chatId !== lastChatId context.chatId !== lastChatId

View File

@ -51,7 +51,6 @@ import {
menu_type, menu_type,
select_selected_character, select_selected_character,
cancelTtsPlay, cancelTtsPlay,
isMultigenEnabled,
displayPastChats, displayPastChats,
sendMessageAsUser, sendMessageAsUser,
getBiasStrings, getBiasStrings,
@ -577,7 +576,7 @@ async function generateGroupWrapper(by_auto_mode, type = null, params = {}) {
await Generate(generateType, { automatic_trigger: by_auto_mode, ...(params || {}) }); await Generate(generateType, { automatic_trigger: by_auto_mode, ...(params || {}) });
if (type !== "swipe" && type !== "impersonate" && !isMultigenEnabled() && !isStreamingEnabled()) { if (type !== "swipe" && type !== "impersonate" && !isStreamingEnabled()) {
// update indicator and scroll down // update indicator and scroll down
typingIndicator typingIndicator
.find(".typing_indicator_name") .find(".typing_indicator_name")
@ -593,7 +592,7 @@ async function generateGroupWrapper(by_auto_mode, type = null, params = {}) {
} }
// if not swipe - check if message generated already // if not swipe - check if message generated already
if (generateType === "group_chat" && !isMultigenEnabled() && chat.length == messagesBefore) { if (generateType === "group_chat" && chat.length == messagesBefore) {
await delay(100); await delay(100);
} }
// if swipe - see if message changed // if swipe - see if message changed
@ -606,13 +605,6 @@ async function generateGroupWrapper(by_auto_mode, type = null, params = {}) {
break; break;
} }
} }
else if (isMultigenEnabled()) {
if (isGenerationDone) {
break;
} else {
await delay(100);
}
}
else { else {
if (lastMessageText === chat[chat.length - 1].mes) { if (lastMessageText === chat[chat.length - 1].mes) {
await delay(100); await delay(100);
@ -631,13 +623,6 @@ async function generateGroupWrapper(by_auto_mode, type = null, params = {}) {
break; break;
} }
} }
else if (isMultigenEnabled()) {
if (isGenerationDone) {
break;
} else {
await delay(100);
}
}
else { else {
if (!$("#send_textarea").val() || $("#send_textarea").val() == userInput) { if (!$("#send_textarea").val() || $("#send_textarea").val() == userInput) {
await delay(100); await delay(100);
@ -654,14 +639,6 @@ async function generateGroupWrapper(by_auto_mode, type = null, params = {}) {
await delay(100); await delay(100);
} }
} }
else if (isMultigenEnabled()) {
if (isGenerationDone) {
messagesBefore++;
break;
} else {
await delay(100);
}
}
else if (isStreamingEnabled()) { else if (isStreamingEnabled()) {
if (streamingProcessor && !streamingProcessor.isFinished) { if (streamingProcessor && !streamingProcessor.isFinished) {
await delay(100); await delay(100);

View File

@ -93,9 +93,11 @@ let power_user = {
always_force_name2: false, always_force_name2: false,
user_prompt_bias: '', user_prompt_bias: '',
show_user_prompt_bias: true, show_user_prompt_bias: true,
multigen: false, auto_continue: {
multigen_first_chunk: 50, enabled: false,
multigen_next_chunks: 30, allow_chat_completions: false,
target_length: 400,
},
markdown_escape_strings: '', markdown_escape_strings: '',
ui_mode: ui_mode.POWER, ui_mode: ui_mode.POWER,
@ -848,9 +850,9 @@ function loadPowerUserSettings(settings, data) {
$("#noShadowsmode").prop("checked", power_user.noShadows); $("#noShadowsmode").prop("checked", power_user.noShadows);
$("#start_reply_with").val(power_user.user_prompt_bias); $("#start_reply_with").val(power_user.user_prompt_bias);
$("#chat-show-reply-prefix-checkbox").prop("checked", power_user.show_user_prompt_bias); $("#chat-show-reply-prefix-checkbox").prop("checked", power_user.show_user_prompt_bias);
$("#multigen").prop("checked", power_user.multigen); $("#auto_continue_enabled").prop("checked", power_user.auto_continue.enabled);
$("#multigen_first_chunk").val(power_user.multigen_first_chunk); $("#auto_continue_allow_chat_completions").prop("checked", power_user.auto_continue.allow_chat_completions);
$("#multigen_next_chunks").val(power_user.multigen_next_chunks); $("#auto_continue_target_length").val(power_user.auto_continue.target_length);
$("#play_message_sound").prop("checked", power_user.play_message_sound); $("#play_message_sound").prop("checked", power_user.play_message_sound);
$("#play_sound_unfocused").prop("checked", power_user.play_sound_unfocused); $("#play_sound_unfocused").prop("checked", power_user.play_sound_unfocused);
$("#never_resize_avatars").prop("checked", power_user.never_resize_avatars); $("#never_resize_avatars").prop("checked", power_user.never_resize_avatars);
@ -1816,8 +1818,18 @@ $(document).ready(() => {
saveSettingsDebounced(); saveSettingsDebounced();
}) })
$("#multigen").change(function () { $("#auto_continue_enabled").on('change', function () {
power_user.multigen = $(this).prop("checked"); power_user.auto_continue.enabled = $(this).prop("checked");
saveSettingsDebounced();
});
$("#auto_continue_allow_chat_completions").on('change', function () {
power_user.auto_continue.allow_chat_completions = !!$(this).prop('checked');
saveSettingsDebounced();
});
$("#auto_continue_target_length").on('input', function () {
power_user.auto_continue.target_length = Number($(this).val());
saveSettingsDebounced(); saveSettingsDebounced();
}); });
@ -1986,16 +1998,6 @@ $(document).ready(() => {
saveSettingsDebounced(); saveSettingsDebounced();
}); });
$("#multigen_first_chunk").on('input', function () {
power_user.multigen_first_chunk = Number($(this).val());
saveSettingsDebounced();
});
$("#multigen_next_chunks").on('input', function () {
power_user.multigen_next_chunks = Number($(this).val());
saveSettingsDebounced();
});
$('#auto_swipe').on('input', function () { $('#auto_swipe').on('input', function () {
power_user.auto_swipe = !!$(this).prop('checked'); power_user.auto_swipe = !!$(this).prop('checked');
saveSettingsDebounced(); saveSettingsDebounced();

View File

@ -2436,18 +2436,18 @@ input[type="range"]::-webkit-slider-thumb {
#anchor_checkbox label, #anchor_checkbox label,
#power-user-option-checkboxes label, #power-user-option-checkboxes label,
.checkbox_label, .checkbox_label,
.multigen_settings_block { .auto_continue_settings_block {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
column-gap: 5px; column-gap: 5px;
align-items: center; align-items: center;
} }
.multigen_settings_block { .auto_continue_settings_block {
margin-top: 10px; margin-top: 10px;
} }
.multigen_settings_block label { .auto_continue_settings_block label {
flex: 1; flex: 1;
display: flex; display: flex;
flex-direction: column; flex-direction: column;