[feat] add selective option in lorebook

This commit is contained in:
kwaroran
2023-05-12 21:57:12 +09:00
parent c4d44d2031
commit 23fe3ae484
8 changed files with 131 additions and 73 deletions

View File

@@ -54,7 +54,7 @@ export const languageEnglish = {
regexScript: "Regex Script is a custom script that is embbedded to the character. it replaces string that matches IN to OUT.\n\nThere are three type options."
+ "- **Modify Input** modifys user's input"
+ "- **Modify Output** modifys character's output"
+ "- **Modify Request Data** modifys current chat data when sent.\n\nIN must be a regex without flags and without backslashes in start and end.\n\nOUT is a normal string."
+ "- **Modify Request Data** modifys current chat data when sent.\n\nIN must be a regex without flags and without slashes in start and end.\n\nOUT is a normal string."
+ "\n\n If OUT has {{data}} in string, it replaces to matched string."
+ "\n\n If OUT starts with **@@**, it doesn't replaces the string, but instead does a special effect if matching string founds."
+ "\n\n- @@emo (emotion name)\n\n if character is Emotion Images mode, sets (emotion name) as emotion and prevents default.",
@@ -70,7 +70,8 @@ export const languageEnglish = {
chatNote: "a note that strongly effects model behavior. embbedded to current chat. also known as memory.",
personality: "A brief description about character's personality. \n\n**It is not recommended to use this option. Describe it in character description instead.**",
scenario: "A brief description about character's scenario. \n\n**It is not recommended to use this option. Describe it in character description instead.**",
utilityBot: "When activated, it ignores main prompt. \n\n**It is not recommended to use this option. Modifiy system prompt instead.**"
utilityBot: "When activated, it ignores main prompt. \n\n**It is not recommended to use this option. Modifiy system prompt instead.**",
loreSelective: "If Selective mode is toggled, both Activation Key and Secondary key should have a match to activate the lore."
},
setup: {
@@ -233,5 +234,10 @@ export const languageEnglish = {
unrecommended: "Not Recommended",
chatNotes: "Chat Notes",
showUnrecommended: "Show Unrecommended Settings",
altGreet: "Alternative First Messages"
altGreet: "Alternative First Messages",
scripts: "Scripts",
settings: "Settings",
selective: "Selective",
SecondaryKeys: 'Secondary keys',
}

View File

@@ -183,7 +183,7 @@ export const languageKorean = {
regexScript: "정규식 스크립트는 캐릭터에 종속된 커스텀 스크립트입니다. IN의 조건에 맞는 문자열을 OUT으로 변경합니다.\n\n타입은 세가지가 있습니다."
+ "- **입력문 수정** 유저의 입력문을 수정합니다"
+ "- **출력문 수정** 캐릭터의 출력문을 수정합니다"
+ "- **리퀘스트 데이터 수정** 리퀘스트를 보낼 때 채팅 데이터를 수정합니다.\n\nIN은 flag가 없고, 양끝에 슬레시가 없는 Regex여야 합니다.\n\nOUT은 일반 문자열입니다."
+ "- **리퀘스트 데이터 수정** 리퀘스트를 보낼 때 채팅 데이터를 수정합니다.\n\nIN은 flag가 없고, 양끝에 슬레시가 없는 Regex여야 합니다.\n\nOUT은 일반 문자열입니다."
+ "\n\n 만약 OUT 문자열에 {{data}}가 있으면, 매칭된 문자열로 바뀝니다."
+ "\n\n 만약 OUT이 @@로 시작된다면, 특수한 효과를 냅니다"
+ "\n\n- @@emo (emotion name)\n\n 감정 이미지 모드일 시 (emotion name)을 감정으로 정하고 감정 처리를 하지 않습니다.",

View File

@@ -3,7 +3,7 @@
import { tokenize } from "../../ts/tokenizer";
import { DataBase, type Database, type character, type groupChat } from "../../ts/database";
import { selectedCharID } from "../../ts/stores";
import { PlusIcon, SmileIcon, TrashIcon, UserIcon, ActivityIcon, BookIcon, LoaderIcon, User } from 'lucide-svelte'
import { PlusIcon, SmileIcon, TrashIcon, UserIcon, ActivityIcon, BookIcon, LoaderIcon, User, DnaIcon, CurlyBracesIcon } from 'lucide-svelte'
import Check from "../Others/Check.svelte";
import { addCharEmotion, addingEmotion, getCharImage, rmCharEmotion, selectCharImg, makeGroupImage } from "../../ts/characters";
import LoreBook from "./LoreBookSetting.svelte";
@@ -156,6 +156,11 @@
<button class={subMenu === 3 ? 'text-gray-200' : 'text-gray-500'} on:click={() => {subMenu = 3;subberMenu = 0}}>
<BookIcon />
</button>
{#if currentChar.type === 'character'}
<button class={subMenu === 4 ? 'text-gray-200' : 'text-gray-500'} on:click={() => {subMenu = 4}}>
<CurlyBracesIcon />
</button>
{/if}
<button class={subMenu === 2 ? 'text-gray-200' : 'text-gray-500'} on:click={() => {subMenu = 2}}>
<ActivityIcon />
</button>
@@ -370,32 +375,9 @@
{:else if subMenu === 3}
<h2 class="mb-2 text-2xl font-bold mt-2">{language.loreBook} <Help key="lorebook"/></h2>
<LoreBook />
{:else if subMenu === 2}
<h2 class="mb-2 text-2xl font-bold mt-2">{language.advancedSettings}</h2>
{#if currentChar.type !== 'group'}
<span class="text-neutral-200">{language.exampleMessage} <Help key="exampleMessage"/></span>
<textarea class="bg-transparent input-text mt-2 mb-2 text-gray-200 text-xs resize-none h-20 focus:bg-selected" autocomplete="off" bind:value={currentChar.data.exampleMessage}></textarea>
<span class="text-neutral-200">{language.creatorNotes} <Help key="creatorQuotes"/></span>
<textarea class="bg-transparent input-text mt-2 mb-2 text-gray-200 text-xs resize-none h-20 focus:bg-selected" autocomplete="off" bind:value={currentChar.data.creatorNotes} on:input={() => {
currentChar.data.removedQuotes = false
}}></textarea>
<span class="text-neutral-200">{language.systemPrompt} <Help key="systemPrompt"/></span>
<textarea class="bg-transparent input-text mt-2 mb-2 text-gray-200 text-xs resize-none h-20 focus:bg-selected" autocomplete="off" bind:value={currentChar.data.systemPrompt}></textarea>
<span class="text-neutral-200">{language.chatNotes} <Help key="chatNote"/></span>
<textarea class="bg-transparent input-text mt-2 mb-2 text-gray-200 resize-none h-20 focus:bg-selected text-xs" autocomplete="off" bind:value={currentChar.data.chats[currentChar.data.chatPage].note}></textarea>
<span class="text-gray-400 mb-6 text-sm">{tokens.localNote} {language.tokens}</span>
{#if $DataBase.showUnrecommended || currentChar.data.personality.length > 3}
<span class="text-neutral-200">{language.personality} <Help key="personality" unrecommended/></span>
<textarea class="bg-transparent input-text mt-2 mb-2 text-gray-200 text-xs resize-none h-20 focus:bg-selected" autocomplete="off" bind:value={currentChar.data.personality}></textarea>
{/if}
{#if $DataBase.showUnrecommended || currentChar.data.scenario.length > 3}
<span class="text-neutral-200">{language.scenario} <Help key="scenario" unrecommended/></span>
<textarea class="bg-transparent input-text mt-2 mb-2 text-gray-200 text-xs resize-none h-20 focus:bg-selected" autocomplete="off" bind:value={currentChar.data.scenario}></textarea>
{/if}
{:else if subMenu === 4}
{#if currentChar.type === 'character'}
<h2 class="mb-2 text-2xl font-bold mt-2">{language.scripts}</h2>
<span class="text-neutral-200 mt-2">Bias <Help key="bias"/></span>
<table class="contain w-full max-w-full tabler mt-2">
@@ -432,8 +414,64 @@
}}><TrashIcon /></button>
</tr>
{/each}
</table>
<span class="text-neutral-200 mt-4">{language.regexScript} <Help key="regexScript"/></span>
<table class="contain w-full max-w-full tabler mt-2 flex flex-col p-2 gap-2">
{#if currentChar.data.customscript.length === 0}
<div class="text-gray-500">No Scripts</div>
{/if}
{#each currentChar.data.customscript as customscript, i}
<RegexData bind:value={currentChar.data.customscript[i]} onRemove={() => {
if(currentChar.type === 'character'){
let customscript = currentChar.data.customscript
customscript.splice(i, 1)
currentChar.data.customscript = customscript
}
}}/>
{/each}
</table>
<button class="font-medium cursor-pointer hover:text-green-500 mb-2" on:click={() => {
if(currentChar.type === 'character'){
let script = currentChar.data.customscript
script.push({
comment: "",
in: "",
out: "",
type: "editinput"
})
currentChar.data.customscript = script
}
}}><PlusIcon /></button>
{/if}
{:else if subMenu === 2}
<h2 class="mb-2 text-2xl font-bold mt-2">{language.advancedSettings}</h2>
{#if currentChar.type !== 'group'}
<span class="text-neutral-200">{language.exampleMessage} <Help key="exampleMessage"/></span>
<textarea class="bg-transparent input-text mt-2 mb-2 text-gray-200 text-xs resize-none h-20 focus:bg-selected" autocomplete="off" bind:value={currentChar.data.exampleMessage}></textarea>
<span class="text-neutral-200">{language.creatorNotes} <Help key="creatorQuotes"/></span>
<textarea class="bg-transparent input-text mt-2 mb-2 text-gray-200 text-xs resize-none h-20 focus:bg-selected" autocomplete="off" bind:value={currentChar.data.creatorNotes} on:input={() => {
currentChar.data.removedQuotes = false
}}></textarea>
<span class="text-neutral-200">{language.systemPrompt} <Help key="systemPrompt"/></span>
<textarea class="bg-transparent input-text mt-2 mb-2 text-gray-200 text-xs resize-none h-20 focus:bg-selected" autocomplete="off" bind:value={currentChar.data.systemPrompt}></textarea>
<span class="text-neutral-200">{language.chatNotes} <Help key="chatNote"/></span>
<textarea class="bg-transparent input-text mt-2 mb-2 text-gray-200 resize-none h-20 focus:bg-selected text-xs" autocomplete="off" bind:value={currentChar.data.chats[currentChar.data.chatPage].note}></textarea>
<span class="text-gray-400 mb-6 text-sm">{tokens.localNote} {language.tokens}</span>
{#if $DataBase.showUnrecommended || currentChar.data.personality.length > 3}
<span class="text-neutral-200">{language.personality} <Help key="personality" unrecommended/></span>
<textarea class="bg-transparent input-text mt-2 mb-2 text-gray-200 text-xs resize-none h-20 focus:bg-selected" autocomplete="off" bind:value={currentChar.data.personality}></textarea>
{/if}
{#if $DataBase.showUnrecommended || currentChar.data.scenario.length > 3}
<span class="text-neutral-200">{language.scenario} <Help key="scenario" unrecommended/></span>
<textarea class="bg-transparent input-text mt-2 mb-2 text-gray-200 text-xs resize-none h-20 focus:bg-selected" autocomplete="off" bind:value={currentChar.data.scenario}></textarea>
{/if}
<span class="text-neutral-200 mt-2">{language.altGreet} <Help key="bias"/></span>
<table class="contain w-full max-w-full tabler mt-2">
<tr>
@@ -476,33 +514,6 @@
{/each}
</table>
<span class="text-neutral-200 mt-4">{language.regexScript} <Help key="regexScript"/></span>
<table class="contain w-full max-w-full tabler mt-2 flex flex-col p-2 gap-2">
{#if currentChar.data.customscript.length === 0}
<div class="text-gray-500">No Scripts</div>
{/if}
{#each currentChar.data.customscript as customscript, i}
<RegexData bind:value={currentChar.data.customscript[i]} onRemove={() => {
if(currentChar.type === 'character'){
let customscript = currentChar.data.customscript
customscript.splice(i, 1)
currentChar.data.customscript = customscript
}
}}/>
{/each}
</table>
<button class="font-medium cursor-pointer hover:text-green-500 mb-2" on:click={() => {
if(currentChar.type === 'character'){
let script = currentChar.data.customscript
script.push({
comment: "",
in: "",
out: "",
type: "editinput"
})
currentChar.data.customscript = script
}
}}><PlusIcon /></button>
{#if $DataBase.showUnrecommended || currentChar.data.utilityBot}
<div class="flex items-center mt-4">

View File

@@ -13,6 +13,7 @@
<div class="w-full flex flex-col">
<div class="flex items-center transition-colors w-full ">
<button class="endflex valuer border-borderc" on:click={() => {
value.secondkey = value.secondkey ?? ''
open = !open
}}>
<span>{value.comment.length === 0 ? 'Unnamed Lore' : value.comment}</span>
@@ -34,15 +35,25 @@
<span class="text-neutral-200 mt-6">{language.activationKeys} <Help key="loreActivationKey"/></span>
<span class="text-xs text-gray-500">{language.activationKeysInfo}</span>
<input class="text-neutral-200 p-2 bg-transparent input-text focus:bg-selected text-sm" bind:value={value.key}>
{#if value.selective}
<span class="text-neutral-200 mt-6">{language.SecondaryKeys}</span>
<span class="text-xs text-gray-500">{language.activationKeysInfo}</span>
<input class="text-neutral-200 p-2 bg-transparent input-text focus:bg-selected text-sm" bind:value={value.secondkey}>
{/if}
{/if}
<span class="text-neutral-200 mt-4">{language.insertOrder} <Help key="loreorder"/></span>
<input class="text-neutral-200 p-2 bg-transparent input-text focus:bg-selected text-sm" bind:value={value.insertorder} type="number" min={0} max={1000}>
<span class="text-neutral-200 mt-4">{language.prompt}</span>
<textarea class="bg-transparent input-text mt-2 text-gray-200 resize-none h-20 focus:bg-selected text-xs" autocomplete="off" bind:value={value.content}></textarea>
<div class="flex items-center mt-4 mb-6">
<div class="flex items-center mt-4">
<Check bind:check={value.alwaysActive}/>
<span>{language.alwaysActive}</span>
</div>
<div class="flex items-center mt-2 mb-6">
<Check bind:check={value.selective}/>
<span>{language.selective} <Help key="loreSelective"/></span>
</div>
</div>
{/if}
</div>

View File

@@ -3,7 +3,7 @@
import { language } from "../../lang";
import {selectedCharID} from '../../ts/stores'
import { DownloadIcon, FolderUpIcon, ImportIcon, PlusIcon } from "lucide-svelte";
import { addLorebook, exportLoreBook, importLoreBook } from "../../ts/lorebook";
import { addLorebook, exportLoreBook, importLoreBook } from "../../ts/process/lorebook";
import LoreBookData from "./LoreBookData.svelte";
let submenu = 0
</script>
@@ -19,6 +19,11 @@
}} class="flex-1 border-solid border-borderc border-1 border-l-transparent p-2 flex justify-center cursor-pointer" class:bg-selected={submenu === 1}>
<span>{language.Chat}</span>
</button>
<button on:click={() => {
submenu = 2
}} class="flex-1 border-solid border-borderc border-1 border-l-transparent p-2 flex justify-center cursor-pointer" class:bg-selected={submenu === 2}>
<span>{language.settings}</span>
</button>
</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>

View File

@@ -216,11 +216,13 @@ export interface customscript{
export interface loreBook{
key:string
secondkey:string
insertorder: number
comment: string
content: string
mode: 'multiple'|'constant'|'normal',
alwaysActive: boolean
selective:boolean
}
export interface character{

View File

@@ -4,7 +4,7 @@ import { CharEmotion, selectedCharID } from "../stores";
import { tokenize, tokenizeNum } from "../tokenizer";
import { language } from "../../lang";
import { alertError } from "../alert";
import { loadLoreBookPrompt } from "../lorebook";
import { loadLoreBookPrompt } from "./lorebook";
import { findCharacterbyId, replacePlaceholders } from "../util";
import { requestChatData } from "./request";
import { stableDiff } from "./stableDiff";

View File

@@ -1,11 +1,11 @@
import { get } from "svelte/store";
import {selectedCharID} from './stores'
import { DataBase, setDatabase, type loreBook } from "./database";
import { tokenize } from "./tokenizer";
import { selectSingleFile } from "./util";
import { alertError, alertNormal } from "./alert";
import { language } from "../lang";
import { downloadFile } from "./globalApi";
import {selectedCharID} from '../stores'
import { DataBase, setDatabase, type loreBook } from "../database";
import { tokenize } from "../tokenizer";
import { selectSingleFile } from "../util";
import { alertError, alertNormal } from "../alert";
import { language } from "../../lang";
import { downloadFile } from "../globalApi";
export function addLorebook(type:number) {
let selectedID = get(selectedCharID)
@@ -17,7 +17,9 @@ export function addLorebook(type:number) {
content: '',
mode: 'normal',
insertorder: 100,
alwaysActive: false
alwaysActive: false,
secondkey: "",
selective: false
})
}
else{
@@ -28,14 +30,17 @@ export function addLorebook(type:number) {
content: '',
mode: 'normal',
insertorder: 100,
alwaysActive: false
alwaysActive: false,
secondkey: "",
selective: false
})
}
setDatabase(db)
}
interface formatedLore{
keys:string[]|'always'
keys:string[]|'always',
secondKey:string[]
content: string
order: number
}
@@ -61,6 +66,9 @@ export async function loadLoreBookPrompt(){
keys: lore.alwaysActive ? 'always' : 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
}) : [],
content: lore.content,
order: lore.insertorder
})
@@ -86,7 +94,20 @@ export async function loadLoreBookPrompt(){
continue
}
let firstKeyActivation = false
for(const key of lore.keys){
if(formatedChat.includes(key)){
firstKeyActivation = true
break
}
}
if(firstKeyActivation && lore.secondKey.length === 0){
activatiedPrompt.push(lore.content)
continue
}
for(const key of lore.secondKey){
if(formatedChat.includes(key)){
activatiedPrompt.push(lore.content)
break
@@ -132,7 +153,9 @@ export async function importLoreBook(mode:'global'|'local'){
comment: currentLore.comment.length < 1 ? 'Unnamed Imported Lore' : currentLore.comment,
content: currentLore.content,
mode: "normal",
alwaysActive: currentLore.constant
alwaysActive: currentLore.constant,
secondkey: "",
selective: false
})
}
}