[feat] add template warn
This commit is contained in:
@@ -3,12 +3,15 @@
|
|||||||
import { language } from "src/lang";
|
import { language } from "src/lang";
|
||||||
import ProomptItem from "src/lib/UI/ProomptItem.svelte";
|
import ProomptItem from "src/lib/UI/ProomptItem.svelte";
|
||||||
import type { Proompt } from "src/ts/process/proompt";
|
import type { Proompt } from "src/ts/process/proompt";
|
||||||
|
import { templateCheck } from "src/ts/process/templates/templateCheck";
|
||||||
import { DataBase } from "src/ts/storage/database";
|
import { DataBase } from "src/ts/storage/database";
|
||||||
|
|
||||||
let sorted = 0
|
let sorted = 0
|
||||||
let opened = 0
|
let opened = 0
|
||||||
|
let warns: string[] = []
|
||||||
export let onGoBack: () => void = () => {}
|
export let onGoBack: () => void = () => {}
|
||||||
|
|
||||||
|
$: warns = templateCheck($DataBase)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<h2 class="mb-2 text-2xl font-bold mt-2 items-center flex">
|
<h2 class="mb-2 text-2xl font-bold mt-2 items-center flex">
|
||||||
@@ -17,6 +20,15 @@
|
|||||||
</button>
|
</button>
|
||||||
{language.promptTemplate}
|
{language.promptTemplate}
|
||||||
</h2>
|
</h2>
|
||||||
|
{#if warns.length > 0}
|
||||||
|
<div class="text-red-500 flex flex-col items-start p-2 rounded-md border-red-500 border">
|
||||||
|
<h2 class="text-xl font-bold">Warning</h2>
|
||||||
|
<div class="border-b border-b-red-500 mt-1 mb-2 w-full"></div>
|
||||||
|
{#each warns as warn}
|
||||||
|
<span class="ml-4">{warn}</span>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
<div class="contain w-full max-w-full mt-4 flex flex-col p-3 rounded-md">
|
<div class="contain w-full max-w-full mt-4 flex flex-col p-3 rounded-md">
|
||||||
{#if $DataBase.promptTemplate.length === 0}
|
{#if $DataBase.promptTemplate.length === 0}
|
||||||
<div class="text-textcolor2">No Format</div>
|
<div class="text-textcolor2">No Format</div>
|
||||||
|
|||||||
79
src/ts/process/templates/templateCheck.ts
Normal file
79
src/ts/process/templates/templateCheck.ts
Normal 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
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user