[feat] added character lore settings
This commit is contained in:
@@ -239,5 +239,6 @@ export const languageEnglish = {
|
|||||||
settings: "Settings",
|
settings: "Settings",
|
||||||
selective: "Selective",
|
selective: "Selective",
|
||||||
SecondaryKeys: 'Secondary keys',
|
SecondaryKeys: 'Secondary keys',
|
||||||
|
useGlobalSettings: "Use Global Settings",
|
||||||
|
recursiveScanning: "Recursive Scanning"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<div class="flex w-full justify-center">
|
<div class="flex w-full justify-center mt-4 max-w-100vw">
|
||||||
<div class="w-3xl max-w-80p bg-darkbg rounded-md p-3 text-white text-sm">
|
<div class="w-5/6 max-w-80vw bg-darkbg rounded-md p-3 text-white text-sm">
|
||||||
<h1 class="text-xl font-bold mb-2">{language.creatorNotes}
|
<h1 class="font-bold mb-2">{language.creatorNotes}
|
||||||
<button class="float-right" on:click={onRemove}>
|
<button class="float-right" on:click={onRemove}>
|
||||||
<XIcon />
|
<XIcon />
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
import { DownloadIcon, FolderUpIcon, ImportIcon, PlusIcon } from "lucide-svelte";
|
import { DownloadIcon, FolderUpIcon, ImportIcon, PlusIcon } from "lucide-svelte";
|
||||||
import { addLorebook, exportLoreBook, importLoreBook } from "../../ts/process/lorebook";
|
import { addLorebook, exportLoreBook, importLoreBook } from "../../ts/process/lorebook";
|
||||||
import LoreBookData from "./LoreBookData.svelte";
|
import LoreBookData from "./LoreBookData.svelte";
|
||||||
|
import Check from "../Others/Check.svelte";
|
||||||
let submenu = 0
|
let submenu = 0
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -25,42 +26,71 @@
|
|||||||
<span>{language.settings}</span>
|
<span>{language.settings}</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<span class="text-gray-500 mt-2 mb-6 text-sm">{submenu === 0 ? $DataBase.characters[$selectedCharID].type === 'group' ? language.groupLoreInfo : language.globalLoreInfo : language.localLoreInfo}</span>
|
{#if submenu !== 2}
|
||||||
|
<span class="text-gray-500 mt-2 mb-6 text-sm">{submenu === 0 ? $DataBase.characters[$selectedCharID].type === 'group' ? language.groupLoreInfo : language.globalLoreInfo : language.localLoreInfo}</span>
|
||||||
<div class="border-solid border-borderc p-2 flex flex-col border-1">
|
<div class="border-solid border-borderc p-2 flex flex-col border-1">
|
||||||
{#if submenu === 0}
|
{#if submenu === 0}
|
||||||
{#if $DataBase.characters[$selectedCharID].globalLore.length === 0}
|
{#if $DataBase.characters[$selectedCharID].globalLore.length === 0}
|
||||||
<span class="text-gray-500">No Lorebook</span>
|
<span class="text-gray-500">No Lorebook</span>
|
||||||
{:else}
|
{:else}
|
||||||
{#each $DataBase.characters[$selectedCharID].globalLore as book, i}
|
{#each $DataBase.characters[$selectedCharID].globalLore as book, i}
|
||||||
{#if i !== 0}
|
{#if i !== 0}
|
||||||
<div class="border-borderc mt-2 mb-2 w-full border-solid border-b-1 seperator"></div>
|
<div class="border-borderc mt-2 mb-2 w-full border-solid border-b-1 seperator"></div>
|
||||||
{/if}
|
{/if}
|
||||||
<LoreBookData bind:value={$DataBase.characters[$selectedCharID].globalLore[i]} onRemove={() => {
|
<LoreBookData bind:value={$DataBase.characters[$selectedCharID].globalLore[i]} onRemove={() => {
|
||||||
let lore = $DataBase.characters[$selectedCharID].globalLore
|
let lore = $DataBase.characters[$selectedCharID].globalLore
|
||||||
lore.splice(i, 1)
|
lore.splice(i, 1)
|
||||||
$DataBase.characters[$selectedCharID].globalLore = lore
|
$DataBase.characters[$selectedCharID].globalLore = lore
|
||||||
}}/>
|
}}/>
|
||||||
{/each}
|
{/each}
|
||||||
|
{/if}
|
||||||
|
{:else if submenu === 1}
|
||||||
|
{#if $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore.length === 0}
|
||||||
|
<span class="text-gray-500">No Lorebook</span>
|
||||||
|
{:else}
|
||||||
|
{#each $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore as book, i}
|
||||||
|
{#if i !== 0}
|
||||||
|
<div class="border-borderc mt-2 mb-2 w-full border-solid border-b-1 seperator"></div>
|
||||||
|
{/if}
|
||||||
|
<LoreBookData bind:value={$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore[i]} onRemove={() => {
|
||||||
|
let lore = $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore
|
||||||
|
lore.splice(i, 1)
|
||||||
|
$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore = lore
|
||||||
|
}}/>
|
||||||
|
{/each}
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
{#if $DataBase.characters[$selectedCharID].loreSettings}
|
||||||
|
<div class="flex items-center mt-4">
|
||||||
|
<Check check={false} onChange={() => {
|
||||||
|
$DataBase.characters[$selectedCharID].loreSettings = undefined
|
||||||
|
}}/>
|
||||||
|
<span>{language.useGlobalSettings}</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center mt-4">
|
||||||
|
<Check bind:check={$DataBase.characters[$selectedCharID].loreSettings.recursiveScanning}/>
|
||||||
|
<span>{language.recursiveScanning}</span>
|
||||||
|
</div>
|
||||||
|
<span class="text-neutral-200 mt-4 mb-2">{language.loreBookDepth}</span>
|
||||||
|
<input class="text-neutral-200 mb-4 p-2 bg-transparent input-text focus:bg-selected text-sm" type="number" min={0} max="20" bind:value={$DataBase.characters[$selectedCharID].loreSettings.scanDepth}>
|
||||||
|
<span class="text-neutral-200">{language.loreBookToken}</span>
|
||||||
|
<input class="text-neutral-200 mb-4 p-2 bg-transparent input-text focus:bg-selected text-sm" type="number" min={0} max="4096" bind:value={$DataBase.characters[$selectedCharID].loreSettings.tokenBudget}>
|
||||||
{:else}
|
{:else}
|
||||||
{#if $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore.length === 0}
|
<div class="flex items-center mt-4">
|
||||||
<span class="text-gray-500">No Lorebook</span>
|
<Check check={true} onChange={() => {
|
||||||
{:else}
|
$DataBase.characters[$selectedCharID].loreSettings = {
|
||||||
{#each $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore as book, i}
|
tokenBudget: $DataBase.loreBookToken,
|
||||||
{#if i !== 0}
|
scanDepth:$DataBase.loreBookDepth,
|
||||||
<div class="border-borderc mt-2 mb-2 w-full border-solid border-b-1 seperator"></div>
|
recursiveScanning: false
|
||||||
{/if}
|
}
|
||||||
<LoreBookData bind:value={$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore[i]} onRemove={() => {
|
}}/>
|
||||||
let lore = $DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore
|
<span>{language.useGlobalSettings}</span>
|
||||||
lore.splice(i, 1)
|
</div>
|
||||||
$DataBase.characters[$selectedCharID].chats[$DataBase.characters[$selectedCharID].chatPage].localLore = lore
|
|
||||||
}}/>
|
|
||||||
{/each}
|
|
||||||
{/if}
|
|
||||||
{/if}
|
{/if}
|
||||||
|
{/if}
|
||||||
</div>
|
{#if submenu !== 2}
|
||||||
|
|
||||||
<div class="text-gray-500 mt-2 flex">
|
<div class="text-gray-500 mt-2 flex">
|
||||||
<button on:click={() => {addLorebook(submenu)}} class="hover:text-neutral-200 cursor-pointer">
|
<button on:click={() => {addLorebook(submenu)}} class="hover:text-neutral-200 cursor-pointer">
|
||||||
@@ -77,7 +107,7 @@
|
|||||||
<FolderUpIcon />
|
<FolderUpIcon />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
{/if}
|
||||||
<style>
|
<style>
|
||||||
.seperator{
|
.seperator{
|
||||||
border-top: 0px;
|
border-top: 0px;
|
||||||
|
|||||||
@@ -254,6 +254,14 @@ export interface character{
|
|||||||
personality:string
|
personality:string
|
||||||
scenario:string
|
scenario:string
|
||||||
firstMsgIndex:number
|
firstMsgIndex:number
|
||||||
|
loreSettings?:loreSettings
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export interface loreSettings{
|
||||||
|
tokenBudget: number
|
||||||
|
scanDepth:number
|
||||||
|
recursiveScanning: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface groupChat{
|
export interface groupChat{
|
||||||
@@ -275,6 +283,7 @@ export interface groupChat{
|
|||||||
creatorNotes?:string,
|
creatorNotes?:string,
|
||||||
removedQuotes?:boolean
|
removedQuotes?:boolean
|
||||||
firstMsgIndex?:number,
|
firstMsgIndex?:number,
|
||||||
|
loreSettings?:loreSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface botPreset{
|
export interface botPreset{
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ interface formatedLore{
|
|||||||
secondKey:string[]
|
secondKey:string[]
|
||||||
content: string
|
content: string
|
||||||
order: number
|
order: number
|
||||||
|
activatied: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const rmRegex = / |\n/g
|
const rmRegex = / |\n/g
|
||||||
@@ -50,11 +51,14 @@ const rmRegex = / |\n/g
|
|||||||
export async function loadLoreBookPrompt(){
|
export async function loadLoreBookPrompt(){
|
||||||
const selectedID = get(selectedCharID)
|
const selectedID = get(selectedCharID)
|
||||||
const db = get(DataBase)
|
const db = get(DataBase)
|
||||||
const page = db.characters[selectedID].chatPage
|
const char = db.characters[selectedID]
|
||||||
const globalLore = db.characters[selectedID].globalLore
|
const page = char.chatPage
|
||||||
const charLore = db.characters[selectedID].chats[page].localLore
|
const globalLore = char.globalLore
|
||||||
|
const charLore = char.chats[page].localLore
|
||||||
const fullLore = globalLore.concat(charLore)
|
const fullLore = globalLore.concat(charLore)
|
||||||
const currentChat = db.characters[selectedID].chats[page].message
|
const currentChat = char.chats[page].message
|
||||||
|
const loreDepth = char.loreSettings?.scanDepth ?? db.loreBookDepth
|
||||||
|
const loreToken = char.loreSettings?.tokenBudget ?? db.loreBookToken
|
||||||
|
|
||||||
let activatiedPrompt: string[] = []
|
let activatiedPrompt: string[] = []
|
||||||
|
|
||||||
@@ -70,7 +74,8 @@ export async function loadLoreBookPrompt(){
|
|||||||
return a.length > 1
|
return a.length > 1
|
||||||
}) : [],
|
}) : [],
|
||||||
content: lore.content,
|
content: lore.content,
|
||||||
order: lore.insertorder
|
order: lore.insertorder,
|
||||||
|
activatied: false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,40 +84,58 @@ export async function loadLoreBookPrompt(){
|
|||||||
return b.order - a.order
|
return b.order - a.order
|
||||||
})
|
})
|
||||||
|
|
||||||
const formatedChat = currentChat.slice(currentChat.length - db.loreBookDepth,currentChat.length).map((msg) => {
|
const formatedChat = currentChat.slice(currentChat.length - loreDepth,currentChat.length).map((msg) => {
|
||||||
return msg.data
|
return msg.data
|
||||||
}).join('||').replace(rmRegex,'').toLocaleLowerCase()
|
}).join('||').replace(rmRegex,'').toLocaleLowerCase()
|
||||||
|
|
||||||
for(const lore of formatedLore){
|
let loreListUpdated = true
|
||||||
const totalTokens = await tokenize(activatiedPrompt.concat([lore.content]).join('\n\n'))
|
|
||||||
if(totalTokens > db.loreBookToken){
|
while(loreListUpdated){
|
||||||
break
|
loreListUpdated = false
|
||||||
}
|
for(let i=0;i<formatedLore.length;i++){
|
||||||
|
const lore = formatedLore[i]
|
||||||
if(lore.keys === 'always'){
|
if(lore.activatied){
|
||||||
activatiedPrompt.push(lore.content)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
let firstKeyActivation = false
|
|
||||||
for(const key of lore.keys){
|
|
||||||
if(formatedChat.includes(key)){
|
|
||||||
firstKeyActivation = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(firstKeyActivation){
|
|
||||||
if(lore.secondKey.length === 0){
|
|
||||||
activatiedPrompt.push(lore.content)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for(const key of lore.secondKey){
|
const totalTokens = await tokenize(activatiedPrompt.concat([lore.content]).join('\n\n'))
|
||||||
|
if(totalTokens > loreToken){
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if(lore.keys === 'always'){
|
||||||
|
activatiedPrompt.push(lore.content)
|
||||||
|
lore.activatied = true
|
||||||
|
loreListUpdated = true
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
let firstKeyActivation = false
|
||||||
|
for(const key of lore.keys){
|
||||||
if(formatedChat.includes(key)){
|
if(formatedChat.includes(key)){
|
||||||
activatiedPrompt.push(lore.content)
|
firstKeyActivation = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(firstKeyActivation){
|
||||||
|
if(lore.secondKey.length === 0){
|
||||||
|
activatiedPrompt.push(lore.content)
|
||||||
|
lore.activatied = true
|
||||||
|
loreListUpdated = true
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for(const key of lore.secondKey){
|
||||||
|
if(formatedChat.includes(key)){
|
||||||
|
activatiedPrompt.push(lore.content)
|
||||||
|
lore.activatied = true
|
||||||
|
loreListUpdated = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!(char.loreSettings?.recursiveScanning)){
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,6 +152,8 @@ export async function importLoreBook(mode:'global'|'local'){
|
|||||||
if(!lorebook){
|
if(!lorebook){
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const importedlore = JSON.parse(Buffer.from(lorebook).toString('utf-8'))
|
const importedlore = JSON.parse(Buffer.from(lorebook).toString('utf-8'))
|
||||||
|
|||||||
@@ -21,7 +21,9 @@ export default {
|
|||||||
maxWidth:{
|
maxWidth:{
|
||||||
'half': '50%',
|
'half': '50%',
|
||||||
'80p': '80%',
|
'80p': '80%',
|
||||||
|
'80vw': '80vw',
|
||||||
'14': '3.5rem',
|
'14': '3.5rem',
|
||||||
|
'100vw': '100vw'
|
||||||
},
|
},
|
||||||
borderWidth: {
|
borderWidth: {
|
||||||
'1': '1px',
|
'1': '1px',
|
||||||
|
|||||||
Reference in New Issue
Block a user