mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'staging' into group-join-examples
This commit is contained in:
@ -849,11 +849,9 @@ export let is_send_press = false; //Send generation
|
|||||||
|
|
||||||
let this_del_mes = -1;
|
let this_del_mes = -1;
|
||||||
|
|
||||||
//message editing and chat scroll position persistence
|
//message editing
|
||||||
var this_edit_mes_chname = '';
|
var this_edit_mes_chname = '';
|
||||||
var this_edit_mes_id;
|
var this_edit_mes_id;
|
||||||
var scroll_holder = 0;
|
|
||||||
var is_use_scroll_holder = false;
|
|
||||||
|
|
||||||
//settings
|
//settings
|
||||||
export let settings;
|
export let settings;
|
||||||
@ -9727,16 +9725,16 @@ jQuery(async function () {
|
|||||||
chooseBogusFolder($(this), tagId);
|
chooseBogusFolder($(this), tagId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const cssAutofit = CSS.supports('field-sizing', 'content');
|
||||||
|
if (!cssAutofit) {
|
||||||
/**
|
/**
|
||||||
* Sets the scroll height of the edit textarea to fit the content.
|
* Sets the scroll height of the edit textarea to fit the content.
|
||||||
* @param {HTMLTextAreaElement} e Textarea element to auto-fit
|
* @param {HTMLTextAreaElement} e Textarea element to auto-fit
|
||||||
*/
|
*/
|
||||||
function autoFitEditTextArea(e) {
|
function autoFitEditTextArea(e) {
|
||||||
scroll_holder = chatElement[0].scrollTop;
|
|
||||||
e.style.height = '0px';
|
e.style.height = '0px';
|
||||||
const newHeight = e.scrollHeight + 4;
|
const newHeight = e.scrollHeight + 4;
|
||||||
e.style.height = `${newHeight}px`;
|
e.style.height = `${newHeight}px`;
|
||||||
is_use_scroll_holder = true;
|
|
||||||
}
|
}
|
||||||
const autoFitEditTextAreaDebounced = debounce(autoFitEditTextArea, debounce_timeout.short);
|
const autoFitEditTextAreaDebounced = debounce(autoFitEditTextArea, debounce_timeout.short);
|
||||||
document.addEventListener('input', e => {
|
document.addEventListener('input', e => {
|
||||||
@ -9746,6 +9744,8 @@ jQuery(async function () {
|
|||||||
immediately ? autoFitEditTextArea(e.target) : autoFitEditTextAreaDebounced(e.target);
|
immediately ? autoFitEditTextArea(e.target) : autoFitEditTextAreaDebounced(e.target);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const chatElementScroll = document.getElementById('chat');
|
const chatElementScroll = document.getElementById('chat');
|
||||||
const chatScrollHandler = function () {
|
const chatScrollHandler = function () {
|
||||||
if (power_user.waifuMode) {
|
if (power_user.waifuMode) {
|
||||||
@ -9767,12 +9767,6 @@ jQuery(async function () {
|
|||||||
};
|
};
|
||||||
chatElementScroll.addEventListener('wheel', chatScrollHandler, { passive: true });
|
chatElementScroll.addEventListener('wheel', chatScrollHandler, { passive: true });
|
||||||
chatElementScroll.addEventListener('touchmove', chatScrollHandler, { passive: true });
|
chatElementScroll.addEventListener('touchmove', chatScrollHandler, { passive: true });
|
||||||
chatElementScroll.addEventListener('scroll', function () {
|
|
||||||
if (is_use_scroll_holder) {
|
|
||||||
this.scrollTop = scroll_holder;
|
|
||||||
is_use_scroll_holder = false;
|
|
||||||
}
|
|
||||||
}, { passive: true });
|
|
||||||
|
|
||||||
$(document).on('click', '.mes', function () {
|
$(document).on('click', '.mes', function () {
|
||||||
//when a 'delete message' parent div is clicked
|
//when a 'delete message' parent div is clicked
|
||||||
@ -10511,14 +10505,16 @@ jQuery(async function () {
|
|||||||
.closest('.mes_block')
|
.closest('.mes_block')
|
||||||
.find('.mes_text')
|
.find('.mes_text')
|
||||||
.append(
|
.append(
|
||||||
'<textarea id=\'curEditTextarea\' class=\'edit_textarea mdHotkeys\' style=\'max-width:auto;\'></textarea>',
|
'<textarea id=\'curEditTextarea\' class=\'edit_textarea mdHotkeys\'></textarea>',
|
||||||
);
|
);
|
||||||
$('#curEditTextarea').val(text);
|
$('#curEditTextarea').val(text);
|
||||||
let edit_textarea = $(this)
|
let edit_textarea = $(this)
|
||||||
.closest('.mes_block')
|
.closest('.mes_block')
|
||||||
.find('.edit_textarea');
|
.find('.edit_textarea');
|
||||||
|
if (!cssAutofit) {
|
||||||
edit_textarea.height(0);
|
edit_textarea.height(0);
|
||||||
edit_textarea.height(edit_textarea[0].scrollHeight);
|
edit_textarea.height(edit_textarea[0].scrollHeight);
|
||||||
|
}
|
||||||
edit_textarea.focus();
|
edit_textarea.focus();
|
||||||
edit_textarea[0].setSelectionRange( //this sets the cursor at the end of the text
|
edit_textarea[0].setSelectionRange( //this sets the cursor at the end of the text
|
||||||
String(edit_textarea.val()).length,
|
String(edit_textarea.val()).length,
|
||||||
|
@ -887,7 +887,40 @@ export function initRossMods() {
|
|||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const cssAutofit = CSS.supports('field-sizing', 'content');
|
||||||
|
|
||||||
|
if (cssAutofit) {
|
||||||
|
let lastHeight = chatBlock.offsetHeight;
|
||||||
|
const chatBlockResizeObserver = new ResizeObserver((entries) => {
|
||||||
|
for (const entry of entries) {
|
||||||
|
if (entry.target !== chatBlock) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const threshold = 1;
|
||||||
|
const newHeight = chatBlock.offsetHeight;
|
||||||
|
const deltaHeight = newHeight - lastHeight;
|
||||||
|
const isScrollAtBottom = Math.abs(chatBlock.scrollHeight - chatBlock.scrollTop - newHeight) <= threshold;
|
||||||
|
|
||||||
|
if (!isScrollAtBottom && Math.abs(deltaHeight) > threshold) {
|
||||||
|
chatBlock.scrollTop -= deltaHeight;
|
||||||
|
}
|
||||||
|
lastHeight = newHeight;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
chatBlockResizeObserver.observe(chatBlock);
|
||||||
|
}
|
||||||
|
|
||||||
sendTextArea.addEventListener('input', () => {
|
sendTextArea.addEventListener('input', () => {
|
||||||
|
saveUserInputDebounced();
|
||||||
|
|
||||||
|
if (cssAutofit) {
|
||||||
|
// Unset modifications made with a manual resize
|
||||||
|
sendTextArea.style.height = 'auto';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const hasContent = sendTextArea.value !== '';
|
const hasContent = sendTextArea.value !== '';
|
||||||
const fitsCurrentSize = sendTextArea.scrollHeight <= sendTextArea.offsetHeight;
|
const fitsCurrentSize = sendTextArea.scrollHeight <= sendTextArea.offsetHeight;
|
||||||
const isScrollbarShown = sendTextArea.clientWidth < sendTextArea.offsetWidth;
|
const isScrollbarShown = sendTextArea.clientWidth < sendTextArea.offsetWidth;
|
||||||
@ -895,7 +928,6 @@ export function initRossMods() {
|
|||||||
const needsDebounce = hasContent && (fitsCurrentSize || (isScrollbarShown && isHalfScreenHeight));
|
const needsDebounce = hasContent && (fitsCurrentSize || (isScrollbarShown && isHalfScreenHeight));
|
||||||
if (needsDebounce) autoFitSendTextAreaDebounced();
|
if (needsDebounce) autoFitSendTextAreaDebounced();
|
||||||
else autoFitSendTextArea();
|
else autoFitSendTextArea();
|
||||||
saveUserInputDebounced();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
restoreUserInput();
|
restoreUserInput();
|
||||||
|
@ -15,6 +15,7 @@ import { SlashCommandEnumValue, enumTypes } from '../../slash-commands/SlashComm
|
|||||||
import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js';
|
import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js';
|
||||||
import { slashCommandReturnHelper } from '../../slash-commands/SlashCommandReturnHelper.js';
|
import { slashCommandReturnHelper } from '../../slash-commands/SlashCommandReturnHelper.js';
|
||||||
import { SlashCommandClosure } from '../../slash-commands/SlashCommandClosure.js';
|
import { SlashCommandClosure } from '../../slash-commands/SlashCommandClosure.js';
|
||||||
|
import { generateWebLlmChatPrompt, isWebLlmSupported } from '../shared.js';
|
||||||
export { MODULE_NAME };
|
export { MODULE_NAME };
|
||||||
|
|
||||||
const MODULE_NAME = 'expressions';
|
const MODULE_NAME = 'expressions';
|
||||||
@ -59,6 +60,7 @@ const EXPRESSION_API = {
|
|||||||
local: 0,
|
local: 0,
|
||||||
extras: 1,
|
extras: 1,
|
||||||
llm: 2,
|
llm: 2,
|
||||||
|
webllm: 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
let expressionsList = null;
|
let expressionsList = null;
|
||||||
@ -852,7 +854,7 @@ function setTalkingHeadState(newState) {
|
|||||||
extension_settings.expressions.talkinghead = newState; // Store setting
|
extension_settings.expressions.talkinghead = newState; // Store setting
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
|
|
||||||
if (extension_settings.expressions.api == EXPRESSION_API.local || extension_settings.expressions.api == EXPRESSION_API.llm) {
|
if ([EXPRESSION_API.local, EXPRESSION_API.llm, EXPRESSION_API.webllm].includes(extension_settings.expressions.api)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1057,21 +1059,25 @@ function parseLlmResponse(emotionResponse, labels) {
|
|||||||
console.debug(`fuzzy search found: ${result[0].item} as closest for the LLM response:`, emotionResponse);
|
console.debug(`fuzzy search found: ${result[0].item} as closest for the LLM response:`, emotionResponse);
|
||||||
return result[0].item;
|
return result[0].item;
|
||||||
}
|
}
|
||||||
|
const lowerCaseResponse = String(emotionResponse || '').toLowerCase();
|
||||||
|
for (const label of labels) {
|
||||||
|
if (lowerCaseResponse.includes(label.toLowerCase())) {
|
||||||
|
console.debug(`Found label ${label} in the LLM response:`, emotionResponse);
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error('Could not parse emotion response ' + emotionResponse);
|
throw new Error('Could not parse emotion response ' + emotionResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onTextGenSettingsReady(args) {
|
/**
|
||||||
// Only call if inside an API call
|
* Gets the JSON schema for the LLM API.
|
||||||
if (inApiCall && extension_settings.expressions.api === EXPRESSION_API.llm && isJsonSchemaSupported()) {
|
* @param {string[]} emotions A list of emotions to search for.
|
||||||
const emotions = DEFAULT_EXPRESSIONS.filter((e) => e != 'talkinghead');
|
* @returns {object} The JSON schema for the LLM API.
|
||||||
Object.assign(args, {
|
*/
|
||||||
top_k: 1,
|
function getJsonSchema(emotions) {
|
||||||
stop: [],
|
return {
|
||||||
stopping_strings: [],
|
|
||||||
custom_token_bans: [],
|
|
||||||
json_schema: {
|
|
||||||
$schema: 'http://json-schema.org/draft-04/schema#',
|
$schema: 'http://json-schema.org/draft-04/schema#',
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
@ -1083,7 +1089,19 @@ function onTextGenSettingsReady(args) {
|
|||||||
required: [
|
required: [
|
||||||
'emotion',
|
'emotion',
|
||||||
],
|
],
|
||||||
},
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function onTextGenSettingsReady(args) {
|
||||||
|
// Only call if inside an API call
|
||||||
|
if (inApiCall && extension_settings.expressions.api === EXPRESSION_API.llm && isJsonSchemaSupported()) {
|
||||||
|
const emotions = DEFAULT_EXPRESSIONS.filter((e) => e != 'talkinghead');
|
||||||
|
Object.assign(args, {
|
||||||
|
top_k: 1,
|
||||||
|
stop: [],
|
||||||
|
stopping_strings: [],
|
||||||
|
custom_token_bans: [],
|
||||||
|
json_schema: getJsonSchema(emotions),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1139,6 +1157,22 @@ export async function getExpressionLabel(text, expressionsApi = extension_settin
|
|||||||
const emotionResponse = await generateRaw(text, main_api, false, false, prompt);
|
const emotionResponse = await generateRaw(text, main_api, false, false, prompt);
|
||||||
return parseLlmResponse(emotionResponse, expressionsList);
|
return parseLlmResponse(emotionResponse, expressionsList);
|
||||||
}
|
}
|
||||||
|
// Using WebLLM
|
||||||
|
case EXPRESSION_API.webllm: {
|
||||||
|
if (!isWebLlmSupported()) {
|
||||||
|
console.warn('WebLLM is not supported. Using fallback expression');
|
||||||
|
return getFallbackExpression();
|
||||||
|
}
|
||||||
|
|
||||||
|
const expressionsList = await getExpressionsList();
|
||||||
|
const prompt = substituteParamsExtended(customPrompt, { labels: expressionsList }) || await getLlmPrompt(expressionsList);
|
||||||
|
const messages = [
|
||||||
|
{ role: 'user', content: text + '\n\n' + prompt },
|
||||||
|
];
|
||||||
|
|
||||||
|
const emotionResponse = await generateWebLlmChatPrompt(messages);
|
||||||
|
return parseLlmResponse(emotionResponse, expressionsList);
|
||||||
|
}
|
||||||
// Extras
|
// Extras
|
||||||
default: {
|
default: {
|
||||||
const url = new URL(getApiUrl());
|
const url = new URL(getApiUrl());
|
||||||
@ -1603,7 +1637,7 @@ function onExpressionApiChanged() {
|
|||||||
const tempApi = this.value;
|
const tempApi = this.value;
|
||||||
if (tempApi) {
|
if (tempApi) {
|
||||||
extension_settings.expressions.api = Number(tempApi);
|
extension_settings.expressions.api = Number(tempApi);
|
||||||
$('.expression_llm_prompt_block').toggle(extension_settings.expressions.api === EXPRESSION_API.llm);
|
$('.expression_llm_prompt_block').toggle([EXPRESSION_API.llm, EXPRESSION_API.webllm].includes(extension_settings.expressions.api));
|
||||||
expressionsList = null;
|
expressionsList = null;
|
||||||
spriteCache = {};
|
spriteCache = {};
|
||||||
moduleWorker();
|
moduleWorker();
|
||||||
@ -1940,7 +1974,7 @@ function migrateSettings() {
|
|||||||
|
|
||||||
await renderAdditionalExpressionSettings();
|
await renderAdditionalExpressionSettings();
|
||||||
$('#expression_api').val(extension_settings.expressions.api ?? EXPRESSION_API.extras);
|
$('#expression_api').val(extension_settings.expressions.api ?? EXPRESSION_API.extras);
|
||||||
$('.expression_llm_prompt_block').toggle(extension_settings.expressions.api === EXPRESSION_API.llm);
|
$('.expression_llm_prompt_block').toggle([EXPRESSION_API.llm, EXPRESSION_API.webllm].includes(extension_settings.expressions.api));
|
||||||
$('#expression_llm_prompt').val(extension_settings.expressions.llmPrompt ?? '');
|
$('#expression_llm_prompt').val(extension_settings.expressions.llmPrompt ?? '');
|
||||||
$('#expression_llm_prompt').on('input', function () {
|
$('#expression_llm_prompt').on('input', function () {
|
||||||
extension_settings.expressions.llmPrompt = $(this).val();
|
extension_settings.expressions.llmPrompt = $(this).val();
|
||||||
|
@ -24,7 +24,8 @@
|
|||||||
<select id="expression_api" class="flex1 margin0">
|
<select id="expression_api" class="flex1 margin0">
|
||||||
<option value="0" data-i18n="Local">Local</option>
|
<option value="0" data-i18n="Local">Local</option>
|
||||||
<option value="1" data-i18n="Extras">Extras</option>
|
<option value="1" data-i18n="Extras">Extras</option>
|
||||||
<option value="2" data-i18n="LLM">LLM</option>
|
<option value="2" data-i18n="Main API">Main API</option>
|
||||||
|
<option value="3" data-i18n="WebLLM Extension">WebLLM Extension</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="expression_llm_prompt_block m-b-1 m-t-1">
|
<div class="expression_llm_prompt_block m-b-1 m-t-1">
|
||||||
|
@ -25,6 +25,7 @@ const OPENROUTER_PROVIDERS = [
|
|||||||
'Anthropic',
|
'Anthropic',
|
||||||
'Google',
|
'Google',
|
||||||
'Google AI Studio',
|
'Google AI Studio',
|
||||||
|
'Amazon Bedrock',
|
||||||
'Groq',
|
'Groq',
|
||||||
'SambaNova',
|
'SambaNova',
|
||||||
'Cohere',
|
'Cohere',
|
||||||
@ -50,6 +51,8 @@ const OPENROUTER_PROVIDERS = [
|
|||||||
'Featherless',
|
'Featherless',
|
||||||
'Inflection',
|
'Inflection',
|
||||||
'xAI',
|
'xAI',
|
||||||
|
'Cloudflare',
|
||||||
|
'SF Compute',
|
||||||
'01.AI',
|
'01.AI',
|
||||||
'HuggingFace',
|
'HuggingFace',
|
||||||
'Mancer',
|
'Mancer',
|
||||||
|
@ -1264,6 +1264,7 @@ button {
|
|||||||
text-shadow: 0px 0px calc(var(--shadowWidth) * 1px) var(--SmartThemeShadowColor);
|
text-shadow: 0px 0px calc(var(--shadowWidth) * 1px) var(--SmartThemeShadowColor);
|
||||||
flex: 1;
|
flex: 1;
|
||||||
order: 3;
|
order: 3;
|
||||||
|
field-sizing: content;
|
||||||
|
|
||||||
--progColor: rgb(146, 190, 252);
|
--progColor: rgb(146, 190, 252);
|
||||||
--progFlashColor: rgb(215, 136, 114);
|
--progFlashColor: rgb(215, 136, 114);
|
||||||
@ -4111,6 +4112,7 @@ input[type="range"]::-webkit-slider-thumb {
|
|||||||
line-height: calc(var(--mainFontSize) + .25rem);
|
line-height: calc(var(--mainFontSize) + .25rem);
|
||||||
max-height: 75vh;
|
max-height: 75vh;
|
||||||
max-height: 75dvh;
|
max-height: 75dvh;
|
||||||
|
field-sizing: content;
|
||||||
}
|
}
|
||||||
|
|
||||||
#anchor_order {
|
#anchor_order {
|
||||||
|
Reference in New Issue
Block a user