Add fal.ai support

This commit is contained in:
kwaroran
2024-09-01 01:50:21 +09:00
parent a5061a3b3e
commit de6c90cbc4
7 changed files with 105 additions and 4 deletions

View File

@@ -523,5 +523,68 @@ export async function generateAIImage(genPrompt:string, currentChar:character, n
return returnSdData
}
if(db.sdProvider === 'fal'){
const model = db.falModel
const token = db.falToken
let body:{[key:string]:any} = {
prompt: genPrompt,
enable_safety_checker: false,
sync_mode: true,
image_size: {
"width": db.sdConfig.width,
"height": db.sdConfig.height,
}
}
if(db.falModel === 'fal-ai/flux-lora'){
let loraPath = db.falLora
if(loraPath.startsWith('urn:') || loraPath.startsWith('civitai:')){
const id = loraPath.split('@').pop()
loraPath = `https://civitai.com/api/download/models/${id}?type=Model&format=SafeTensor`
}
body.loras = [{
"path": loraPath,
"scale": db.falLoraScale
}]
}
if(db.falModel === 'fal-ai/flux-pro'){
delete body.enable_safety_checker
}
console.log(body)
const res = await globalFetch('https://fal.run/' + model, {
headers: {
"Authorization": "Key " + token,
"Content-Type": "application/json"
},
method: 'POST',
body: body
})
console.log(res)
if(!res.ok){
alertError(JSON.stringify(res.data))
return false
}
let image = res.data?.images?.[0]?.url
if(!image){
alertError(JSON.stringify(res.data))
return false
}
if(returnSdData === 'inlay'){
return image
}
else{
let charemotions = get(CharEmotion)
const emos:[string, string,number][] = [[image, image, Date.now()]]
charemotions[currentChar.chaId] = emos
CharEmotion.set(charemotions)
}
}
return ''
}

View File

@@ -267,7 +267,7 @@ export async function sayTTS(character:character,text:string) {
'Content-Type': 'application/json'
},
rawResponse: false,
plainFetchDeforce: true,
})
console.log(path)
if(path.ok){

View File

@@ -432,6 +432,8 @@ export function setDatabase(data:Database){
data.unformatQuotes ??= false
data.ttsAutoSpeech ??= false
data.translatorInputLanguage ??= 'auto'
data.falModel ??= 'fal-ai/flux/dev'
data.falLoraScale ??= 1
changeLanguage(data.language)
DataBase.set(data)
}
@@ -718,6 +720,11 @@ export interface Database{
hideApiKey: boolean
unformatQuotes: boolean
enableDevTools: boolean
falToken: string
falModel: string
falLora: string
falLoraName: string
falLoraScale: number
}
export interface customscript{

View File

@@ -577,6 +577,7 @@ const knownHostes = ["localhost","127.0.0.1","0.0.0.0"]
interface GlobalFetchArgs {
plainFetchForce?: boolean;
plainFetchDeforce?: boolean;
body?: any;
headers?: { [key: string]: string };
rawResponse?: boolean;
@@ -625,7 +626,7 @@ export async function globalFetch(url: string, arg: GlobalFetchArgs = {}): Promi
if (arg.abortSignal?.aborted) { return { ok: false, data: 'aborted', headers: {} }}
const urlHost = new URL(url).hostname
const forcePlainFetch = (knownHostes.includes(urlHost) && !isTauri) || db.usePlainFetch || arg.plainFetchForce
const forcePlainFetch = ((knownHostes.includes(urlHost) && !isTauri) || db.usePlainFetch || arg.plainFetchForce) && !arg.plainFetchDeforce
if (knownHostes.includes(urlHost) && !isTauri && !isNodeServer){
return { ok: false, headers: {}, data: 'You are trying local request on web version. This is not allowed due to browser security policy. Use the desktop version instead, or use a tunneling service like ngrok and set the CORS to allow all.' }