Skip to content

Commit

Permalink
Merge branch 'staging' into model-write-in
Browse files Browse the repository at this point in the history
  • Loading branch information
Cohee1207 committed Oct 1, 2024
2 parents c76fc7d + 14fb42b commit bb1139b
Show file tree
Hide file tree
Showing 15 changed files with 706 additions and 285 deletions.
1 change: 0 additions & 1 deletion default/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ extras:
classificationModel: Cohee/distilbert-base-uncased-go-emotions-onnx
captioningModel: Xenova/vit-gpt2-image-captioning
embeddingModel: Cohee/jina-embeddings-v2-base-en
promptExpansionModel: Cohee/fooocus_expansion-onnx
speechToTextModel: Xenova/whisper-small
textToSpeechModel: Xenova/speecht5_tts
# -- OPENAI CONFIGURATION --
Expand Down
34 changes: 18 additions & 16 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1709,9 +1709,9 @@ <h4 class="range-block-title justifyCenter">
<div class="">
<div class="inline-drawer wide100p flexFlowColumn">
<div class="inline-drawer-toggle inline-drawer-header">
<div class="flex-container alignItemsCenter flexNoGap">
<div class="flex-container alignItemsCenter">
<b data-i18n="Character Names Behavior">Character Names Behavior</b>
<span title="Helps the model to associate messages with characters." data-i18n="[title]Helps the model to associate messages with characters." class="note-link-span fa-solid fa-circle-question"></span>
<span title="Helps the model to associate messages with characters." data-i18n="[title]Helps the model to associate messages with characters." class="opacity50p fa-solid fa-circle-info"></span>
<small class="flexBasis100p">(<span id="character_names_display"></span>)</small>
</div>
<div class="fa-solid fa-circle-chevron-down inline-drawer-icon down"></div>
Expand All @@ -1720,25 +1720,22 @@ <h4 class="range-block-title justifyCenter">
<label class="checkbox_label flexWrap alignItemsCenter" for="character_names_none">
<input type="radio" id="character_names_none" name="character_names" value="-1">
<span data-i18n="None">None</span>
<i class="right_menu_button fa-solid fa-circle-exclamation" title="Never add character name prefixes. May behave poorly in groups, choose with caution." data-i18n="[title]character_names_none"></i>
<small class="flexBasis100p" data-i18n="Never add character names.">
Never add character names.
<small class="flexBasis100p" data-i18n="character_names_none">
Never add character name prefixes. May behave poorly in groups, choose with caution.
</small>
</label>
<label class="checkbox_label flexWrap alignItemsCenter" for="character_names_default">
<input type="radio" id="character_names_default" name="character_names" value="0">
<span data-i18n="Default">Default</span>
<i class="right_menu_button fa-solid fa-circle-exclamation" title="Add prefixes for groups and past personas. Otherwise, make sure you provide names in the prompt." data-i18n="[title]character_names_default"></i>
<small class="flexBasis100p" data-i18n="Don't add character names unless necessary.">
Don't add character names unless necessary.
<small class="flexBasis100p" data-i18n="character_names_default">
Add prefixes for groups and past personas. Otherwise, make sure you provide names in the prompt.
</small>
</label>
<label class="checkbox_label flexWrap alignItemsCenter" for="character_names_completion">
<input type="radio" id="character_names_completion" name="character_names" value="1">
<span data-i18n="Completion Object">Completion Object</span>
<i class="right_menu_button fa-solid fa-circle-exclamation" title="Restrictions apply: only Latin alphanumerics and underscores. Doesn't work for all sources, notably: Claude, MistralAI, Google." data-i18n="[title]character_names_completion"></i>
<small class="flexBasis100p" data-i18n="Add character names to completion objects.">
Add character names to completion objects.
<small class="flexBasis100p" data-i18n="character_names_completion">
Add character names to completion objects. Restrictions apply: only Latin alphanumerics and underscores.
</small>
</label>
<label class="checkbox_label flexWrap alignItemsCenter" for="character_names_content">
Expand All @@ -1754,9 +1751,9 @@ <h4 class="range-block-title justifyCenter">
</div>
<div class="inline-drawer wide100p flexFlowColumn marginBot10">
<div class="inline-drawer-toggle inline-drawer-header">
<div class="flex-container alignItemsCenter flexNoGap">
<div class="flex-container alignItemsCenter">
<b data-i18n="Continue Postfix">Continue Postfix</b>
<span data-i18n="[title]The next chunk of the continued message will be appended using this as a separator." title="The next chunk of the continued message will be appended using this as a separator." class="note-link-span fa-solid fa-circle-question"></span>
<span data-i18n="[title]The next chunk of the continued message will be appended using this as a separator." title="The next chunk of the continued message will be appended using this as a separator." class="opacity50p fa-solid fa-circle-info"></span>
<small class="flexBasis100p">(<span id="continue_postfix_display"></span>)</small>
</div>
<div class="fa-solid fa-circle-chevron-down inline-drawer-icon down"></div>
Expand Down Expand Up @@ -4013,6 +4010,10 @@ <h4 class="title_restorable">
<input id="compact_input_area" type="checkbox" />
<small data-i18n="Compact Input Area (Mobile)">Compact Input Area</small><i class="fa-solid fa-mobile-screen-button"></i>
</label>
<label for="show_swipe_num_all_messages" class="checkbox_label" title="Display swipe numbers for all messages, not just the last." data-i18n="[title]Display swipe numbers for all messages, not just the last.">
<input id="show_swipe_num_all_messages" type="checkbox" />
<small data-i18n="Swipe # for All Messages">Swipe # for All Messages</small><i class="fa-solid fa-mobile-screen-button"></i>
</label>
<label for="hotswapEnabled" class="checkbox_label" title="In the Character Management panel, show quick selection buttons for favorited characters." data-i18n="[title]In the Character Management panel, show quick selection buttons for favorited characters">
<input id="hotswapEnabled" type="checkbox" />
<small data-i18n="Characters Hotswap">Characters Hotswap</small>
Expand Down Expand Up @@ -5941,9 +5942,10 @@ <h3 data-i18n="prompt_manager_edit">Edit</h3>
</div>
<div class="mes_bias"></div>
</div>
<div class="swipe_right fa-solid fa-chevron-right" style="display: none;">
<div class="swipes-counter"></div>
</div>
<div class="flex-container swipeRightBlock flexFlowColumn flexNoGap">
<div class="swipe_right fa-solid fa-chevron-right" style="display: none;"></div>
<div class="swipes-counter"></div>
</div>
</div>
</div>
<div id="group_avatars_template" class="template_element">
Expand Down
55 changes: 34 additions & 21 deletions public/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import {
resetMovableStyles,
forceCharacterEditorTokenize,
applyPowerUserSettings,
switchSwipeNumAllMessages,
} from './scripts/power-user.js';

import {
Expand Down Expand Up @@ -2369,6 +2370,13 @@ export function addOneMessage(mes, { type = 'normal', insertAfter = null, scroll

addCopyToCodeBlocks(newMessage);

// Set the swipes counter for past messages, only visible if 'Show Swipes on All Message' is enabled
if (!params.isUser && newMessageId !== 0 && newMessageId !== chat.length - 1) {
const swipesNum = chat[newMessageId].swipes?.length;
const swipeId = chat[newMessageId].swipe_id + 1;
newMessage.find('.swipes-counter').text(`${swipeId}\u200B/\u200b${swipesNum}`);
}

if (showSwipes) {
$('#chat .mes').last().addClass('last_mes');
$('#chat .mes').eq(-2).removeClass('last_mes');
Expand Down Expand Up @@ -4785,7 +4793,7 @@ export function removeMacros(str) {
* @param {boolean} [compact] Send as a compact display message.
* @param {string} [name] Name of the user sending the message. Defaults to name1.
* @param {string} [avatar] Avatar of the user sending the message. Defaults to user_avatar.
* @returns {Promise<void>} A promise that resolves when the message is inserted.
* @returns {Promise<any>} A promise that resolves to the message when it is inserted.
*/
export async function sendMessageAsUser(messageText, messageBias, insertAt = null, compact = false, name = name1, avatar = user_avatar) {
messageText = getRegexedString(messageText, regex_placement.USER_INPUT);
Expand Down Expand Up @@ -4832,6 +4840,8 @@ export async function sendMessageAsUser(messageText, messageBias, insertAt = nul
await eventSource.emit(event_types.USER_MESSAGE_RENDERED, chat_id);
await saveChatConditional();
}

return message;
}

/**
Expand Down Expand Up @@ -7469,7 +7479,6 @@ export function showSwipeButtons() {
//had to add this to make the swipe counter work
//(copied from the onclick functions for swipe buttons..
//don't know why the array isn't set for non-swipe messsages in Generate or addOneMessage..)

if (chat[chat.length - 1]['swipe_id'] === undefined) { // if there is no swipe-message in the last spot of the chat array
chat[chat.length - 1]['swipe_id'] = 0; // set it to id 0
chat[chat.length - 1]['swipes'] = []; // empty the array
Expand All @@ -7479,32 +7488,36 @@ export function showSwipeButtons() {
const currentMessage = $('#chat').children().filter(`[mesid="${chat.length - 1}"]`);
const swipeId = chat[chat.length - 1].swipe_id;
const swipeCounterText = (`${(swipeId + 1)}\u200B/\u200b${(chat[chat.length - 1].swipes.length)}`);
const swipeRight = currentMessage.find('.swipe_right');
const swipeLeft = currentMessage.find('.swipe_left');
const swipeCounter = currentMessage.find('.swipes-counter');

if (swipeId !== undefined && (chat[chat.length - 1].swipes.length > 1 || swipeId > 0)) {
currentMessage.children('.swipe_left').css('display', 'flex');
swipeLeft.css('display', 'flex');
}
//only show right when generate is off, or when next right swipe would not make a generate happen
if (is_send_press === false || chat[chat.length - 1].swipes.length >= swipeId) {
currentMessage.children('.swipe_right').css('display', 'flex');
currentMessage.children('.swipe_right').css('opacity', '0.3');
swipeRight.css('display', 'flex').css('opacity', '0.3');
swipeCounter.css('opacity', '0.3');
}
//console.log((chat[chat.length - 1]));
if ((chat[chat.length - 1].swipes.length - swipeId) === 1) {
//console.log('highlighting R swipe');
currentMessage.children('.swipe_right').css('opacity', '0.7');
//chevron was moved out of hardcode in HTML to class toggle dependent on last_mes or not
//necessary for 'swipe_right' div in past messages to have no chevron if 'show swipes for all messages' is turned on
swipeRight.css('opacity', '0.7');
swipeCounter.css('opacity', '0.7');
}
//console.log(swipesCounterHTML);

$('.swipes-counter').text(swipeCounterText);
//allows for writing individual swipe counters for past messages
const lastSwipeCounter = $('.last_mes .swipes-counter');
lastSwipeCounter.text(swipeCounterText).show();

//console.log(swipeId);
//console.log(chat[chat.length - 1].swipes.length);
switchSwipeNumAllMessages();
}

export function hideSwipeButtons() {
//console.log('hideswipebuttons entered');
$('#chat').find('.swipe_right').css('display', 'none');
$('#chat').find('.swipe_left').css('display', 'none');
$('#chat').find('.swipe_right').hide();
$('#chat').find('.last_mes .swipes-counter').hide();
$('#chat').find('.swipe_left').hide();
}

/**
Expand Down Expand Up @@ -8339,8 +8352,8 @@ const swipe_right = () => {
}

const currentMessage = $('#chat').children().filter(`[mesid="${chat.length - 1}"]`);
let this_div = currentMessage.children('.swipe_right');
let this_mes_div = this_div.parent();
let this_div = currentMessage.find('.swipe_right');
let this_mes_div = this_div.parent().parent();

if (chat[chat.length - 1]['swipe_id'] > chat[chat.length - 1]['swipes'].length) { //if we swipe right while generating (the swipe ID is greater than what we are viewing now)
chat[chat.length - 1]['swipe_id'] = chat[chat.length - 1]['swipes'].length; //show that message slot (will be '...' while generating)
Expand All @@ -8350,7 +8363,7 @@ const swipe_right = () => {
}
// handles animated transitions when swipe right, specifically height transitions between messages
if (run_generate || run_swipe_right) {
let this_mes_block = this_mes_div.children('.mes_block').children('.mes_text');
let this_mes_block = this_mes_div.find('.mes_block .mes_text');
const this_mes_div_height = this_mes_div[0].scrollHeight;
const this_mes_block_height = this_mes_block[0].scrollHeight;

Expand Down Expand Up @@ -9407,9 +9420,9 @@ jQuery(async function () {

///// SWIPE BUTTON CLICKS ///////

$(document).on('click', '.swipe_right', swipe_right);

$(document).on('click', '.swipe_left', swipe_left);
//limit swiping to only last message clicks
$(document).on('click', '.last_mes .swipe_right', swipe_right);
$(document).on('click', '.last_mes .swipe_left', swipe_left);

const debouncedCharacterSearch = debounce((searchQuery) => {
entitiesFilter.setFilterData(FILTER_TYPES.SEARCH, searchQuery);
Expand Down
40 changes: 33 additions & 7 deletions public/scripts/extensions/expressions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '
import { isFunctionCallingSupported } from '../../openai.js';
import { SlashCommandEnumValue, enumTypes } from '../../slash-commands/SlashCommandEnumValue.js';
import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js';
import { slashCommandReturnHelper } from '../../slash-commands/SlashCommandReturnHelper.js';
import { SlashCommandClosure } from '../../slash-commands/SlashCommandClosure.js';
export { MODULE_NAME };

const MODULE_NAME = 'expressions';
Expand Down Expand Up @@ -2134,18 +2136,42 @@ function migrateSettings() {
name: 'classify-expressions',
aliases: ['expressions'],
callback: async (args) => {
const list = await getExpressionsList();
switch (String(args.format).toLowerCase()) {
case 'json':
return JSON.stringify(list);
default:
return list.join(', ');
/** @type {import('../../slash-commands/SlashCommandReturnHelper.js').SlashCommandReturnType} */
// @ts-ignore
let returnType = args.return;

// Old legacy return type handling
if (args.format) {
toastr.warning(`Legacy argument 'format' with value '${args.format}' is deprecated. Please use 'return' instead. Routing to the correct return type...`, 'Deprecation warning');
const type = String(args?.format).toLowerCase().trim();
switch (type) {
case 'json':
returnType = 'object';
break;
default:
returnType = 'pipe';
break;
}
}

// Now the actual new return type handling
const list = await getExpressionsList();

return await slashCommandReturnHelper.doReturn(returnType ?? 'pipe', list, { objectToStringFunc: list => list.join(', ') });
},
namedArgumentList: [
SlashCommandNamedArgument.fromProps({
name: 'return',
description: 'The way how you want the return value to be provided',
typeList: [ARGUMENT_TYPE.STRING],
defaultValue: 'pipe',
enumList: slashCommandReturnHelper.enumList({ allowObject: true }),
forceEnum: true,
}),
// TODO remove some day
SlashCommandNamedArgument.fromProps({
name: 'format',
description: 'The format to return the list in: comma-separated plain text or JSON array. Default is plain text.',
description: '!!! DEPRECATED - use "return" instead !!! The format to return the list in: comma-separated plain text or JSON array. Default is plain text.',
typeList: [ARGUMENT_TYPE.STRING],
enumList: [
new SlashCommandEnumValue('plain', null, enumTypes.enum, ', '),
Expand Down
Loading

0 comments on commit bb1139b

Please sign in to comment.