From 8a782ab24fa1681a355b12c1d1e960574913b6eb Mon Sep 17 00:00:00 2001 From: kwaroran Date: Thu, 13 Mar 2025 12:13:09 +0900 Subject: [PATCH] add assetprompt cbs --- src/ts/process/index.svelte.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/ts/process/index.svelte.ts b/src/ts/process/index.svelte.ts index cfc36580..5d859a46 100644 --- a/src/ts/process/index.svelte.ts +++ b/src/ts/process/index.svelte.ts @@ -30,6 +30,8 @@ import { runLuaEditTrigger } from "./lua"; import { parseChatML } from "../parser.svelte"; import { getModelInfo, LLMFlags } from "../model/modellist"; import { hypaMemoryV3 } from "./memory/hypav3"; +import { getModuleAssets } from "./modules"; +import { getFileSrc, readImage } from "../globalApi.svelte"; export interface OpenAIChat{ role: 'system'|'user'|'assistant'|'function' @@ -795,6 +797,35 @@ export async function sendChat(chatProcessIndex = -1,arg:{ return '' }) + const assetPromises:Promise[] = [] + formatedChat = formatedChat.replace(/\{\{asset_?prompt::(.+?)\}\}/gmsiu, (match, p1) => { + const moduleAssets = getModuleAssets() + const assets = (currentChar.additionalAssets ?? []).concat(moduleAssets) + const asset = assets.find(v => { + return v[0] === p1 + }) + if(asset){ + assetPromises.push((async () => { + const assetDataBuf = await readImage(asset[1]) + multimodal.push({ + type: "image", + base64: `data:image/png;base64,${Buffer.from(assetDataBuf).toString('base64')}` + }) + })()) + } + else if(p1 === 'icon'){ + assetPromises.push((async () => { + const assetDataBuf = await readImage(currentChar.image ?? '') + multimodal.push({ + type: "image", + base64: `data:image/png;base64,${Buffer.from(assetDataBuf).toString('base64')}` + }) + })()) + } + return '' + }) + await Promise.all(assetPromises) + const chat:OpenAIChat = { role: role, content: formatedChat,