mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge pull request #1493 from valadaptive/generate-cleanups
Clean up Generate(), part 1
This commit is contained in:
@ -694,7 +694,6 @@ let abortController;
|
|||||||
//css
|
//css
|
||||||
var css_mes_bg = $('<div class="mes"></div>').css('background');
|
var css_mes_bg = $('<div class="mes"></div>').css('background');
|
||||||
var css_send_form_display = $('<div id=send_form></div>').css('display');
|
var css_send_form_display = $('<div id=send_form></div>').css('display');
|
||||||
let generate_loop_counter = 0;
|
|
||||||
const MAX_GENERATION_LOOPS = 5;
|
const MAX_GENERATION_LOOPS = 5;
|
||||||
|
|
||||||
var kobold_horde_model = '';
|
var kobold_horde_model = '';
|
||||||
@ -2316,26 +2315,8 @@ function getStoppingStrings(isImpersonate, isContinue) {
|
|||||||
*/
|
*/
|
||||||
export async function generateQuietPrompt(quiet_prompt, quietToLoud, skipWIAN, quietImage = null) {
|
export async function generateQuietPrompt(quiet_prompt, quietToLoud, skipWIAN, quietImage = null) {
|
||||||
console.log('got into genQuietPrompt');
|
console.log('got into genQuietPrompt');
|
||||||
return await new Promise(
|
const generateFinished = await Generate('quiet', { quiet_prompt, quietToLoud, skipWIAN: skipWIAN, force_name2: true, quietImage: quietImage });
|
||||||
async function promptPromise(resolve, reject) {
|
return generateFinished;
|
||||||
if (quietToLoud === true) {
|
|
||||||
try {
|
|
||||||
await Generate('quiet', { resolve, reject, quiet_prompt, quietToLoud: true, skipWIAN: skipWIAN, force_name2: true, quietImage: quietImage });
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
reject();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
try {
|
|
||||||
console.log('going to generate non-QuietToLoud');
|
|
||||||
await Generate('quiet', { resolve, reject, quiet_prompt, quietToLoud: false, skipWIAN: skipWIAN, force_name2: true, quietImage: quietImage });
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
reject();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processCommands(message, type, dryRun) {
|
async function processCommands(message, type, dryRun) {
|
||||||
@ -2915,7 +2896,8 @@ export async function generateRaw(prompt, api, instructOverride) {
|
|||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function Generate(type, { automatic_trigger, force_name2, resolve, reject, quiet_prompt, quietToLoud, skipWIAN, force_chid, signal, quietImage } = {}, dryRun = false) {
|
// Returns a promise that resolves when the text is done generating.
|
||||||
|
async function Generate(type, { automatic_trigger, force_name2, quiet_prompt, quietToLoud, skipWIAN, force_chid, signal, quietImage, maxLoops } = {}, dryRun = false) {
|
||||||
console.log('Generate entered');
|
console.log('Generate entered');
|
||||||
setGenerationProgress(0);
|
setGenerationProgress(0);
|
||||||
generation_started = new Date();
|
generation_started = new Date();
|
||||||
@ -2936,13 +2918,13 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
if (interruptedByCommand) {
|
if (interruptedByCommand) {
|
||||||
//$("#send_textarea").val('').trigger('input');
|
//$("#send_textarea").val('').trigger('input');
|
||||||
unblockGeneration();
|
unblockGeneration();
|
||||||
return;
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (main_api == 'kobold' && kai_settings.streaming_kobold && !kai_flags.can_use_streaming) {
|
if (main_api == 'kobold' && kai_settings.streaming_kobold && !kai_flags.can_use_streaming) {
|
||||||
toastr.error('Streaming is enabled, but the version of Kobold used does not support token streaming.', undefined, { timeOut: 10000, preventDuplicates: true });
|
toastr.error('Streaming is enabled, but the version of Kobold used does not support token streaming.', undefined, { timeOut: 10000, preventDuplicates: true });
|
||||||
unblockGeneration();
|
unblockGeneration();
|
||||||
return;
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (main_api === 'textgenerationwebui' &&
|
if (main_api === 'textgenerationwebui' &&
|
||||||
@ -2951,12 +2933,12 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
textgen_settings.type !== MANCER) {
|
textgen_settings.type !== MANCER) {
|
||||||
toastr.error('Streaming is not supported for the Legacy API. Update Ooba and use --extensions openai to enable streaming.', undefined, { timeOut: 10000, preventDuplicates: true });
|
toastr.error('Streaming is not supported for the Legacy API. Update Ooba and use --extensions openai to enable streaming.', undefined, { timeOut: 10000, preventDuplicates: true });
|
||||||
unblockGeneration();
|
unblockGeneration();
|
||||||
return;
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isHordeGenerationNotAllowed()) {
|
if (isHordeGenerationNotAllowed()) {
|
||||||
unblockGeneration();
|
unblockGeneration();
|
||||||
return;
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hide swipes if not in a dry run.
|
// Hide swipes if not in a dry run.
|
||||||
@ -2964,17 +2946,9 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
hideSwipeButtons();
|
hideSwipeButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set empty promise resolution functions
|
|
||||||
if (typeof resolve !== 'function') {
|
|
||||||
resolve = () => { };
|
|
||||||
}
|
|
||||||
if (typeof reject !== 'function') {
|
|
||||||
reject = () => { };
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selected_group && !is_group_generating && !dryRun) {
|
if (selected_group && !is_group_generating && !dryRun) {
|
||||||
generateGroupWrapper(false, type, { resolve, reject, quiet_prompt, force_chid, signal: abortController.signal, quietImage });
|
// Returns the promise that generateGroupWrapper returns; resolves when generation is done
|
||||||
return;
|
return generateGroupWrapper(false, type, { quiet_prompt, force_chid, signal: abortController.signal, quietImage, maxLoops });
|
||||||
} else if (selected_group && !is_group_generating && dryRun) {
|
} else if (selected_group && !is_group_generating && dryRun) {
|
||||||
const characterIndexMap = new Map(characters.map((char, index) => [char.avatar, index]));
|
const characterIndexMap = new Map(characters.map((char, index) => [char.avatar, index]));
|
||||||
const group = groups.find((x) => x.id === selected_group);
|
const group = groups.find((x) => x.id === selected_group);
|
||||||
@ -2996,7 +2970,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
} else {
|
} else {
|
||||||
console.log('No enabled members found');
|
console.log('No enabled members found');
|
||||||
unblockGeneration();
|
unblockGeneration();
|
||||||
return;
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3160,7 +3134,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
if (aborted) {
|
if (aborted) {
|
||||||
console.debug('Generation aborted by extension interceptors');
|
console.debug('Generation aborted by extension interceptors');
|
||||||
unblockGeneration();
|
unblockGeneration();
|
||||||
return;
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.debug('Skipping extension interceptors for dry run');
|
console.debug('Skipping extension interceptors for dry run');
|
||||||
@ -3215,7 +3189,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
unblockGeneration();
|
unblockGeneration();
|
||||||
return;
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
if (horde_settings.auto_adjust_context_length) {
|
if (horde_settings.auto_adjust_context_length) {
|
||||||
this_max_context = (adjustedParams.maxContextLength - adjustedParams.maxLength);
|
this_max_context = (adjustedParams.maxContextLength - adjustedParams.maxLength);
|
||||||
@ -3375,7 +3349,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
}
|
}
|
||||||
|
|
||||||
const originalType = type;
|
const originalType = type;
|
||||||
runGenerate(cyclePrompt);
|
return runGenerate(cyclePrompt);
|
||||||
|
|
||||||
async function runGenerate(cycleGenerationPrompt = '') {
|
async function runGenerate(cycleGenerationPrompt = '') {
|
||||||
if (!dryRun) {
|
if (!dryRun) {
|
||||||
@ -3723,6 +3697,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
if (true === dryRun) return onSuccess({ error: 'dryRun' });
|
if (true === dryRun) return onSuccess({ error: 'dryRun' });
|
||||||
|
|
||||||
if (power_user.console_log_prompts) {
|
if (power_user.console_log_prompts) {
|
||||||
@ -3895,20 +3870,26 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
if (type !== 'quiet') {
|
if (type !== 'quiet') {
|
||||||
playMessageSound();
|
playMessageSound();
|
||||||
}
|
}
|
||||||
|
|
||||||
generate_loop_counter = 0;
|
|
||||||
} else {
|
} else {
|
||||||
++generate_loop_counter;
|
// If maxLoops is not passed in (e.g. first time generating), set it to MAX_GENERATION_LOOPS
|
||||||
|
maxLoops ??= MAX_GENERATION_LOOPS;
|
||||||
|
|
||||||
if (generate_loop_counter > MAX_GENERATION_LOOPS) {
|
if (maxLoops === 0) {
|
||||||
|
reject(new Error('Generate circuit breaker interruption'));
|
||||||
|
if (type !== 'quiet') {
|
||||||
throwCircuitBreakerError();
|
throwCircuitBreakerError();
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// regenerate with character speech reenforced
|
// regenerate with character speech reenforced
|
||||||
// to make sure we leave on swipe type while also adding the name2 appendage
|
// to make sure we leave on swipe type while also adding the name2 appendage
|
||||||
setTimeout(() => {
|
delay(1000).then(async () => {
|
||||||
Generate(type, { automatic_trigger, force_name2: true, resolve, reject, quiet_prompt, skipWIAN, force_chid });
|
// The first await is for waiting for the generate to start. The second one is waiting for it to finish
|
||||||
}, generate_loop_counter * 1000);
|
const result = await await Generate(type, { automatic_trigger, force_name2: true, quiet_prompt, skipWIAN, force_chid, maxLoops: maxLoops - 1 });
|
||||||
|
resolve(result);
|
||||||
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (power_user.auto_swipe) {
|
if (power_user.auto_swipe) {
|
||||||
@ -3934,6 +3915,8 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
console.debug('swiping right automatically');
|
console.debug('swiping right automatically');
|
||||||
is_send_press = false;
|
is_send_press = false;
|
||||||
swipe_right();
|
swipe_right();
|
||||||
|
// TODO: do we want to resolve after an auto-swipe?
|
||||||
|
resolve();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3946,6 +3929,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
if (data?.response) {
|
if (data?.response) {
|
||||||
toastr.error(data.response, 'API Error');
|
toastr.error(data.response, 'API Error');
|
||||||
}
|
}
|
||||||
|
reject(data.response);
|
||||||
}
|
}
|
||||||
console.debug('/api/chats/save called by /Generate');
|
console.debug('/api/chats/save called by /Generate');
|
||||||
|
|
||||||
@ -3959,8 +3943,8 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
|
|
||||||
if (type !== 'quiet') {
|
if (type !== 'quiet') {
|
||||||
triggerAutoContinue(messageChunk, isImpersonate);
|
triggerAutoContinue(messageChunk, isImpersonate);
|
||||||
resolve();
|
|
||||||
}
|
}
|
||||||
|
resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
function onError(exception) {
|
function onError(exception) {
|
||||||
@ -3973,6 +3957,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
console.log(exception);
|
console.log(exception);
|
||||||
streamingProcessor = null;
|
streamingProcessor = null;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
} //rungenerate ends
|
} //rungenerate ends
|
||||||
} else { //generate's primary loop ends, after this is error handling for no-connection or safety-id
|
} else { //generate's primary loop ends, after this is error handling for no-connection or safety-id
|
||||||
@ -4440,7 +4425,6 @@ function getGenerateUrl(api) {
|
|||||||
|
|
||||||
function throwCircuitBreakerError() {
|
function throwCircuitBreakerError() {
|
||||||
callPopup(`Could not extract reply in ${MAX_GENERATION_LOOPS} attempts. Try generating again`, 'text');
|
callPopup(`Could not extract reply in ${MAX_GENERATION_LOOPS} attempts. Try generating again`, 'text');
|
||||||
generate_loop_counter = 0;
|
|
||||||
unblockGeneration();
|
unblockGeneration();
|
||||||
throw new Error('Generate circuit breaker interruption');
|
throw new Error('Generate circuit breaker interruption');
|
||||||
}
|
}
|
||||||
|
@ -1781,7 +1781,14 @@ async function generateMultimodalPrompt(generationType, quietPrompt) {
|
|||||||
*/
|
*/
|
||||||
async function generatePrompt(quietPrompt) {
|
async function generatePrompt(quietPrompt) {
|
||||||
const reply = await generateQuietPrompt(quietPrompt, false, false);
|
const reply = await generateQuietPrompt(quietPrompt, false, false);
|
||||||
return processReply(reply);
|
const processedReply = processReply(reply);
|
||||||
|
|
||||||
|
if (!processedReply) {
|
||||||
|
toastr.error('Prompt generation produced no text. Make sure you\'re using a valid instruct template and try again', 'Image Generation');
|
||||||
|
throw new Error('Prompt generation failed.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return processedReply;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendGenerationRequest(generationType, prompt, characterName = null, callback) {
|
async function sendGenerationRequest(generationType, prompt, characterName = null, callback) {
|
||||||
|
@ -8,7 +8,6 @@ import {
|
|||||||
extractAllWords,
|
extractAllWords,
|
||||||
saveBase64AsFile,
|
saveBase64AsFile,
|
||||||
PAGINATION_TEMPLATE,
|
PAGINATION_TEMPLATE,
|
||||||
waitUntilCondition,
|
|
||||||
getBase64Async,
|
getBase64Async,
|
||||||
} from './utils.js';
|
} from './utils.js';
|
||||||
import { RA_CountCharTokens, humanizedDateTime, dragElement, favsToHotswap, getMessageTimeStamp } from './RossAscends-mods.js';
|
import { RA_CountCharTokens, humanizedDateTime, dragElement, favsToHotswap, getMessageTimeStamp } from './RossAscends-mods.js';
|
||||||
@ -46,7 +45,6 @@ import {
|
|||||||
updateChatMetadata,
|
updateChatMetadata,
|
||||||
isStreamingEnabled,
|
isStreamingEnabled,
|
||||||
getThumbnailUrl,
|
getThumbnailUrl,
|
||||||
streamingProcessor,
|
|
||||||
getRequestHeaders,
|
getRequestHeaders,
|
||||||
setMenuType,
|
setMenuType,
|
||||||
menu_type,
|
menu_type,
|
||||||
@ -612,14 +610,20 @@ function getGroupChatNames(groupId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function generateGroupWrapper(by_auto_mode, type = null, params = {}) {
|
async function generateGroupWrapper(by_auto_mode, type = null, params = {}) {
|
||||||
|
function throwIfAborted() {
|
||||||
|
if (params.signal instanceof AbortSignal && params.signal.aborted) {
|
||||||
|
throw new Error('AbortSignal was fired. Group generation stopped');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (online_status === 'no_connection') {
|
if (online_status === 'no_connection') {
|
||||||
is_group_generating = false;
|
is_group_generating = false;
|
||||||
setSendButtonState(false);
|
setSendButtonState(false);
|
||||||
return;
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_group_generating) {
|
if (is_group_generating) {
|
||||||
return false;
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto-navigate back to group menu
|
// Auto-navigate back to group menu
|
||||||
@ -630,13 +634,15 @@ async function generateGroupWrapper(by_auto_mode, type = null, params = {}) {
|
|||||||
|
|
||||||
const group = groups.find((x) => x.id === selected_group);
|
const group = groups.find((x) => x.id === selected_group);
|
||||||
let typingIndicator = $('#chat .typing_indicator');
|
let typingIndicator = $('#chat .typing_indicator');
|
||||||
|
let textResult = '';
|
||||||
|
|
||||||
if (!group || !Array.isArray(group.members) || !group.members.length) {
|
if (!group || !Array.isArray(group.members) || !group.members.length) {
|
||||||
sendSystemMessage(system_message_types.EMPTY, '', { isSmallSys: true });
|
sendSystemMessage(system_message_types.EMPTY, '', { isSmallSys: true });
|
||||||
return;
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
throwIfAborted();
|
||||||
hideSwipeButtons();
|
hideSwipeButtons();
|
||||||
is_group_generating = true;
|
is_group_generating = true;
|
||||||
setCharacterName('');
|
setCharacterName('');
|
||||||
@ -654,50 +660,18 @@ async function generateGroupWrapper(by_auto_mode, type = null, params = {}) {
|
|||||||
// id of this specific batch for regeneration purposes
|
// id of this specific batch for regeneration purposes
|
||||||
group_generation_id = Date.now();
|
group_generation_id = Date.now();
|
||||||
const lastMessage = chat[chat.length - 1];
|
const lastMessage = chat[chat.length - 1];
|
||||||
let messagesBefore = chat.length;
|
|
||||||
let lastMessageText = lastMessage?.mes || '';
|
|
||||||
let activationText = '';
|
let activationText = '';
|
||||||
let isUserInput = false;
|
let isUserInput = false;
|
||||||
let isGenerationDone = false;
|
|
||||||
let isGenerationAborted = false;
|
|
||||||
|
|
||||||
if (userInput?.length && !by_auto_mode) {
|
if (userInput?.length && !by_auto_mode) {
|
||||||
isUserInput = true;
|
isUserInput = true;
|
||||||
activationText = userInput;
|
activationText = userInput;
|
||||||
messagesBefore++;
|
|
||||||
} else {
|
} else {
|
||||||
if (lastMessage && !lastMessage.is_system) {
|
if (lastMessage && !lastMessage.is_system) {
|
||||||
activationText = lastMessage.mes;
|
activationText = lastMessage.mes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const resolveOriginal = params.resolve;
|
|
||||||
const rejectOriginal = params.reject;
|
|
||||||
|
|
||||||
if (params.signal instanceof AbortSignal) {
|
|
||||||
if (params.signal.aborted) {
|
|
||||||
throw new Error('Already aborted signal passed. Group generation stopped');
|
|
||||||
}
|
|
||||||
|
|
||||||
params.signal.onabort = () => {
|
|
||||||
isGenerationAborted = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof params.resolve === 'function') {
|
|
||||||
params.resolve = function () {
|
|
||||||
isGenerationDone = true;
|
|
||||||
resolveOriginal.apply(this, arguments);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof params.reject === 'function') {
|
|
||||||
params.reject = function () {
|
|
||||||
isGenerationDone = true;
|
|
||||||
rejectOriginal.apply(this, arguments);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const activationStrategy = Number(group.activation_strategy ?? group_activation_strategy.NATURAL);
|
const activationStrategy = Number(group.activation_strategy ?? group_activation_strategy.NATURAL);
|
||||||
const enabledMembers = group.members.filter(x => !group.disabled_members.includes(x));
|
const enabledMembers = group.members.filter(x => !group.disabled_members.includes(x));
|
||||||
let activatedMembers = [];
|
let activatedMembers = [];
|
||||||
@ -742,14 +716,12 @@ async function generateGroupWrapper(by_auto_mode, type = null, params = {}) {
|
|||||||
|
|
||||||
// now the real generation begins: cycle through every activated character
|
// now the real generation begins: cycle through every activated character
|
||||||
for (const chId of activatedMembers) {
|
for (const chId of activatedMembers) {
|
||||||
|
throwIfAborted();
|
||||||
deactivateSendButtons();
|
deactivateSendButtons();
|
||||||
isGenerationDone = false;
|
|
||||||
const generateType = type == 'swipe' || type == 'impersonate' || type == 'quiet' || type == 'continue' ? type : 'group_chat';
|
const generateType = type == 'swipe' || type == 'impersonate' || type == 'quiet' || type == 'continue' ? type : 'group_chat';
|
||||||
setCharacterId(chId);
|
setCharacterId(chId);
|
||||||
setCharacterName(characters[chId].name);
|
setCharacterName(characters[chId].name);
|
||||||
|
|
||||||
await Generate(generateType, { automatic_trigger: by_auto_mode, ...(params || {}) });
|
|
||||||
|
|
||||||
if (type !== 'swipe' && type !== 'impersonate' && !isStreamingEnabled()) {
|
if (type !== 'swipe' && type !== 'impersonate' && !isStreamingEnabled()) {
|
||||||
// update indicator and scroll down
|
// update indicator and scroll down
|
||||||
typingIndicator
|
typingIndicator
|
||||||
@ -758,75 +730,9 @@ async function generateGroupWrapper(by_auto_mode, type = null, params = {}) {
|
|||||||
typingIndicator.show();
|
typingIndicator.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This is awful. Refactor this
|
// Wait for generation to finish
|
||||||
while (true) {
|
const generateFinished = await Generate(generateType, { automatic_trigger: by_auto_mode, ...(params || {}) });
|
||||||
deactivateSendButtons();
|
textResult = await generateFinished;
|
||||||
if (isGenerationAborted) {
|
|
||||||
throw new Error('Group generation aborted');
|
|
||||||
}
|
|
||||||
|
|
||||||
// if not swipe - check if message generated already
|
|
||||||
if (generateType === 'group_chat' && chat.length == messagesBefore) {
|
|
||||||
await delay(100);
|
|
||||||
}
|
|
||||||
// if swipe - see if message changed
|
|
||||||
else if (type === 'swipe') {
|
|
||||||
if (isStreamingEnabled()) {
|
|
||||||
if (streamingProcessor && !streamingProcessor.isFinished) {
|
|
||||||
await delay(100);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (lastMessageText === chat[chat.length - 1].mes) {
|
|
||||||
await delay(100);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (type === 'impersonate') {
|
|
||||||
if (isStreamingEnabled()) {
|
|
||||||
if (streamingProcessor && !streamingProcessor.isFinished) {
|
|
||||||
await delay(100);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (!$('#send_textarea').val() || $('#send_textarea').val() == userInput) {
|
|
||||||
await delay(100);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (type === 'quiet') {
|
|
||||||
if (isGenerationDone) {
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
await delay(100);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (isStreamingEnabled()) {
|
|
||||||
if (streamingProcessor && !streamingProcessor.isFinished) {
|
|
||||||
await delay(100);
|
|
||||||
} else {
|
|
||||||
await waitUntilCondition(() => streamingProcessor == null, 1000, 10);
|
|
||||||
messagesBefore++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
messagesBefore++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
typingIndicator.hide();
|
typingIndicator.hide();
|
||||||
@ -839,6 +745,8 @@ async function generateGroupWrapper(by_auto_mode, type = null, params = {}) {
|
|||||||
activateSendButtons();
|
activateSendButtons();
|
||||||
showSwipeButtons();
|
showSwipeButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Promise.resolve(textResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLastMessageGenerationId() {
|
function getLastMessageGenerationId() {
|
||||||
|
@ -636,6 +636,7 @@ hr {
|
|||||||
display: none;
|
display: none;
|
||||||
order: 2;
|
order: 2;
|
||||||
padding-right: 2px;
|
padding-right: 2px;
|
||||||
|
place-self: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options_button {
|
#options_button {
|
||||||
|
Reference in New Issue
Block a user