feat: Add custom toggles
This commit is contained in:
@@ -127,6 +127,7 @@ export const languageEnglish = {
|
||||
nickname: "Nickname would used be in {{char}} or <char> in chat instead of character's name if it is set.",
|
||||
useRegexLorebook: "If enabled, it will use regex for lorebook search, instead of string matching. it uses /regex/flags format.",
|
||||
customChainOfThought: "Warning: chain of thought toggle is no longer recommended to use. put chain of thought prompt in other prompt entries instead.",
|
||||
customPromptTemplateToggle: "Here you can define your own prompt toggles. use `<toggle variable>=<toggle name>` format, seperated by newline. for example, `cot=Toggle COT`. you can use these toggles in prompt by using `{{getglobalvar::toggle_<toggle variable>}}`. like `{{getglobalvar::toggle_cot}}`.",
|
||||
},
|
||||
setup: {
|
||||
chooseProvider: "Choose AI Provider",
|
||||
@@ -608,5 +609,6 @@ export const languageEnglish = {
|
||||
risupresetDesc: "Risupreset format is a format specifically designed for RisuAI presets.",
|
||||
jsonDesc: "JSON format is a format that is easy to read and write for both humans and machines.",
|
||||
nickname: "Nickname",
|
||||
useRegexLorebook: "Use Regex"
|
||||
useRegexLorebook: "Use Regex",
|
||||
customPromptTemplateToggle: "Custom Toggles",
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
import TextInput from "src/lib/UI/GUI/TextInput.svelte";
|
||||
import NumberInput from "src/lib/UI/GUI/NumberInput.svelte";
|
||||
import Help from "src/lib/Others/Help.svelte";
|
||||
import TextAreaInput from "src/lib/UI/GUI/TextAreaInput.svelte";
|
||||
|
||||
let sorted = 0
|
||||
let opened = 0
|
||||
@@ -117,4 +118,6 @@
|
||||
{/if}
|
||||
<span class="text-textcolor mt-4">{language.maxThoughtTagDepth}</span>
|
||||
<NumberInput bind:value={$DataBase.promptSettings.maxThoughtTagDepth}/>
|
||||
<span class="text-textcolor mt-4">{language.customPromptTemplateToggle} <Help key='customPromptTemplateToggle' /></span>
|
||||
<TextAreaInput bind:value={$DataBase.customPromptTemplateToggle}/>
|
||||
{/if}
|
||||
@@ -29,6 +29,7 @@
|
||||
import { updateInlayScreen } from "src/ts/process/inlayScreen";
|
||||
import { registerOnnxModel } from "src/ts/process/transformers";
|
||||
import MultiLangInput from "../UI/GUI/MultiLangInput.svelte";
|
||||
import { getCustomToggles } from "src/ts/process/prompt";
|
||||
|
||||
|
||||
let subMenu = 0
|
||||
@@ -246,6 +247,14 @@
|
||||
<div class="flex mt-6 items-center">
|
||||
<Check bind:check={$DataBase.jailbreakToggle} name={language.jailbreakToggle}/>
|
||||
</div>
|
||||
|
||||
{#each getCustomToggles($DataBase.customPromptTemplateToggle) as toggle}
|
||||
<div class="flex mt-2 items-center">
|
||||
<Check check={$DataBase.globalChatVariables[`toggle_${toggle[0]}`] === '1'} name={toggle[1]} onChange={() => {
|
||||
$DataBase.globalChatVariables[`toggle_${toggle[0]}`] = $DataBase.globalChatVariables[`toggle_${toggle[0]}`] === '1' ? '0' : '1'
|
||||
}} />
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
{#if $DataBase.supaMemoryType !== 'none' || $DataBase.hanuraiEnable}
|
||||
{#if $DataBase.hanuraiEnable}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import type { character, groupChat } from "src/ts/storage/database";
|
||||
import { DataBase } from "src/ts/storage/database";
|
||||
import TextInput from "../UI/GUI/TextInput.svelte";
|
||||
import { DownloadIcon, EditIcon, FolderUpIcon, MenuIcon, TrashIcon } from "lucide-svelte";
|
||||
import { DownloadIcon, PencilIcon, FolderUpIcon, MenuIcon, TrashIcon } from "lucide-svelte";
|
||||
import { exportChat, importChat } from "src/ts/characters";
|
||||
import { alertConfirm, alertError, alertSelect } from "src/ts/alert";
|
||||
import { language } from "src/lang";
|
||||
@@ -11,6 +11,7 @@
|
||||
import CheckInput from "../UI/GUI/CheckInput.svelte";
|
||||
import { createMultiuserRoom } from "src/ts/sync/multiuser";
|
||||
import { CurrentCharacter } from "src/ts/stores";
|
||||
import { getCustomToggles } from "src/ts/process/prompt";
|
||||
export let chara:character|groupChat
|
||||
let editMode = false
|
||||
</script>
|
||||
@@ -62,7 +63,7 @@
|
||||
<button class="text-textcolor2 hover:text-green-500 mr-1 cursor-pointer" on:click={() => {
|
||||
editMode = !editMode
|
||||
}}>
|
||||
<EditIcon size={18}/>
|
||||
<PencilIcon size={18}/>
|
||||
</button>
|
||||
<button class="text-textcolor2 hover:text-green-500 mr-1 cursor-pointer" on:click={async (e) => {
|
||||
e.stopPropagation()
|
||||
@@ -101,7 +102,7 @@
|
||||
<button class="text-textcolor2 hover:text-green-500 cursor-pointer" on:click={() => {
|
||||
editMode = !editMode
|
||||
}}>
|
||||
<EditIcon size={18}/>
|
||||
<PencilIcon size={18}/>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -110,6 +111,14 @@
|
||||
<CheckInput bind:check={$DataBase.jailbreakToggle} name={language.jailbreakToggle}/>
|
||||
</div>
|
||||
|
||||
{#each getCustomToggles($DataBase.customPromptTemplateToggle) as toggle}
|
||||
<div class="flex mt-2 items-center">
|
||||
<CheckInput check={$DataBase.globalChatVariables[`toggle_${toggle[0]}`] === '1'} name={toggle[1]} onChange={() => {
|
||||
$DataBase.globalChatVariables[`toggle_${toggle[0]}`] = $DataBase.globalChatVariables[`toggle_${toggle[0]}`] === '1' ? '0' : '1'
|
||||
}} />
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
{#if $DataBase.supaMemoryType !== 'none' || $DataBase.hanuraiEnable}
|
||||
{#if $DataBase.hanuraiEnable}
|
||||
<div class="flex mt-2 items-center">
|
||||
|
||||
@@ -783,6 +783,9 @@ const matcher = (p1:string,matcherArg:matcherArg) => {
|
||||
}
|
||||
return null
|
||||
}
|
||||
case 'getglobalvar':{
|
||||
return getGlobalChatVar(v)
|
||||
}
|
||||
case 'button':{
|
||||
return `<button class="button-default" risu-trigger="${arra[2]}">${arra[1]}</button>`
|
||||
}
|
||||
@@ -1461,6 +1464,11 @@ export function getChatVar(key:string){
|
||||
return (chat.scriptstate['$' + key])?.toString() ?? 'null'
|
||||
}
|
||||
|
||||
export function getGlobalChatVar(key:string){
|
||||
const db = get(DataBase)
|
||||
return db.globalChatVariables[key] ?? 'null'
|
||||
}
|
||||
|
||||
export function setChatVar(key:string, value:string){
|
||||
const db = get(DataBase)
|
||||
const selectedChar = get(selectedCharID)
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { get } from "svelte/store";
|
||||
import { tokenizeAccurate } from "../tokenizer";
|
||||
import type { Database } from "../storage/database";
|
||||
|
||||
export type PromptItem = PromptItemPlain|PromptItemTyped|PromptItemChat|PromptItemAuthorNote;
|
||||
export type PromptType = PromptItem['type'];
|
||||
@@ -61,4 +63,21 @@ export async function tokenizePreset(prompts:PromptItem[], consti:boolean = fals
|
||||
}
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
export function getCustomToggles(template:string){
|
||||
if(!template){
|
||||
return []
|
||||
}
|
||||
|
||||
const keyValue:[string, string][] = []
|
||||
|
||||
for(const line of template.split('\n')){
|
||||
const [key, value] = line.split('=')
|
||||
if(key && value){
|
||||
keyValue.push([key, value])
|
||||
}
|
||||
}
|
||||
|
||||
return keyValue
|
||||
}
|
||||
@@ -400,6 +400,8 @@ export function setDatabase(data:Database){
|
||||
data.sideBarSize ??= 0
|
||||
data.textAreaTextSize ??= 0
|
||||
data.combineTranslation ??= false
|
||||
data.customPromptTemplateToggle ??= ''
|
||||
data.globalChatVariables ??= {}
|
||||
|
||||
changeLanguage(data.language)
|
||||
DataBase.set(data)
|
||||
@@ -657,7 +659,8 @@ export interface Database{
|
||||
combineTranslation:boolean
|
||||
dynamicAssets:boolean
|
||||
dynamicAssetsEditDisplay:boolean
|
||||
|
||||
customPromptTemplateToggle:string
|
||||
globalChatVariables:{[key:string]:string}
|
||||
}
|
||||
|
||||
export interface customscript{
|
||||
@@ -878,6 +881,7 @@ export interface botPreset{
|
||||
top_a?:number
|
||||
openrouterProvider?:string
|
||||
useInstructPrompt?:boolean
|
||||
customPromptTemplateToggle?:string
|
||||
}
|
||||
|
||||
|
||||
@@ -1144,7 +1148,8 @@ export function saveCurrentPreset(){
|
||||
min_p: db.min_p,
|
||||
top_a: db.top_a,
|
||||
openrouterProvider: db.openrouterProvider,
|
||||
useInstructPrompt: db.useInstructPrompt
|
||||
useInstructPrompt: db.useInstructPrompt,
|
||||
customPromptTemplateToggle: db.customPromptTemplateToggle ?? ""
|
||||
}
|
||||
db.botPresets = pres
|
||||
setDatabase(db)
|
||||
@@ -1227,6 +1232,7 @@ export function setPreset(db:Database, newPres: botPreset){
|
||||
db.top_a = newPres.top_a
|
||||
db.openrouterProvider = newPres.openrouterProvider
|
||||
db.useInstructPrompt = newPres.useInstructPrompt ?? false
|
||||
db.customPromptTemplateToggle = newPres.customPromptTemplateToggle ?? ''
|
||||
return db
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user