Merge branch 'staging' into qr-editor-wordwrap

This commit is contained in:
LenAnderson
2024-03-25 09:05:49 -04:00
38 changed files with 1691 additions and 707 deletions

View File

@ -29,7 +29,7 @@ let galleryMaxRows = 3;
* @returns {Promise<Array>} - Resolves with an array of gallery item objects, rejects on error.
*/
async function getGalleryItems(url) {
const response = await fetch(`/listimgfiles/${url}`, {
const response = await fetch(`/api/images/list/${url}`, {
method: 'POST',
headers: getRequestHeaders(),
});
@ -201,7 +201,7 @@ async function uploadFile(file, url) {
'Content-Type': 'application/json',
});
const response = await fetch('/uploadimage', {
const response = await fetch('/api/images/upload', {
method: 'POST',
headers: headers,
body: JSON.stringify(payload),

View File

@ -1,6 +1,6 @@
import { getStringHash, debounce, waitUntilCondition, extractAllWords } from '../../utils.js';
import { getContext, getApiUrl, extension_settings, doExtrasFetch, modules } from '../../extensions.js';
import { animation_duration, eventSource, event_types, extension_prompt_types, generateQuietPrompt, is_send_press, saveSettingsDebounced, substituteParams } from '../../../script.js';
import { animation_duration, eventSource, event_types, extension_prompt_roles, extension_prompt_types, generateQuietPrompt, is_send_press, saveSettingsDebounced, substituteParams } from '../../../script.js';
import { is_group_generating, selected_group } from '../../group-chats.js';
import { registerSlashCommand } from '../../slash-commands.js';
import { loadMovingUIState } from '../../power-user.js';
@ -49,6 +49,7 @@ const defaultSettings = {
prompt: defaultPrompt,
template: defaultTemplate,
position: extension_prompt_types.IN_PROMPT,
role: extension_prompt_roles.SYSTEM,
depth: 2,
promptWords: 200,
promptMinWords: 25,
@ -83,6 +84,7 @@ function loadSettings() {
$('#memory_prompt_interval').val(extension_settings.memory.promptInterval).trigger('input');
$('#memory_template').val(extension_settings.memory.template).trigger('input');
$('#memory_depth').val(extension_settings.memory.depth).trigger('input');
$('#memory_role').val(extension_settings.memory.role).trigger('input');
$(`input[name="memory_position"][value="${extension_settings.memory.position}"]`).prop('checked', true).trigger('input');
$('#memory_prompt_words_force').val(extension_settings.memory.promptForceWords).trigger('input');
switchSourceControls(extension_settings.memory.source);
@ -148,6 +150,13 @@ function onMemoryDepthInput() {
saveSettingsDebounced();
}
function onMemoryRoleInput() {
const value = $(this).val();
extension_settings.memory.role = Number(value);
reinsertMemory();
saveSettingsDebounced();
}
function onMemoryPositionChange(e) {
const value = e.target.value;
extension_settings.memory.position = value;
@ -480,11 +489,12 @@ function reinsertMemory() {
function setMemoryContext(value, saveToMessage) {
const context = getContext();
context.setExtensionPrompt(MODULE_NAME, formatMemoryValue(value), extension_settings.memory.position, extension_settings.memory.depth);
context.setExtensionPrompt(MODULE_NAME, formatMemoryValue(value), extension_settings.memory.position, extension_settings.memory.depth, false, extension_settings.memory.role);
$('#memory_contents').val(value);
console.log('Summary set to: ' + value);
console.debug('Position: ' + extension_settings.memory.position);
console.debug('Depth: ' + extension_settings.memory.depth);
console.debug('Role: ' + extension_settings.memory.role);
if (saveToMessage && context.chat.length) {
const idx = context.chat.length - 2;
@ -560,6 +570,7 @@ function setupListeners() {
$('#memory_force_summarize').off('click').on('click', forceSummarizeChat);
$('#memory_template').off('click').on('input', onMemoryTemplateInput);
$('#memory_depth').off('click').on('input', onMemoryDepthInput);
$('#memory_role').off('click').on('input', onMemoryRoleInput);
$('input[name="memory_position"]').off('click').on('change', onMemoryPositionChange);
$('#memory_prompt_words_force').off('click').on('input', onMemoryPromptWordsForceInput);
$('#summarySettingsBlockToggle').off('click').on('click', function () {
@ -620,9 +631,15 @@ jQuery(function () {
<input type="radio" name="memory_position" value="0" />
After Main Prompt / Story String
</label>
<label for="memory_depth" title="How many messages before the current end of the chat." data-i18n="[title]How many messages before the current end of the chat.">
<label class="flex-container alignItemsCenter" title="How many messages before the current end of the chat." data-i18n="[title]How many messages before the current end of the chat.">
<input type="radio" name="memory_position" value="1" />
In-chat @ Depth <input id="memory_depth" class="text_pole widthUnset" type="number" min="0" max="999" />
as
<select id="memory_role" class="text_pole widthNatural">
<option value="0">System</option>
<option value="1">User</option>
<option value="2">Assistant</option>
</select>
</label>
</div>
<div data-source="main" class="memory_contents_controls">

View File

@ -177,7 +177,7 @@ export class QuickReplySet {
async performSave() {
const response = await fetch('/savequickreply', {
const response = await fetch('/api/quick-replies/save', {
method: 'POST',
headers: getRequestHeaders(),
body: JSON.stringify(this),
@ -191,7 +191,7 @@ export class QuickReplySet {
}
async delete() {
const response = await fetch('/deletequickreply', {
const response = await fetch('/api/quick-replies/delete', {
method: 'POST',
headers: getRequestHeaders(),
body: JSON.stringify(this),

View File

@ -118,7 +118,7 @@ function runRegexScript(regexScript, rawString, { characterOverride } = {}) {
newString = rawString.replace(findRegex, function(match) {
const args = [...arguments];
const replaceString = regexScript.replaceString.replace(/{{match}}/gi, '$0');
const replaceWithGroups = replaceString.replaceAll(/\$(\d)+/g, (_, num) => {
const replaceWithGroups = replaceString.replaceAll(/\$(\d+)/g, (_, num) => {
// Get a full match or a capture group
const match = args[Number(num)];

View File

@ -237,6 +237,8 @@ const defaultSettings = {
novel_upscale_ratio_step: 0.1,
novel_upscale_ratio: 1.0,
novel_anlas_guard: false,
novel_sm: false,
novel_sm_dyn: false,
// OpenAI settings
openai_style: 'vivid',
@ -372,6 +374,9 @@ async function loadSettings() {
$('#sd_hr_second_pass_steps').val(extension_settings.sd.hr_second_pass_steps).trigger('input');
$('#sd_novel_upscale_ratio').val(extension_settings.sd.novel_upscale_ratio).trigger('input');
$('#sd_novel_anlas_guard').prop('checked', extension_settings.sd.novel_anlas_guard);
$('#sd_novel_sm').prop('checked', extension_settings.sd.novel_sm);
$('#sd_novel_sm_dyn').prop('checked', extension_settings.sd.novel_sm_dyn);
$('#sd_novel_sm_dyn').prop('disabled', !extension_settings.sd.novel_sm);
$('#sd_horde').prop('checked', extension_settings.sd.horde);
$('#sd_horde_nsfw').prop('checked', extension_settings.sd.horde_nsfw);
$('#sd_horde_karras').prop('checked', extension_settings.sd.horde_karras);
@ -799,6 +804,22 @@ function onNovelAnlasGuardInput() {
saveSettingsDebounced();
}
function onNovelSmInput() {
extension_settings.sd.novel_sm = !!$('#sd_novel_sm').prop('checked');
saveSettingsDebounced();
if (!extension_settings.sd.novel_sm) {
$('#sd_novel_sm_dyn').prop('checked', false).prop('disabled', true).trigger('input');
} else {
$('#sd_novel_sm_dyn').prop('disabled', false);
}
}
function onNovelSmDynInput() {
extension_settings.sd.novel_sm_dyn = !!$('#sd_novel_sm_dyn').prop('checked');
saveSettingsDebounced();
}
function onHordeNsfwInput() {
extension_settings.sd.horde_nsfw = !!$(this).prop('checked');
saveSettingsDebounced();
@ -2165,7 +2186,7 @@ async function generateAutoImage(prompt, negativePrompt) {
* @returns {Promise<{format: string, data: string}>} - A promise that resolves when the image generation and processing are complete.
*/
async function generateNovelImage(prompt, negativePrompt) {
const { steps, width, height } = getNovelParams();
const { steps, width, height, sm, sm_dyn } = getNovelParams();
const result = await fetch('/api/novelai/generate-image', {
method: 'POST',
@ -2180,6 +2201,8 @@ async function generateNovelImage(prompt, negativePrompt) {
height: height,
negative_prompt: negativePrompt,
upscale_ratio: extension_settings.sd.novel_upscale_ratio,
sm: sm,
sm_dyn: sm_dyn,
}),
});
@ -2194,16 +2217,23 @@ async function generateNovelImage(prompt, negativePrompt) {
/**
* Adjusts extension parameters for NovelAI. Applies Anlas guard if needed.
* @returns {{steps: number, width: number, height: number}} - A tuple of parameters for NovelAI API.
* @returns {{steps: number, width: number, height: number, sm: boolean, sm_dyn: boolean}} - A tuple of parameters for NovelAI API.
*/
function getNovelParams() {
let steps = extension_settings.sd.steps;
let width = extension_settings.sd.width;
let height = extension_settings.sd.height;
let sm = extension_settings.sd.novel_sm;
let sm_dyn = extension_settings.sd.novel_sm_dyn;
if (extension_settings.sd.sampler === 'ddim') {
sm = false;
sm_dyn = false;
}
// Don't apply Anlas guard if it's disabled.
if (!extension_settings.sd.novel_anlas_guard) {
return { steps, width, height };
return { steps, width, height, sm, sm_dyn };
}
const MAX_STEPS = 28;
@ -2244,7 +2274,7 @@ function getNovelParams() {
steps = MAX_STEPS;
}
return { steps, width, height };
return { steps, width, height, sm, sm_dyn };
}
async function generateOpenAiImage(prompt) {
@ -2725,6 +2755,8 @@ jQuery(async () => {
$('#sd_novel_upscale_ratio').on('input', onNovelUpscaleRatioInput);
$('#sd_novel_anlas_guard').on('input', onNovelAnlasGuardInput);
$('#sd_novel_view_anlas').on('click', onViewAnlasClick);
$('#sd_novel_sm').on('input', onNovelSmInput);
$('#sd_novel_sm_dyn').on('input', onNovelSmDynInput);;
$('#sd_comfy_validate').on('click', validateComfyUrl);
$('#sd_comfy_url').on('input', onComfyUrlInput);
$('#sd_comfy_workflow').on('change', onComfyWorkflowChange);

View File

@ -85,15 +85,9 @@
Sanitize prompts (recommended)
</span>
</label>
<label for="sd_horde_karras" class="checkbox_label">
<input id="sd_horde_karras" type="checkbox" />
<span data-i18n="Karras (not all samplers supported)">
Karras (not all samplers supported)
</span>
</label>
</div>
<div data-sd-source="novel">
<div class="flex-container">
<div class="flex-container flexFlowColumn">
<label for="sd_novel_anlas_guard" class="checkbox_label flex1" title="Automatically adjust generation parameters to ensure free image generations.">
<input id="sd_novel_anlas_guard" type="checkbox" />
<span data-i18n="Avoid spending Anlas">
@ -160,6 +154,26 @@
<select id="sd_model"></select>
<label for="sd_sampler">Sampling method</label>
<select id="sd_sampler"></select>
<label data-sd-source="horde" for="sd_horde_karras" class="checkbox_label">
<input id="sd_horde_karras" type="checkbox" />
<span data-i18n="Karras (not all samplers supported)">
Karras (not all samplers supported)
</span>
</label>
<div data-sd-source="novel" class="flex-container">
<label class="flex1 checkbox_label" title="SMEA versions of samplers are modified to perform better at high resolution.">
<input id="sd_novel_sm" type="checkbox" />
<span data-i18n="SMEA">
SMEA
</span>
</label>
<label class="flex1 checkbox_label" title="DYN variants of SMEA samplers often lead to more varied output, but may fail at very high resolutions.">
<input id="sd_novel_sm_dyn" type="checkbox" />
<span data-i18n="DYN">
DYN
</span>
</label>
</div>
<label for="sd_resolution">Resolution</label>
<select id="sd_resolution"><!-- Populated in JS --></select>
<div data-sd-source="comfy">

View File

@ -101,7 +101,9 @@ function drawChunks(chunks, ids) {
}
const color = pastelRainbow[i % pastelRainbow.length];
const chunkHtml = $(`<code style="background-color: ${color};">${chunk}</code>`);
const chunkHtml = $('<code></code>');
chunkHtml.css('background-color', color);
chunkHtml.text(chunk);
chunkHtml.attr('title', ids[i]);
$('#tokenized_chunks_display').append(chunkHtml);
}