[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:','')}) :
(lore.key ?? '').replace(rmRegex, '').toLocaleLowerCase().split(',').filter((a) => {
return a.length > 1 return a.length > 1
}), }),
secondKey: lore.selective ? (lore.secondkey ?? '').replace(rmRegex, '').toLocaleLowerCase().split(',').filter((a) => { 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 return a.length > 1
}) : [], })) : [],
content: lore.content, content: lore.content,
order: lore.insertorder, order: lore.insertorder,
activatied: false activatied: false
@@ -136,6 +138,7 @@ export async function loadLoreBookPrompt(){
} }
let firstKeyActivation = false let firstKeyActivation = false
if(Array.isArray(lore.keys)){
for(const key of lore.keys){ for(const key of lore.keys){
if(key){ if(key){
if(formatedChat.includes(key)){ if(formatedChat.includes(key)){
@@ -144,8 +147,15 @@ export async function loadLoreBookPrompt(){
} }
} }
} }
}
else{
if(formatedChat.match(new RegExp(lore.keys.regex,'g'))){
firstKeyActivation = true
}
}
if(firstKeyActivation){ if(firstKeyActivation){
if(Array.isArray(lore.secondKey)){
if(lore.secondKey.length === 0){ if(lore.secondKey.length === 0){
activatiedPrompt.push(lore.content) activatiedPrompt.push(lore.content)
lore.activatied = true lore.activatied = true
@@ -161,6 +171,12 @@ export async function loadLoreBookPrompt(){
} }
} }
} }
else{
if(formatedChat.match(new RegExp(lore.secondKey.regex,'g'))){
firstKeyActivation = true
}
}
}
} }
if(!(char.loreSettings?.recursiveScanning)){ if(!(char.loreSettings?.recursiveScanning)){
break break