fix: Protect loadLoreBooks() from very short max context length

This commit is contained in:
enzi221
2025-05-19 20:24:20 +09:00
parent 6e5cf5eb48
commit 5e10607cb6

View File

@@ -524,7 +524,7 @@ export async function runLua(code:string, arg:{
return JSON.stringify(found.map((b) => ({ ...b, content: risuChatParser(b.content, { chara: selectedChar }) })))
})
luaEngine.global.set('loadLoreBooksMain', async (id:string, usedContext:number) => {
luaEngine.global.set('loadLoreBooksMain', async (id:string, reserve:number) => {
if(!LuaLowLevelIds.has(id)){
return
}
@@ -538,9 +538,9 @@ export async function runLua(code:string, arg:{
}
const fullLoreBooks = (await loadLoreBookV3Prompt()).actives
const maxContext = db.maxContext - usedContext
const maxContext = db.maxContext - reserve
if (maxContext < 0) {
return
return JSON.stringify([])
}
let totalTokens = 0