[feat] add template warn

This commit is contained in:
kwaroran
2023-08-09 01:38:47 +09:00
parent f80f1f9e9e
commit f61da89db2
2 changed files with 91 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
import type { Database } from 'src/ts/storage/database'
export function templateCheck(db:Database){
const temp = db.promptTemplate
if(!temp){
return []
}
let mainPrompts = 0
let notePrompts = 0
let endRanges:number[] = []
let startRanges:number[] = []
let hasDescription = false
let hasLorebook = false
let reachEnd = false
for(let i=0;i<temp.length;i++){
const c = temp[i]
if(c.type === 'jailbreak' || c.type === 'plain'){
if(c.type2 === 'globalNote'){
notePrompts++
}
if(c.type2 === 'main'){
mainPrompts++
}
}
else if(c.type === 'chat'){
if(c.rangeStart !== 0){
startRanges.push(c.rangeStart)
}
if(c.rangeEnd !== 'end'){
endRanges.push(c.rangeEnd)
}
else{
reachEnd = true
}
}
else if(c.type === 'description'){
hasDescription = true
}
else if(c.type === 'lorebook'){
hasLorebook = true
}
}
let warnings:string[] = []
let unresolvedRanges = startRanges.filter(x => !endRanges.includes(x)).concat(endRanges.filter(x => !startRanges.includes(x)))
if(mainPrompts === 0){
warnings.push('No main prompt entry found')
}
if(mainPrompts > 1){
warnings.push('Multiple main prompt entries found, this can result in unexpected behavior')
}
if(notePrompts === 0){
warnings.push('No global notes entry found')
}
if(notePrompts > 1){
warnings.push('Multiple global notes entries found, this can result in unexpected behavior')
}
if(!hasDescription){
warnings.push('No description entry found')
}
if(!hasLorebook){
warnings.push('No lorebook entry found')
}
if(!reachEnd){
warnings.push('No chat entry found with range end set to "Until chat end"')
}
if(unresolvedRanges.length > 0){
warnings.push('Unresolved chat ranges: ' + unresolvedRanges.join(', '))
}
return warnings
}