From c141f9398e753565f05c2a980b247884c30c7c24 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Tue, 27 Aug 2024 16:56:40 +0900 Subject: [PATCH] Add kei stablediff --- src/ts/process/stableDiff.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/ts/process/stableDiff.ts b/src/ts/process/stableDiff.ts index fea4138c..d95e9226 100644 --- a/src/ts/process/stableDiff.ts +++ b/src/ts/process/stableDiff.ts @@ -6,6 +6,7 @@ import { globalFetch, readImage } from "../storage/globalApi" import { CharEmotion } from "../stores" import type { OpenAIChat } from "." import { processZip } from "./processzip" +import { keiServerURL } from "../kei/kei" export async function stableDiff(currentChar:character,prompt:string){ let db = get(DataBase) @@ -488,5 +489,39 @@ export async function generateAIImage(genPrompt:string, currentChar:character, n return false } } + if(db.sdProvider === 'kei'){ + const db = get(DataBase) + let auth = db?.account?.token + if(!auth){ + db.account = JSON.parse(localStorage.getItem("fallbackRisuToken")) + auth = db?.account?.token + db.account.useSync = true + } + const da = await globalFetch(keiServerURL() + '/imaggen', { + body: { + "prompt": genPrompt, + }, + headers: { + "x-api-key": auth + } + }) + + if(!da.ok || !da.data.success){ + alertError(Buffer.from(da.data.message || da.data).toString()) + return false + } + if(returnSdData === 'inlay'){ + return da.data.data + } + else{ + let charemotions = get(CharEmotion) + const img = da.data.data + const emos:[string, string,number][] = [[img, img, Date.now()]] + charemotions[currentChar.chaId] = emos + CharEmotion.set(charemotions) + } + return returnSdData + + } return '' }