fix style-data

This commit is contained in:
kwaroran
2024-07-10 15:58:32 +09:00
parent f591721645
commit 98576eeae4

View File

@@ -448,6 +448,13 @@ async function translateLLM(text:string, arg:{to:string}){
if(llmCache.has(text)){
return llmCache.get(text)
}
const styleDecodeRegex = /\<risu-style\>(.+?)\<\/risu-style\>/gms
let styleDecodes:string[] = []
text = text.replace(styleDecodeRegex, (match, p1) => {
styleDecodes.push(p1)
return `<style-data style-index="${styleDecodes.length-1}"></style-data>`
})
const db = get(DataBase)
let formated:OpenAIChat[] = []
let prompt = db.translatorPrompt || `You are a translator. translate the following html or text into {{slot}}. do not output anything other than the translation.`
@@ -480,6 +487,9 @@ async function translateLLM(text:string, arg:{to:string}){
alertError(`${rq.result}`)
return text
}
llmCache.set(text, rq.result)
return rq.result
const result = rq.result.replace(/<style-data style-index="(\d+)" ?\/?>/g, (match, p1) => {
return styleDecodes[parseInt(p1)] ?? ''
}).replace(/<\/style-data>/g, '')
llmCache.set(text, result)
return result
}