[feat] added inlay emotion/imggen & rework imggen
This commit is contained in:
@@ -7,7 +7,6 @@ import { CharEmotion } from "../stores"
|
||||
import type { OpenAIChat } from "."
|
||||
import { processZip } from "./processzip"
|
||||
export async function stableDiff(currentChar:character,prompt:string){
|
||||
const mainPrompt = "assistant is a chat analyzer.\nuser will input a data of situation with key and values before chat, and a chat of a user and character.\nView the status of the chat and change the data.\nif data's key starts with $, it must change it every time.\nif data value is none, it must change it."
|
||||
let db = get(DataBase)
|
||||
|
||||
if(db.sdProvider === ''){
|
||||
@@ -15,53 +14,14 @@ export async function stableDiff(currentChar:character,prompt:string){
|
||||
return false
|
||||
}
|
||||
|
||||
let proompt = 'Data:'
|
||||
|
||||
let currentSd:[string,string][] = []
|
||||
|
||||
const sdData = currentChar.chats[currentChar.chatPage].sdData
|
||||
if(sdData){
|
||||
const das = sdData.split('\n')
|
||||
for(const data of das){
|
||||
const splited = data.split(':::')
|
||||
currentSd.push([splited[0].trim(), splited[1].trim()])
|
||||
}
|
||||
}
|
||||
else{
|
||||
currentSd = JSON.parse(JSON.stringify(currentChar.sdData))
|
||||
}
|
||||
|
||||
for(const d of currentSd){
|
||||
let val = d[1].trim()
|
||||
if(val === ''){
|
||||
val = 'none'
|
||||
}
|
||||
|
||||
if(!d[0].startsWith('|') || d[0] === 'negative' || d[0] === 'always'){
|
||||
proompt += `\n${d[0].trim()}: ${val}`
|
||||
}
|
||||
}
|
||||
|
||||
proompt += `\n\nChat:\n${prompt}`
|
||||
const proompt = `Chat:\n${prompt}`
|
||||
|
||||
const promptbody:OpenAIChat[] = [
|
||||
{
|
||||
|
||||
role:'system',
|
||||
content: mainPrompt
|
||||
},
|
||||
{
|
||||
role: 'user',
|
||||
content: `Data:\ncharacter's appearance: red hair, cute, black eyes\ncurrent situation: none\n$character's pose: none\n$character's emotion: none\n\nChat:\nuser: *eats breakfeast* \n I'm ready.\ncharacter: Lemon waits patiently outside your room while you get ready. Once you are dressed and have finished your breakfast, she escorts you to the door.\n"Have a good day at school, Master. Don't forget to study hard and make the most of your time there," Lemon reminds you with a smile as she sees you off.`
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
content: "character's appearance: red hair, cute, black eyes\ncurrent situation: waking up in the morning\n$character's pose: standing\n$character's emotion: apologetic"
|
||||
},
|
||||
{
|
||||
|
||||
role:'system',
|
||||
content: mainPrompt
|
||||
content: currentChar.newGenData.instructions
|
||||
},
|
||||
{
|
||||
role: 'user',
|
||||
@@ -69,7 +29,6 @@ export async function stableDiff(currentChar:character,prompt:string){
|
||||
},
|
||||
]
|
||||
|
||||
console.log(proompt)
|
||||
const rq = await requestChatData({
|
||||
formated: promptbody,
|
||||
currentChar: currentChar,
|
||||
@@ -83,38 +42,20 @@ export async function stableDiff(currentChar:character,prompt:string){
|
||||
alertError(`${rq.result}`)
|
||||
return false
|
||||
}
|
||||
else{
|
||||
const res = rq.result
|
||||
const das = res.split('\n')
|
||||
for(const data of das){
|
||||
const splited = data.split(':')
|
||||
if(splited.length === 2){
|
||||
for(let i=0;i<currentSd.length;i++){
|
||||
if(currentSd[i][0].trim() === splited[0]){
|
||||
currentSd[i][1] = splited[1].trim()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let returnSdData = currentSd.map((val) => {
|
||||
return val.join(':::')
|
||||
}).join('\n')
|
||||
const r = rq.result
|
||||
|
||||
|
||||
const genPrompt = currentChar.newGenData.prompt.replaceAll('{{slot}}', r)
|
||||
const neg = currentChar.newGenData.negative
|
||||
|
||||
return await generateAIImage(genPrompt, currentChar, neg, '')
|
||||
}
|
||||
|
||||
export async function generateAIImage(genPrompt:string, currentChar:character, neg:string, returnSdData:string){
|
||||
const db = get(DataBase)
|
||||
if(db.sdProvider === 'webui'){
|
||||
|
||||
let prompts:string[] = []
|
||||
let neg = ''
|
||||
for(let i=0;i<currentSd.length;i++){
|
||||
if(currentSd[i][0] !== 'negative'){
|
||||
prompts.push(currentSd[i][1])
|
||||
}
|
||||
else{
|
||||
neg = currentSd[i][1]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const uri = new URL(db.webUiUrl)
|
||||
uri.pathname = '/sdapi/v1/txt2img'
|
||||
@@ -126,7 +67,7 @@ export async function stableDiff(currentChar:character,prompt:string){
|
||||
"seed": -1,
|
||||
"steps": db.sdSteps,
|
||||
"cfg_scale": db.sdCFG,
|
||||
"prompt": prompts.join(','),
|
||||
"prompt": genPrompt,
|
||||
"negative_prompt": neg,
|
||||
"sampler_name": db.sdConfig.sampler_name,
|
||||
"enable_hr": db.sdConfig.enable_hr,
|
||||
@@ -139,6 +80,16 @@ export async function stableDiff(currentChar:character,prompt:string){
|
||||
}
|
||||
})
|
||||
|
||||
if(returnSdData === 'inlay'){
|
||||
if(da.ok){
|
||||
return `data:image/png;base64,${da.data.images[0]}`
|
||||
}
|
||||
else{
|
||||
alertError(JSON.stringify(da.data))
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
if(da.ok){
|
||||
let charemotions = get(CharEmotion)
|
||||
const img = `data:image/png;base64,${da.data.images[0]}`
|
||||
@@ -162,19 +113,6 @@ export async function stableDiff(currentChar:character,prompt:string){
|
||||
}
|
||||
if(db.sdProvider === 'novelai'){
|
||||
|
||||
let prompts:string[] = []
|
||||
let neg = ''
|
||||
for(let i=0;i<currentSd.length;i++){
|
||||
if(currentSd[i][0] !== 'negative'){
|
||||
prompts.push(currentSd[i][1])
|
||||
}
|
||||
else{
|
||||
neg = currentSd[i][1]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
let reqlist= {}
|
||||
|
||||
if(db.NAII2I){
|
||||
@@ -192,7 +130,7 @@ export async function stableDiff(currentChar:character,prompt:string){
|
||||
reqlist = {
|
||||
body: {
|
||||
"action": "img2img",
|
||||
"input": prompts.join(','),
|
||||
"input": genPrompt,
|
||||
"model": db.NAIImgModel,
|
||||
"parameters": {
|
||||
"seed": seed,
|
||||
@@ -226,7 +164,7 @@ export async function stableDiff(currentChar:character,prompt:string){
|
||||
}else{
|
||||
reqlist = {
|
||||
body: {
|
||||
"input": prompts.join(','),
|
||||
"input": genPrompt,
|
||||
"model": db.NAIImgModel,
|
||||
"parameters": {
|
||||
"width": db.NAIImgConfig.width,
|
||||
@@ -249,6 +187,17 @@ export async function stableDiff(currentChar:character,prompt:string){
|
||||
try {
|
||||
const da = await globalFetch(db.NAIImgUrl, reqlist)
|
||||
|
||||
if(returnSdData === 'inlay'){
|
||||
if(da.ok){
|
||||
const img = await processZip(da.data);
|
||||
return img
|
||||
}
|
||||
else{
|
||||
alertError(Buffer.from(da.data).toString())
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
if(da.ok){
|
||||
let charemotions = get(CharEmotion)
|
||||
const img = await processZip(da.data);
|
||||
|
||||
Reference in New Issue
Block a user