[fix] lorebook replace error

This commit is contained in:
kwaroran
2023-05-24 10:40:02 +09:00
parent 73a8805fce
commit b8ead62da4

View File

@@ -68,7 +68,7 @@ export async function loadLoreBookPrompt(){
const characterLore = char.globalLore const characterLore = char.globalLore
const chatLore = char.chats[page].localLore const chatLore = char.chats[page].localLore
const globalLore = db.loreBook[db.loreBookPage].data const globalLore = db.loreBook[db.loreBookPage].data
const fullLore = characterLore.concat(chatLore.concat(globalLore)) const fullLore = characterLore.concat(chatLore.concat(globalLore ?? []))
const currentChat = char.chats[page].message const currentChat = char.chats[page].message
const loreDepth = char.loreSettings?.scanDepth ?? db.loreBookDepth const loreDepth = char.loreSettings?.scanDepth ?? db.loreBookDepth
const loreToken = char.loreSettings?.tokenBudget ?? db.loreBookToken const loreToken = char.loreSettings?.tokenBudget ?? db.loreBookToken
@@ -78,6 +78,7 @@ export async function loadLoreBookPrompt(){
let formatedLore:formatedLore[] = [] let formatedLore:formatedLore[] = []
for (const lore of fullLore){ for (const lore of fullLore){
if(lore && lore.key){
if(lore.key.length > 1 || lore.alwaysActive){ if(lore.key.length > 1 || lore.alwaysActive){
formatedLore.push({ formatedLore.push({
keys: lore.alwaysActive ? 'always' : lore.key.replace(rmRegex, '').toLocaleLowerCase().split(',').filter((a) => { keys: lore.alwaysActive ? 'always' : lore.key.replace(rmRegex, '').toLocaleLowerCase().split(',').filter((a) => {
@@ -92,6 +93,7 @@ export async function loadLoreBookPrompt(){
}) })
} }
} }
}
formatedLore.sort((a, b) => { formatedLore.sort((a, b) => {
return b.order - a.order return b.order - a.order