Use deepMerge to combine payloads
This commit is contained in:
parent
301a31b8b2
commit
a3693ccf6d
|
@ -18,7 +18,7 @@ import {
|
|||
} from '../../../script.js';
|
||||
import { getApiUrl, getContext, extension_settings, doExtrasFetch, modules, renderExtensionTemplateAsync, writeExtensionField } from '../../extensions.js';
|
||||
import { selected_group } from '../../group-chats.js';
|
||||
import { stringFormat, initScrollHeight, resetScrollHeight, getCharaFilename, saveBase64AsFile, getBase64Async, delay, isTrueBoolean, debounce, isFalseBoolean } from '../../utils.js';
|
||||
import { stringFormat, initScrollHeight, resetScrollHeight, getCharaFilename, saveBase64AsFile, getBase64Async, delay, isTrueBoolean, debounce, isFalseBoolean, deepMerge } from '../../utils.js';
|
||||
import { getMessageTimeStamp, humanizedDateTime } from '../../RossAscends-mods.js';
|
||||
import { SECRET_KEYS, secret_state, writeSecret } from '../../secrets.js';
|
||||
import { getNovelUnlimitedImageGeneration, getNovelAnlas, loadNovelSubscriptionData } from '../../nai-settings.js';
|
||||
|
@ -219,7 +219,7 @@ const defaultSettings = {
|
|||
// Automatic1111/Horde exclusives
|
||||
restore_faces: false,
|
||||
enable_hr: false,
|
||||
aiFaceDetailer: false,
|
||||
adetailer_face: false,
|
||||
|
||||
// Horde settings
|
||||
horde: false,
|
||||
|
@ -436,7 +436,7 @@ async function loadSettings() {
|
|||
$('#sd_horde_sanitize').prop('checked', extension_settings.sd.horde_sanitize);
|
||||
$('#sd_restore_faces').prop('checked', extension_settings.sd.restore_faces);
|
||||
$('#sd_enable_hr').prop('checked', extension_settings.sd.enable_hr);
|
||||
$('#sd_aiFaceDetailer').prop('checked', extension_settings.sd.aiFaceDetailer);
|
||||
$('#sd_adetailer_face').prop('checked', extension_settings.sd.adetailer_face);
|
||||
$('#sd_refine_mode').prop('checked', extension_settings.sd.refine_mode);
|
||||
$('#sd_multimodal_captioning').prop('checked', extension_settings.sd.multimodal_captioning);
|
||||
$('#sd_auto_url').val(extension_settings.sd.auto_url);
|
||||
|
@ -855,8 +855,8 @@ function onSamplerChange() {
|
|||
saveSettingsDebounced();
|
||||
}
|
||||
|
||||
function onAiFaceDetailerChange() {
|
||||
extension_settings.sd.aiFaceDetailer = $('#sd_aiFaceDetailer').prop('checked');
|
||||
function onADetailerFaceChange() {
|
||||
extension_settings.sd.adetailer_face = !!$('#sd_adetailer_face').prop('checked');
|
||||
saveSettingsDebounced();
|
||||
}
|
||||
|
||||
|
@ -2955,20 +2955,22 @@ async function generateAutoImage(prompt, negativePrompt, signal) {
|
|||
do_not_save_grid: false,
|
||||
do_not_save_samples: false,
|
||||
};
|
||||
// Conditionally add the ADetailer if aiFaceDetailer is enabled
|
||||
console.log('extension_settings.sd.aiFaceDetailer:', extension_settings.sd.aiFaceDetailer);
|
||||
if (extension_settings.sd.aiFaceDetailer) {
|
||||
payload.alwayson_scripts = {
|
||||
ADetailer: {
|
||||
args: [
|
||||
true, // ad_enable
|
||||
true, // skip_img2img
|
||||
{
|
||||
"ad_model": "face_yolov8n.pt"
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
// Conditionally add the ADetailer if adetailer_face is enabled
|
||||
if (extension_settings.sd.adetailer_face) {
|
||||
payload = deepMerge(payload, {
|
||||
alwayson_scripts: {
|
||||
ADetailer: {
|
||||
args: [
|
||||
true, // ad_enable
|
||||
true, // skip_img2img
|
||||
{
|
||||
'ad_model': 'face_yolov8n.pt',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Make the fetch call with the payload
|
||||
|
@ -2979,8 +2981,6 @@ async function generateAutoImage(prompt, negativePrompt, signal) {
|
|||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
|
||||
|
||||
if (result.ok) {
|
||||
const data = await result.json();
|
||||
return { format: 'png', data: data.images[0] };
|
||||
|
@ -4210,7 +4210,7 @@ jQuery(async () => {
|
|||
$('#sd_horde_sanitize').on('input', onHordeSanitizeInput);
|
||||
$('#sd_restore_faces').on('input', onRestoreFacesInput);
|
||||
$('#sd_enable_hr').on('input', onHighResFixInput);
|
||||
$('#sd_aiFaceDetailer').on('change', onAiFaceDetailerChange);
|
||||
$('#sd_adetailer_face').on('change', onADetailerFaceChange);
|
||||
$('#sd_refine_mode').on('input', onRefineModeInput);
|
||||
$('#sd_character_prompt').on('input', onCharacterPromptInput);
|
||||
$('#sd_character_negative_prompt').on('input', onCharacterNegativePromptInput);
|
||||
|
|
|
@ -354,11 +354,16 @@
|
|||
<small data-i18n="Karras">Karras</small>
|
||||
<i class="fa-solid fa-info-circle fa-sm opacity50p" data-i18n="[title]Not all samplers supported." title="Not all samplers supported."></i>
|
||||
</label>
|
||||
<label for="sd_aiFaceDetailer" class="checkbox_label" data-i18n="[title]sd_aiFaceDetailer" title="Use AI Face Detailer in image generation.">
|
||||
<input id="sd_aiFaceDetailer" type="checkbox" />
|
||||
<small data-i18n="sd_aiFaceDetailer">Use AI Face Detailer</small>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="flex-container marginTopBot5" data-sd-source="auto">
|
||||
<label for="sd_adetailer_face" class="flex1 checkbox_label" data-i18n="[title]sd_adetailer_face" title="Use ADetailer with face model during the generation. The ADetailer extension must be installed on the backend.">
|
||||
<input id="sd_adetailer_face" type="checkbox" />
|
||||
<small data-i18n="Use ADetailer (Face)">Use ADetailer (Face)</small>
|
||||
</label>
|
||||
<div class="flex1">
|
||||
<!-- I will be useful later! -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex-container marginTopBot5" data-sd-source="novel">
|
||||
|
|
|
@ -23,6 +23,38 @@ export const navigation_option = {
|
|||
previous: -1000,
|
||||
};
|
||||
|
||||
/**
|
||||
* Determines if a value is an object.
|
||||
* @param {any} item The item to check.
|
||||
* @returns {boolean} True if the item is an object, false otherwise.
|
||||
*/
|
||||
function isObject(item) {
|
||||
return (item && typeof item === 'object' && !Array.isArray(item));
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges properties of two objects. If the property is an object, it will be merged recursively.
|
||||
* @param {object} target The target object
|
||||
* @param {object} source The source object
|
||||
* @returns {object} Merged object
|
||||
*/
|
||||
export function deepMerge(target, source) {
|
||||
let output = Object.assign({}, target);
|
||||
if (isObject(target) && isObject(source)) {
|
||||
Object.keys(source).forEach(key => {
|
||||
if (isObject(source[key])) {
|
||||
if (!(key in target))
|
||||
Object.assign(output, { [key]: source[key] });
|
||||
else
|
||||
output[key] = deepMerge(target[key], source[key]);
|
||||
} else {
|
||||
Object.assign(output, { [key]: source[key] });
|
||||
}
|
||||
});
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
export function escapeHtml(str) {
|
||||
return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue