[feat] lorebook regex

This commit is contained in:
kwaroran
2023-07-25 05:02:50 +09:00
parent 52dd433238
commit 9e3e5a327d

View File

@@ -51,8 +51,8 @@ export function addLorebook(type:number) {
} }
interface formatedLore{ interface formatedLore{
keys:string[]|'always', keys:string[]|'always'|{type:'regex',regex:string},
secondKey:string[] secondKey:string[]|{type:'regex',regex:string}
content: string content: string
order: number order: number
activatied: boolean activatied: boolean
@@ -91,12 +91,14 @@ export async function loadLoreBookPrompt(){
} }
formatedLore.push({ formatedLore.push({
keys: lore.alwaysActive ? 'always' : (lore.key ?? '').replace(rmRegex, '').toLocaleLowerCase().split(',').filter((a) => { keys: lore.alwaysActive ? 'always' : (lore.key?.startsWith("regex:")) ? ({type:'regex',regex:lore.key.replace('regex:','')}) :
return a.length > 1 (lore.key ?? '').replace(rmRegex, '').toLocaleLowerCase().split(',').filter((a) => {
}), return a.length > 1
secondKey: lore.selective ? (lore.secondkey ?? '').replace(rmRegex, '').toLocaleLowerCase().split(',').filter((a) => { }),
return a.length > 1 secondKey: lore.selective ? ((lore.secondkey?.startsWith("regex:")) ? ({type:'regex',regex:lore.secondkey.replace('regex:','')}) :
}) : [], (lore.secondkey ?? '').replace(rmRegex, '').toLocaleLowerCase().split(',').filter((a) => {
return a.length > 1
})) : [],
content: lore.content, content: lore.content,
order: lore.insertorder, order: lore.insertorder,
activatied: false activatied: false
@@ -136,28 +138,42 @@ export async function loadLoreBookPrompt(){
} }
let firstKeyActivation = false let firstKeyActivation = false
for(const key of lore.keys){ if(Array.isArray(lore.keys)){
if(key){ for(const key of lore.keys){
if(formatedChat.includes(key)){ if(key){
firstKeyActivation = true if(formatedChat.includes(key)){
break firstKeyActivation = true
break
}
} }
} }
} }
else{
if(formatedChat.match(new RegExp(lore.keys.regex,'g'))){
firstKeyActivation = true
}
}
if(firstKeyActivation){ if(firstKeyActivation){
if(lore.secondKey.length === 0){ if(Array.isArray(lore.secondKey)){
activatiedPrompt.push(lore.content) if(lore.secondKey.length === 0){
lore.activatied = true
loreListUpdated = true
continue
}
for(const key of lore.secondKey){
if(formatedChat.includes(key)){
activatiedPrompt.push(lore.content) activatiedPrompt.push(lore.content)
lore.activatied = true lore.activatied = true
loreListUpdated = true loreListUpdated = true
break continue
}
for(const key of lore.secondKey){
if(formatedChat.includes(key)){
activatiedPrompt.push(lore.content)
lore.activatied = true
loreListUpdated = true
break
}
}
}
else{
if(formatedChat.match(new RegExp(lore.secondKey.regex,'g'))){
firstKeyActivation = true
} }
} }
} }