Code updates due to NAI API changes and feature additions.
This commit is contained in:
@@ -69,7 +69,7 @@
|
||||
|
||||
{#if $DataBase.sdProvider === 'novelai'}
|
||||
<span class="text-textcolor mt-2">Novel AI {language.providerURL}</span>
|
||||
<TextInput size="sm" marginBottom placeholder="https://api.novelai.net" bind:value={$DataBase.NAIImgUrl}/>
|
||||
<TextInput size="sm" marginBottom placeholder="https://image.novelai.net" bind:value={$DataBase.NAIImgUrl}/>
|
||||
<span class="text-textcolor">API Key</span>
|
||||
<TextInput size="sm" marginBottom placeholder="pst-..." bind:value={$DataBase.NAIApiKey}/>
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
<span class="text-textcolor">CFG scale</span>
|
||||
<NumberInput size="sm" marginBottom min={0} max={2048} bind:value={$DataBase.NAIImgConfig.scale}/>
|
||||
|
||||
{#if !$DataBase.NAII2I || $DataBase.NAIImgConfig.sampler === 'ddim_v3'}
|
||||
{#if !$DataBase.NAII2I || $DataBase.NAIImgConfig.sampler !== 'ddim_v3'}
|
||||
<Check bind:check={$DataBase.NAIImgConfig.sm} name="Use SMEA"/>
|
||||
<Check bind:check={$DataBase.NAIImgConfig.sm_dyn} name='Use DYN'/>
|
||||
{/if}
|
||||
@@ -103,10 +103,10 @@
|
||||
|
||||
{#if $DataBase.NAII2I}
|
||||
|
||||
<span class="text-textcolor mt-4">strength</span>
|
||||
<span class="text-textcolor mt-4">Strength</span>
|
||||
<SliderInput min={0} max={0.99} step={0.01} bind:value={$DataBase.NAIImgConfig.strength}/>
|
||||
<span class="text-textcolor2 mb-6 text-sm">{$DataBase.NAIImgConfig.strength}</span>
|
||||
<span class="text-textcolor">noise</span>
|
||||
<span class="text-textcolor">Noise</span>
|
||||
<SliderInput min={0} max={0.99} step={0.01} bind:value={$DataBase.NAIImgConfig.noise}/>
|
||||
<span class="text-textcolor2 mb-6 text-sm">{$DataBase.NAIImgConfig.noise}</span>
|
||||
|
||||
@@ -136,6 +136,47 @@
|
||||
</button>
|
||||
|
||||
{/if}
|
||||
|
||||
<Check bind:check={$DataBase.NAIREF} name="Enable Reference" className="mt-4"/>
|
||||
|
||||
{#if $DataBase.NAIREF}
|
||||
|
||||
|
||||
<span class="text-textcolor mt-4">Information Extracted</span>
|
||||
<SliderInput min={0} max={1} step={0.01} bind:value={$DataBase.NAIImgConfig.InfoExtracted}/>
|
||||
<span class="text-textcolor2 mb-6 text-sm">{$DataBase.NAIImgConfig.InfoExtracted}</span>
|
||||
<span class="text-textcolor">Reference Strength</span>
|
||||
<SliderInput min={0} max={1} step={0.01} bind:value={$DataBase.NAIImgConfig.RefStrength}/>
|
||||
<span class="text-textcolor2 mb-6 text-sm">{$DataBase.NAIImgConfig.RefStrength}</span>
|
||||
|
||||
|
||||
|
||||
|
||||
<span class="text-textcolor">Reference image</span>
|
||||
<button on:click={async () => {
|
||||
const img = await selectSingleFile([
|
||||
'jpg',
|
||||
'jpeg',
|
||||
'png',
|
||||
'webp'
|
||||
])
|
||||
if(!img){
|
||||
return null
|
||||
}
|
||||
const saveId = await saveAsset(img.data)
|
||||
$DataBase.NAIImgConfig.refimage = saveId
|
||||
}}>
|
||||
{#if $DataBase.NAIImgConfig.refimage === ''}
|
||||
<div class="rounded-md h-20 w-20 shadow-lg bg-textcolor2 cursor-pointer hover:text-green-500"/>
|
||||
{:else}
|
||||
{#await getCharImage($DataBase.NAIImgConfig.refimage, 'css')}
|
||||
<div class="rounded-md h-20 w-20 shadow-lg bg-textcolor2 cursor-pointer hover:text-green-500"/>
|
||||
{:then im}
|
||||
<div class="rounded-md h-20 w-20 shadow-lg bg-textcolor2 cursor-pointer hover:text-green-500" style={im} />
|
||||
{/await}
|
||||
{/if}
|
||||
</button>
|
||||
{/if}
|
||||
{/if}
|
||||
</Arcodion>
|
||||
|
||||
|
||||
@@ -112,18 +112,19 @@ export async function generateAIImage(genPrompt:string, currentChar:character, n
|
||||
}
|
||||
}
|
||||
if(db.sdProvider === 'novelai'){
|
||||
genPrompt = genPrompt
|
||||
.replaceAll('\\(', "♧")
|
||||
.replaceAll('\\)', "♤")
|
||||
.replaceAll('(','{')
|
||||
.replaceAll(')','}')
|
||||
.replaceAll('♧','(')
|
||||
.replaceAll('♤',')')
|
||||
|
||||
let reqlist= {}
|
||||
let reqlist:any = {}
|
||||
|
||||
if(db.NAII2I){
|
||||
genPrompt = genPrompt
|
||||
.replaceAll('\\(', "♧")
|
||||
.replaceAll('\\)', "♤")
|
||||
.replaceAll('(','{')
|
||||
.replaceAll(')','}')
|
||||
.replaceAll('♧','(')
|
||||
.replaceAll('♤',')')
|
||||
|
||||
let seed = Math.floor(Math.random() * 10000000000)
|
||||
|
||||
let base64img = ''
|
||||
if(db.NAIImgConfig.image === ''){
|
||||
const charimg = currentChar.image;
|
||||
@@ -133,26 +134,37 @@ export async function generateAIImage(genPrompt:string, currentChar:character, n
|
||||
} else{
|
||||
base64img = Buffer.from(await readImage(db.NAIImgConfig.image)).toString('base64');
|
||||
}
|
||||
|
||||
let refimgbase64 = undefined
|
||||
|
||||
|
||||
|
||||
|
||||
if(db.NAIREF){
|
||||
if(db.NAIImgConfig.refimage !== ''){
|
||||
refimgbase64 = Buffer.from(await readImage(db.NAIImgConfig.refimage)).toString('base64');
|
||||
}
|
||||
}
|
||||
|
||||
let seed = Math.floor(Math.random() * 10000000000)
|
||||
reqlist = {
|
||||
body: {
|
||||
"action": "img2img",
|
||||
"input": genPrompt,
|
||||
"model": db.NAIImgModel,
|
||||
"parameters": {
|
||||
"seed": seed,
|
||||
"extra_noise_seed": seed,
|
||||
"add_original_image": false,
|
||||
"params_version": 1,
|
||||
"add_original_image": true,
|
||||
"cfg_rescale": 0,
|
||||
"controlnet_strength": 1,
|
||||
"dynamic_threshold": false,
|
||||
"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,
|
||||
@@ -160,8 +172,13 @@ export async function generateAIImage(genPrompt:string, currentChar:character, n
|
||||
"noise_schedule": "native",
|
||||
"strength": db.NAIImgConfig.strength,
|
||||
"image": base64img,
|
||||
"ucPreset": 2,
|
||||
"uncond_scale": 1
|
||||
"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:{
|
||||
@@ -169,28 +186,103 @@ export async function generateAIImage(genPrompt:string, currentChar:character, n
|
||||
},
|
||||
rawResponse: true
|
||||
}
|
||||
|
||||
if(refimgbase64 !== undefined){
|
||||
reqlist.body.parameters.reference_image = refimgbase64
|
||||
}
|
||||
}else{
|
||||
reqlist = {
|
||||
body: {
|
||||
"input": genPrompt,
|
||||
"model": db.NAIImgModel,
|
||||
"parameters": {
|
||||
"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
|
||||
}
|
||||
},
|
||||
headers:{
|
||||
"Authorization": "Bearer " + db.NAIApiKey
|
||||
},
|
||||
rawResponse: true
|
||||
|
||||
|
||||
if (db.NAIREF) {
|
||||
|
||||
|
||||
let base64img = ''
|
||||
if(db.NAIImgConfig.image === ''){
|
||||
const charimg = currentChar.image;
|
||||
|
||||
const img = await readImage(charimg)
|
||||
base64img = Buffer.from(img).toString('base64');
|
||||
} 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
|
||||
}
|
||||
} 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
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
try {
|
||||
const da = await globalFetch(db.NAIImgUrl, reqlist)
|
||||
|
||||
@@ -175,7 +175,7 @@ export function setDatabase(data:Database){
|
||||
data.sdCFG = 7
|
||||
}
|
||||
if(checkNullish(data.NAIImgUrl)){
|
||||
data.NAIImgUrl = 'https://api.novelai.net/ai/generate-image'
|
||||
data.NAIImgUrl = 'https://image.novelai.net/ai/generate-image'
|
||||
}
|
||||
if(checkNullish(data.NAIApiKey)){
|
||||
data.NAIApiKey = ''
|
||||
@@ -184,7 +184,10 @@ export function setDatabase(data:Database){
|
||||
data.NAIImgModel = 'nai-diffusion-3'
|
||||
}
|
||||
if(checkNullish(data.NAII2I)){
|
||||
data.NAII2I = true
|
||||
data.NAII2I = false
|
||||
}
|
||||
if(checkNullish(data.NAIREF)){
|
||||
data.NAIREF = false
|
||||
}
|
||||
if(checkNullish(data.textTheme)){
|
||||
data.textTheme = "standard"
|
||||
@@ -251,10 +254,13 @@ export function setDatabase(data:Database){
|
||||
steps:28,
|
||||
scale:5,
|
||||
sm:true,
|
||||
sm_dyn:true,
|
||||
sm_dyn:false,
|
||||
noise:0.0,
|
||||
strength:0.6,
|
||||
image:""
|
||||
image:"",
|
||||
refimage:"",
|
||||
InfoExtracted:1,
|
||||
RefStrength:0.4
|
||||
}
|
||||
}
|
||||
if(checkNullish(data.customTextTheme)){
|
||||
@@ -447,6 +453,7 @@ export interface Database{
|
||||
NAIApiKey:string
|
||||
NAIImgModel:string
|
||||
NAII2I:boolean
|
||||
NAIREF:boolean
|
||||
NAIImgConfig:NAIImgConfig
|
||||
runpodKey:string
|
||||
promptPreprocess:boolean
|
||||
@@ -829,7 +836,10 @@ interface NAIImgConfig{
|
||||
sm_dyn:boolean,
|
||||
noise:number,
|
||||
strength:number,
|
||||
image:string
|
||||
image:string,
|
||||
refimage:string,
|
||||
InfoExtracted:number,
|
||||
RefStrength:number
|
||||
}
|
||||
export type FormatingOrderItem = 'main'|'jailbreak'|'chats'|'lorebook'|'globalNote'|'authorNote'|'lastChat'|'description'|'postEverything'|'personaPrompt'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user