Merge branch 'staging' into small-bookmark-updates

This commit is contained in:
Wolfsblvt
2024-09-10 19:05:05 +02:00
32 changed files with 1624 additions and 594 deletions

View File

@ -224,7 +224,7 @@ import {
import { getBackgrounds, initBackgrounds, loadBackgroundSettings, background_settings } from './scripts/backgrounds.js';
import { hideLoader, showLoader } from './scripts/loader.js';
import { BulkEditOverlay, CharacterContextMenu } from './scripts/BulkEditOverlay.js';
import { loadFeatherlessModels, loadMancerModels, loadOllamaModels, loadTogetherAIModels, loadInfermaticAIModels, loadOpenRouterModels, loadVllmModels, loadAphroditeModels, loadDreamGenModels, initTextGenModels } from './scripts/textgen-models.js';
import { loadFeatherlessModels, loadMancerModels, loadOllamaModels, loadTogetherAIModels, loadInfermaticAIModels, loadOpenRouterModels, loadVllmModels, loadAphroditeModels, loadDreamGenModels, initTextGenModels, loadTabbyModels } from './scripts/textgen-models.js';
import { appendFileContent, hasPendingFileAttachment, populateFileAttachment, decodeStyleTags, encodeStyleTags, isExternalMediaAllowed, getCurrentEntityId } from './scripts/chats.js';
import { initPresetManager } from './scripts/preset-manager.js';
import { MacrosParser, evaluateMacros, getLastMessageId } from './scripts/macros.js';
@ -242,6 +242,7 @@ import { INTERACTABLE_CONTROL_CLASS, initKeyboard } from './scripts/keyboard.js'
import { initDynamicStyles } from './scripts/dynamic-styles.js';
import { SlashCommandEnumValue, enumTypes } from './scripts/slash-commands/SlashCommandEnumValue.js';
import { commonEnumProviders, enumIcons } from './scripts/slash-commands/SlashCommandCommonEnumsProvider.js';
import { AbortReason } from './scripts/util/AbortReason.js';
//exporting functions and vars for mods
export {
@ -462,6 +463,7 @@ export const event_types = {
LLM_FUNCTION_TOOL_CALL: 'llm_function_tool_call',
ONLINE_STATUS_CHANGED: 'online_status_changed',
IMAGE_SWIPED: 'image_swiped',
CONNECTION_PROFILE_LOADED: 'connection_profile_loaded',
};
export const eventSource = new EventEmitter();
@ -962,8 +964,8 @@ async function fixViewport() {
document.body.style.position = '';
}
function cancelStatusCheck() {
abortStatusCheck?.abort();
function cancelStatusCheck(reason = 'Manually cancelled status check') {
abortStatusCheck?.abort(new AbortReason(reason));
abortStatusCheck = new AbortController();
setOnlineStatus('no_connection');
}
@ -1197,6 +1199,9 @@ async function getStatusTextgen() {
} else if (textgen_settings.type === FEATHERLESS) {
loadFeatherlessModels(data?.data);
setOnlineStatus(textgen_settings.featherless_model);
} else if (textgen_settings.type === TABBY) {
loadTabbyModels(data?.data);
setOnlineStatus(textgen_settings.tabby_model || data?.result);
} else {
setOnlineStatus(data?.result);
}
@ -1213,7 +1218,12 @@ async function getStatusTextgen() {
toastr.error(data.response, 'API Error', { timeOut: 5000, preventDuplicates: true });
}
} catch (err) {
console.error('Error getting status', err);
if (err instanceof AbortReason) {
console.info('Status check aborted.', err.reason);
} else {
console.error('Error getting status', err);
}
setOnlineStatus('no_connection');
}
@ -1867,6 +1877,7 @@ export async function sendTextareaMessage() {
// message was sent from a character (not the user or the system).
const textareaText = String($('#send_textarea').val());
if (power_user.continue_on_send &&
!hasPendingFileAttachment() &&
!textareaText &&
!selected_group &&
chat.length &&
@ -3080,6 +3091,12 @@ class StreamingProcessor {
this.hideMessageButtons(this.messageId);
generatedPromptCache = '';
unblockGeneration();
const noEmitTypes = ['swipe', 'impersonate', 'continue'];
if (!noEmitTypes.includes(this.type)) {
eventSource.emit(event_types.MESSAGE_RECEIVED, this.messageId);
eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, this.messageId);
}
}
setFirstSwipe(messageId) {
@ -3310,7 +3327,7 @@ function removeLastMessage() {
*/
export async function Generate(type, { automatic_trigger, force_name2, quiet_prompt, quietToLoud, skipWIAN, force_chid, signal, quietImage, maxLoops, quietName } = {}, dryRun = false) {
console.log('Generate entered');
eventSource.emit(event_types.GENERATION_STARTED, type, { automatic_trigger, force_name2, quiet_prompt, quietToLoud, skipWIAN, force_chid, signal, quietImage, maxLoops }, dryRun);
await eventSource.emit(event_types.GENERATION_STARTED, type, { automatic_trigger, force_name2, quiet_prompt, quietToLoud, skipWIAN, force_chid, signal, quietImage, maxLoops }, dryRun);
setGenerationProgress(0);
generation_started = new Date();
@ -3390,7 +3407,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
.filter((index) => index !== undefined && index !== null);
if (memberIds.length > 0) {
setCharacterId(memberIds[0]);
if (menu_type != 'character_edit') setCharacterId(memberIds[0]);
setCharacterName('');
} else {
console.log('No enabled members found');
@ -3456,8 +3473,17 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
//PRE FORMATING STRING
//*********************************
// These generation types should not attach pending files to the chat
const noAttachTypes = [
'regenerate',
'swipe',
'impersonate',
'quiet',
'continue',
'ask_command',
];
//for normal messages sent from user..
if ((textareaText != '' || hasPendingFileAttachment()) && !automatic_trigger && type !== 'quiet' && !dryRun) {
if ((textareaText != '' || (hasPendingFileAttachment() && !noAttachTypes.includes(type))) && !automatic_trigger && type !== 'quiet' && !dryRun) {
// If user message contains no text other than bias - send as a system message
if (messageBias && !removeMacros(textareaText)) {
sendSystemMessage(system_message_types.GENERIC, ' ', { bias: messageBias });
@ -4910,7 +4936,7 @@ async function duplicateCharacter() {
return '';
}
export async function itemizedParams(itemizedPrompts, thisPromptSet) {
export async function itemizedParams(itemizedPrompts, thisPromptSet, incomingMesId) {
const params = {
charDescriptionTokens: await getTokenCountAsync(itemizedPrompts[thisPromptSet].charDescription),
charPersonalityTokens: await getTokenCountAsync(itemizedPrompts[thisPromptSet].charPersonality),
@ -4929,8 +4955,20 @@ export async function itemizedParams(itemizedPrompts, thisPromptSet) {
chatInjects: await getTokenCountAsync(itemizedPrompts[thisPromptSet].chatInjects),
chatVectorsStringTokens: await getTokenCountAsync(itemizedPrompts[thisPromptSet].chatVectorsString),
dataBankVectorsStringTokens: await getTokenCountAsync(itemizedPrompts[thisPromptSet].dataBankVectorsString),
modelUsed: chat[incomingMesId]?.extra?.model,
apiUsed: chat[incomingMesId]?.extra?.api,
};
const getFriendlyName = (value) => $(`#rm_api_block select option[value="${value}"]`).first().text() || value;
if (params.apiUsed) {
params.apiUsed = getFriendlyName(params.apiUsed);
}
if (params.this_main_api) {
params.mainApiFriendlyName = getFriendlyName(params.this_main_api);
}
if (params.chatInjects) {
params.ActualChatHistoryTokens = params.ActualChatHistoryTokens - params.chatInjects;
}
@ -5045,7 +5083,7 @@ async function promptItemize(itemizedPrompts, requestedMesId) {
return null;
}
const params = await itemizedParams(itemizedPrompts, thisPromptSet);
const params = await itemizedParams(itemizedPrompts, thisPromptSet, incomingMesId);
const flatten = (rawPrompt) => Array.isArray(rawPrompt) ? rawPrompt.map(x => x.content).join('\n') : rawPrompt;
const template = params.this_main_api == 'openai'
@ -8482,7 +8520,7 @@ async function selectContextCallback(args, name) {
}
const foundName = result[0].item;
selectContextPreset(foundName, quiet);
selectContextPreset(foundName, { quiet: quiet });
return foundName;
}
@ -8502,7 +8540,7 @@ async function selectInstructCallback(args, name) {
}
const foundName = result[0].item;
selectInstructPreset(foundName, quiet);
selectInstructPreset(foundName, { quiet: quiet });
return foundName;
}
@ -9279,7 +9317,7 @@ jQuery(async function () {
$('#groupCurrentMemberListToggle .inline-drawer-icon').trigger('click');
}, 200);
$(document).on('click', '.api_loading', cancelStatusCheck);
$(document).on('click', '.api_loading', () => cancelStatusCheck('Canceled because connecting was manually canceled'));
//////////INPUT BAR FOCUS-KEEPING LOGIC/////////////
let S_TAPreviouslyFocused = false;
@ -10038,7 +10076,7 @@ jQuery(async function () {
});
$('#main_api').change(function () {
cancelStatusCheck();
cancelStatusCheck('Canceled because main api changed');
changeMainAPI();
saveSettingsDebounced();
});
@ -10655,7 +10693,11 @@ jQuery(async function () {
var icon = $(this).find('.inline-drawer-icon');
icon.toggleClass('down up');
icon.toggleClass('fa-circle-chevron-down fa-circle-chevron-up');
$(this).closest('.inline-drawer').find('.inline-drawer-content').stop().slideToggle();
$(this).closest('.inline-drawer').find('.inline-drawer-content').stop().slideToggle({
complete: () => {
$(this).css('height', '');
},
});
// Set the height of "autoSetHeight" textareas within the inline-drawer to their scroll height
if (!CSS.supports('field-sizing', 'content')) {