From 668b8d171ce9d11152f832cd70a2823dd99ce396 Mon Sep 17 00:00:00 2001 From: YH_KIM Date: Sat, 12 Apr 2025 23:29:45 +0900 Subject: [PATCH 1/3] Add support for NovelAI V4 model and configuration settings --- src/lib/Setting/Pages/OtherBotSettings.svelte | 99 ++++++--- src/ts/process/stableDiff.ts | 190 ++++++------------ src/ts/storage/database.svelte.ts | 58 +++++- 3 files changed, 198 insertions(+), 149 deletions(-) diff --git a/src/lib/Setting/Pages/OtherBotSettings.svelte b/src/lib/Setting/Pages/OtherBotSettings.svelte index 836748e4..48577984 100644 --- a/src/lib/Setting/Pages/OtherBotSettings.svelte +++ b/src/lib/Setting/Pages/OtherBotSettings.svelte @@ -35,7 +35,25 @@ image: '', InfoExtracted: 0.5, RefStrength: 0.5, - refimage: '' + refimage: '', + autoSmea:false, + legacy_uc:false, + use_coords:false, + v4_prompt:{ + caption:{ + base_caption:'', + char_captions:[] + }, + use_coords:false, + use_order:true + }, + v4_negative_prompt:{ + caption:{ + base_caption:'', + char_captions:[] + }, + legacy_uc:false, + } } if (DBState.db.NAIImgConfig.sampler === 'ddim_v3'){ DBState.db.NAIImgConfig.sm = false @@ -43,7 +61,7 @@ } }); - let submenu = $state(DBState.db.useLegacyGUI ? -1 : 0) + let submenu = $state(DBState.db.useLegacyGUI ? -1 : 0); // HypaV3 $effect(() => { @@ -88,6 +106,14 @@ return parseFloat(maxMemoryRatio.toFixed(2)); } // End HypaV3 + + // add init NAI V4 + // if(DBState.db.NAIImgConfig.autoSmea === undefined) DBState.db.NAIImgConfig.autoSmea = false; + // if(DBState.db.NAIImgConfig.use_coords === undefined) DBState.db.NAIImgConfig.use_coords = false; + // if(DBState.db.NAIImgConfig.v4_prompt.use_coords === undefined) DBState.db.NAIImgConfig.v4_prompt.use_coords = false; + // if(DBState.db.NAIImgConfig.v4_prompt.use_order === undefined) DBState.db.NAIImgConfig.v4_prompt.use_order = false; + // if(DBState.db.NAIImgConfig.v4_negative_prompt.legacy_uc === undefined) DBState.db.NAIImgConfig.v4_negative_prompt.legacy_uc = false; +

{language.otherBots}

@@ -168,50 +194,75 @@ {/if} {/if} - + {#if DBState.db.sdProvider === 'novelai'} Novel AI {language.providerURL} API Key - + Model - - + + Width Height Sampler - - Euler - Euler Ancestral - DPM++ 2S Ancestral - DPM++ 2M - DPM++ SDE - DPM++ 2S - DDIM - + + {#if DBState.db.NAIImgModel === 'nai-diffusion-4-full'} + + (Recommended)Euler Ancestral + (Recommended)DPM++ 2S Ancestral + (Recommended)DPM++ 2M SDE + (Other)Euler + (Other)DPM++ 2M + (Other)DPM++ SDE + + {:else} + + Euler + Euler Ancestral + DPM++ 2S Ancestral + DPM++ 2M + DPM++ SDE + DPM++ 2S + DDIM + + {/if} + steps CFG scale - + {#if !DBState.db.NAII2I || DBState.db.NAIImgConfig.sampler !== 'ddim_v3'} + {:else if DBState.db.NAIImgModel !== 'nai-diffusion-4-full'} {/if} - + + {#if DBState.db.NAIImgModel === 'nai-diffusion-4-full'} + + + + + + + + + {/if} + {#if DBState.db.NAII2I} - + Strength {DBState.db.NAIImgConfig.strength} Noise {DBState.db.NAIImgConfig.noise} - + Base image - + {/if} @@ -273,8 +324,8 @@ {:else} {#await getCharImage(DBState.db.NAIImgConfig.refimage, 'css')}
- {:then im} -
+ {:then im} +
{/await} {/if} diff --git a/src/ts/process/stableDiff.ts b/src/ts/process/stableDiff.ts index 3b5ce4bf..5fe1ba1f 100644 --- a/src/ts/process/stableDiff.ts +++ b/src/ts/process/stableDiff.ts @@ -1,5 +1,5 @@ import { get } from "svelte/store" -import { getDatabase, type character } from "../storage/database.svelte" +import { getDatabase, type character, type NAIImgConfig } from "../storage/database.svelte" import { requestChatData } from "./request" import { alertError } from "../alert" import { fetchNative, globalFetch, readImage } from "../globalApi.svelte" @@ -125,6 +125,62 @@ export async function generateAIImage(genPrompt:string, currentChar:character, n let reqlist:any = {} + const commonReq = { + body: { + "input": genPrompt, + "model": db.NAIImgModel, + "parameters": { + "params_version": 3, + "add_original_image": true, + "cfg_rescale": 0, + "controlnet_strength": 1, + "dynamic_thresholding": false, + "n_samples": 1, + "width": db.NAIImgConfig.width, + "height": db.NAIImgConfig.height, + "sampler": db.NAIImgConfig.sampler, + "steps": db.NAIImgConfig.steps, + "scale": db.NAIImgConfig.scale, + "negative_prompt": neg, + "sm": false, + "sm_dyn": false, + "noise": db.NAIImgConfig.noise, + "noise_schedule": "native", + "strength": db.NAIImgConfig.strength, + "ucPreset": 3, + "uncond_scale": 1, + "qualityToggle": false, + "lagacy_v3_extend": false, + "lagacy": false, + "reference_information_extracted": db.NAIImgConfig.InfoExtracted, + "reference_strength": db.NAIImgConfig.RefStrength, + //add v4 + "autoSmea": db.NAIImgConfig.autoSmea || false, + use_coords: db.NAIImgConfig.use_coords || false, + legacy_uc: db.NAIImgConfig.legacy_uc || false, + v4_prompt:{ + caption:{ + base_caption:genPrompt, + char_captions: [] + }, + use_coords: false,//db.NAIImgConfig.v4_prompt.use_coords || false, + use_order: true//db.NAIImgConfig.v4_prompt.use_order || true + }, + "v4_negative_prompt":{ + caption:{ + base_caption:neg, + char_captions: [] + }, + legacy_uc: false//db.NAIImgConfig.v4_negative_prompt.legacy_uc || false, + } + } + }, + headers:{ + "Authorization": "Bearer " + db.NAIApiKey + }, + rawResponse: true + } + if(db.NAII2I){ let seed = Math.floor(Math.random() * 10000000000) @@ -139,9 +195,6 @@ export async function generateAIImage(genPrompt:string, currentChar:character, n } let refimgbase64 = undefined - - - if(db.NAIREF){ if(db.NAIImgConfig.refimage !== ''){ @@ -149,56 +202,19 @@ export async function generateAIImage(genPrompt:string, currentChar:character, n } } - reqlist = { - body: { - "action": "img2img", - "input": genPrompt, - "model": db.NAIImgModel, - "parameters": { - "params_version": 1, - "add_original_image": true, - "cfg_rescale": 0, - "controlnet_strength": 1, - "dynamic_thresholding": false, - "extra_noise_seed": seed, - "n_samples": 1, - "width": db.NAIImgConfig.width, - "height": db.NAIImgConfig.height, - "sampler": db.NAIImgConfig.sampler, - "steps": db.NAIImgConfig.steps, - "scale": db.NAIImgConfig.scale, - "seed": seed, - "negative_prompt": neg, - "sm": false, - "sm_dyn": false, - "noise": db.NAIImgConfig.noise, - "noise_schedule": "native", - "strength": db.NAIImgConfig.strength, - "image": base64img, - "ucPreset": 3, - "uncond_scale": 1, - "qualityToggle": false, - "lagacy_v3_extend": false, - "lagacy": false, - "reference_information_extracted": db.NAIImgConfig.InfoExtracted, - "reference_strength": db.NAIImgConfig.RefStrength - } - }, - headers:{ - "Authorization": "Bearer " + db.NAIApiKey - }, - rawResponse: true - } + reqlist = commonReq; + reqlist.body.action = "img2img"; + reqlist.body.parameters.image = base64img; + reqlist.body.parameters.extra_noise_seed = seed; + reqlist.body.parameters.seed = seed; if(refimgbase64 !== undefined){ reqlist.body.parameters.reference_image = refimgbase64 } }else{ - if (db.NAIREF) { - - + let base64img = '' if(db.NAIImgConfig.image === ''){ const charimg = currentChar.image; @@ -208,84 +224,12 @@ export async function generateAIImage(genPrompt:string, currentChar:character, n } else{ base64img = Buffer.from(await readImage(db.NAIImgConfig.refimage)).toString('base64'); } - reqlist = { - body: { - "action": "generate", - "input": genPrompt, - "model": db.NAIImgModel, - "parameters": { - "params_version": 1, - "add_original_image": true, - "cfg_rescale": 0, - "controlnet_strength": 1, - "dynamic_thresholding": false, - "n_samples": 1, - "width": db.NAIImgConfig.width, - "height": db.NAIImgConfig.height, - "sampler": db.NAIImgConfig.sampler, - "steps": db.NAIImgConfig.steps, - "scale": db.NAIImgConfig.scale, - "negative_prompt": neg, - "sm": db.NAIImgConfig.sm, - "sm_dyn": db.NAIImgConfig.sm_dyn, - "noise_schedule": "native", - "ucPreset": 3, - "uncond_scale": 1, - "qualityToggle": false, - "legacy": false, - "lagacy_v3_extend": false, - "reference_image": base64img, - "reference_strength": db.NAIImgConfig.RefStrength, - "reference_information_extracted": db.NAIImgConfig.InfoExtracted - } - }, - headers:{ - "Authorization": "Bearer " + db.NAIApiKey - }, - rawResponse: true - } + reqlist = commonReq; + reqlist.body.action = 'generate'; + reqlist.body.parameters.reference_image = base64img; } else { - reqlist = { - body: { - "input": genPrompt, - "model": db.NAIImgModel, - "parameters": { - "params_version": 1, - "width": db.NAIImgConfig.width, - "height": db.NAIImgConfig.height, - "scale": db.NAIImgConfig.scale, - "sampler": db.NAIImgConfig.sampler, - "steps": db.NAIImgConfig.steps, - "n_samples": 1, - "ucPreset": 3, - "qualityToggle": false, - "sm": db.NAIImgConfig.sm, - "sm_dyn": db.NAIImgConfig.sm_dyn, - "dynamic_thresholding": false, - "controlnet_strength": 1, - "legacy": false, - "add_original_image": true, - "uncond_scale": 1, - "cfg_rescale": 0, - "noise_schedule": "native", - "legacy_v3_extend": false, - "reference_information_extracted": db.NAIImgConfig.InfoExtracted, - "reference_strength": db.NAIImgConfig.RefStrength, - "negative_prompt": neg, - } - }, - headers:{ - "Authorization": "Bearer " + db.NAIApiKey - }, - rawResponse: true - - } + reqlist = commonReq; } - - - - - } try { const da = await globalFetch(db.NAIImgUrl, reqlist) diff --git a/src/ts/storage/database.svelte.ts b/src/ts/storage/database.svelte.ts index 8da25e4a..809ea782 100644 --- a/src/ts/storage/database.svelte.ts +++ b/src/ts/storage/database.svelte.ts @@ -264,7 +264,26 @@ export function setDatabase(data:Database){ image:"", refimage:"", InfoExtracted:1, - RefStrength:0.4 + RefStrength:0.4, + //add 4 + autoSmea:false, + legacy_uc:false, + use_coords:false, + v4_prompt:{ + caption:{ + base_caption:'', + char_captions:[] + }, + use_coords:false, + use_order:true + }, + v4_negative_prompt:{ + caption:{ + base_caption:'', + char_captions:[] + }, + legacy_uc:false, + } } } if(checkNullish(data.customTextTheme)){ @@ -1363,7 +1382,7 @@ interface sdConfig{ hr_upscaler:string } -interface NAIImgConfig{ +export interface NAIImgConfig{ width:number, height:number, sampler:string, @@ -1377,8 +1396,43 @@ interface NAIImgConfig{ refimage:string, InfoExtracted:number, RefStrength:number + //add 4 + autoSmea:boolean, + use_coords:boolean, + legacy_uc: boolean, + v4_prompt:NAIImgConfigV4Prompt, + v4_negative_prompt:NAIImgConfigV4NegativePrompt, + } +//add 4 +interface NAIImgConfigV4Prompt{ + caption: NAIImgConfigV4Caption, + use_coords: boolean, + use_order: boolean +} +//add 4 +interface NAIImgConfigV4NegativePrompt{ + caption: NAIImgConfigV4Caption, + legacy_uc: boolean +} +//add 4 +interface NAIImgConfigV4Caption{ + base_caption: string, + char_captions: NAIImgConfigV4CharCaption[] +} +//add 4 +interface NAIImgConfigV4CharCaption{ + char_caption: string, + centers: + { + x: number, + y: number + }[] + +} + + interface ComfyConfig{ workflow:string, posNodeID: string, From d11bff3f8033b20c4af84793ceab56cb4f53acb1 Mon Sep 17 00:00:00 2001 From: YH_KIM Date: Mon, 14 Apr 2025 04:38:47 +0900 Subject: [PATCH 2/3] Add support for NAI v4 model configuration and inputs --- src/lib/Setting/Pages/OtherBotSettings.svelte | 28 +++++++++++++++---- src/ts/process/stableDiff.ts | 16 +++++++---- src/ts/storage/database.svelte.ts | 23 +++++++++++++-- 3 files changed, 53 insertions(+), 14 deletions(-) diff --git a/src/lib/Setting/Pages/OtherBotSettings.svelte b/src/lib/Setting/Pages/OtherBotSettings.svelte index 48577984..3a29f5ed 100644 --- a/src/lib/Setting/Pages/OtherBotSettings.svelte +++ b/src/lib/Setting/Pages/OtherBotSettings.svelte @@ -107,6 +107,8 @@ } // End HypaV3 + let imageModel = ''; + // add init NAI V4 // if(DBState.db.NAIImgConfig.autoSmea === undefined) DBState.db.NAIImgConfig.autoSmea = false; // if(DBState.db.NAIImgConfig.use_coords === undefined) DBState.db.NAIImgConfig.use_coords = false; @@ -203,6 +205,17 @@ Model + { + DBState.db.NAIImgModel = imageModel; + }}> + 선택하여 자동입력 + nai-diffusion-4-full + nai-diffusion-4-curated-preview + nai-diffusion-3 + nai-diffusion-furry-3 + nai-diffusion-2 + + Width @@ -210,7 +223,8 @@ Sampler - {#if DBState.db.NAIImgModel === 'nai-diffusion-4-full'} + {#if DBState.db.NAIImgModel === 'nai-diffusion-4-full' + || DBState.db.NAIImgModel === 'nai-diffusion-4-curated-preview'} (Recommended)Euler Ancestral (Recommended)DPM++ 2S Ancestral @@ -238,20 +252,22 @@ {#if !DBState.db.NAII2I || DBState.db.NAIImgConfig.sampler !== 'ddim_v3'} - {:else if DBState.db.NAIImgModel !== 'nai-diffusion-4-full'} + {:else if DBState.db.NAIImgModel === 'nai-diffusion-4-full' + || DBState.db.NAIImgModel === 'nai-diffusion-4-curated-preview'} {/if} - {#if DBState.db.NAIImgModel === 'nai-diffusion-4-full'} + {#if DBState.db.NAIImgModel === 'nai-diffusion-4-full' + || DBState.db.NAIImgModel === 'nai-diffusion-4-curated-preview'} - - + + - + {/if} {#if DBState.db.NAII2I} diff --git a/src/ts/process/stableDiff.ts b/src/ts/process/stableDiff.ts index 5fe1ba1f..fb24033a 100644 --- a/src/ts/process/stableDiff.ts +++ b/src/ts/process/stableDiff.ts @@ -155,23 +155,23 @@ export async function generateAIImage(genPrompt:string, currentChar:character, n "reference_information_extracted": db.NAIImgConfig.InfoExtracted, "reference_strength": db.NAIImgConfig.RefStrength, //add v4 - "autoSmea": db.NAIImgConfig.autoSmea || false, - use_coords: db.NAIImgConfig.use_coords || false, - legacy_uc: db.NAIImgConfig.legacy_uc || false, + "autoSmea": db.NAIImgConfig.autoSmea, + use_coords: db.NAIImgConfig.use_coords, + legacy_uc: db.NAIImgConfig.legacy_uc, v4_prompt:{ caption:{ base_caption:genPrompt, char_captions: [] }, - use_coords: false,//db.NAIImgConfig.v4_prompt.use_coords || false, - use_order: true//db.NAIImgConfig.v4_prompt.use_order || true + use_coords: db.NAIImgConfig.v4_prompt.use_coords, + use_order: db.NAIImgConfig.v4_prompt.use_order }, "v4_negative_prompt":{ caption:{ base_caption:neg, char_captions: [] }, - legacy_uc: false//db.NAIImgConfig.v4_negative_prompt.legacy_uc || false, + legacy_uc: db.NAIImgConfig.v4_negative_prompt.legacy_uc, } } }, @@ -211,6 +211,7 @@ export async function generateAIImage(genPrompt:string, currentChar:character, n if(refimgbase64 !== undefined){ reqlist.body.parameters.reference_image = refimgbase64 } + console.log({img2img:reqlist}); }else{ if (db.NAIREF) { @@ -227,8 +228,11 @@ export async function generateAIImage(genPrompt:string, currentChar:character, n reqlist = commonReq; reqlist.body.action = 'generate'; reqlist.body.parameters.reference_image = base64img; + console.log({generate:reqlist}); } else { reqlist = commonReq; + reqlist.body.action = 'generate'; + console.log({nothing:reqlist}); } } try { diff --git a/src/ts/storage/database.svelte.ts b/src/ts/storage/database.svelte.ts index 809ea782..cc3723b7 100644 --- a/src/ts/storage/database.svelte.ts +++ b/src/ts/storage/database.svelte.ts @@ -286,6 +286,27 @@ export function setDatabase(data:Database){ } } } + //add NAI v4 (사용중인 사람용 추가 DB Init) + if(checkNullish(data.NAIImgConfig.v4_prompt)){ + data.NAIImgConfig.autoSmea = false; + data.NAIImgConfig.use_coords = false; + data.NAIImgConfig.legacy_uc = false; + data.NAIImgConfig.v4_prompt = { + caption:{ + base_caption:"", + char_captions:[] + }, + use_coords:false, + use_order:true + }; + data.NAIImgConfig.v4_negative_prompt = { + caption:{ + base_caption:"", + char_captions:[] + }, + legacy_uc:false, + }; + } if(checkNullish(data.customTextTheme)){ data.customTextTheme = { FontColorStandard: "#f8f8f2", @@ -1429,10 +1450,8 @@ interface NAIImgConfigV4CharCaption{ x: number, y: number }[] - } - interface ComfyConfig{ workflow:string, posNodeID: string, From 517b2ff86b296cea4c3c6d8ff67820c3f30dcfb0 Mon Sep 17 00:00:00 2001 From: YH_KIM Date: Mon, 14 Apr 2025 04:49:13 +0900 Subject: [PATCH 3/3] Update placeholder text for image model selection --- src/lib/Setting/Pages/OtherBotSettings.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/Setting/Pages/OtherBotSettings.svelte b/src/lib/Setting/Pages/OtherBotSettings.svelte index 3a29f5ed..13b8e9bd 100644 --- a/src/lib/Setting/Pages/OtherBotSettings.svelte +++ b/src/lib/Setting/Pages/OtherBotSettings.svelte @@ -208,7 +208,7 @@ { DBState.db.NAIImgModel = imageModel; }}> - 선택하여 자동입력 + Choose... nai-diffusion-4-full nai-diffusion-4-curated-preview nai-diffusion-3