feat: Add default variables to character settings
This commit is contained in:
@@ -128,6 +128,7 @@ export const languageEnglish = {
|
||||
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}}`.",
|
||||
defaultVariables: "Here you can define your own default variables. use `<variable name>=<variable value>` format, seperated by newline. for example, `name=RisuAI`, which then can be used with trigger scripts and variables CBS like `{{getvar::A}}`, `{{setvar::A::B}}` or `{{? $A + 1}}`. if prompt template's default variable and character's default variable has same name, character's default variable will be used.",
|
||||
},
|
||||
setup: {
|
||||
chooseProvider: "Choose AI Provider",
|
||||
@@ -611,4 +612,5 @@ export const languageEnglish = {
|
||||
nickname: "Nickname",
|
||||
useRegexLorebook: "Use Regex",
|
||||
customPromptTemplateToggle: "Custom Toggles",
|
||||
defaultVariables: "Default Variables"
|
||||
}
|
||||
@@ -120,4 +120,6 @@
|
||||
<NumberInput bind:value={$DataBase.promptSettings.maxThoughtTagDepth}/>
|
||||
<span class="text-textcolor mt-4">{language.customPromptTemplateToggle} <Help key='customPromptTemplateToggle' /></span>
|
||||
<TextAreaInput bind:value={$DataBase.customPromptTemplateToggle}/>
|
||||
<span class="text-textcolor mt-4">{language.defaultVariables} <Help key='defaultVariables' /></span>
|
||||
<TextAreaInput bind:value={$DataBase.templateDefaultVariables}/>
|
||||
{/if}
|
||||
@@ -254,6 +254,7 @@
|
||||
}} />
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
|
||||
{#if $DataBase.supaMemoryType !== 'none' || $DataBase.hanuraiEnable}
|
||||
{#if $DataBase.hanuraiEnable}
|
||||
@@ -764,6 +765,9 @@
|
||||
<span class="text-textcolor mt-2">{language.backgroundHTML} <Help key="backgroundHTML" /></span>
|
||||
<TextAreaInput highlight margin="both" autocomplete="off" bind:value={currentChar.data.backgroundHTML}></TextAreaInput>
|
||||
|
||||
<span class="text-textcolor mt-2">{language.defaultVariables} <Help key="defaultVariables" /></span>
|
||||
<TextAreaInput highlight margin="both" autocomplete="off" bind:value={currentChar.data.defaultVariables}></TextAreaInput>
|
||||
|
||||
<span class="text-textcolor">{language.creator}</span>
|
||||
<TextInput size="sm" autocomplete="off" bind:value={currentChar.data.additionalData.creator} />
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import { get } from 'svelte/store';
|
||||
import css from '@adobe/css-tools'
|
||||
import { selectedCharID } from './stores';
|
||||
import { calcString } from './process/infunctions';
|
||||
import { findCharacterbyId, sfc32, uuidtoNumber } from './util';
|
||||
import { findCharacterbyId, parseKeyValue, sfc32, uuidtoNumber } from './util';
|
||||
import { getInlayImage } from './process/files/image';
|
||||
import { autoMarkNew } from './plugins/automark';
|
||||
import { getModuleLorebooks } from './process/modules';
|
||||
@@ -1461,7 +1461,18 @@ export function getChatVar(key:string){
|
||||
}
|
||||
const chat = char.chats[char.chatPage]
|
||||
chat.scriptstate = chat.scriptstate ?? {}
|
||||
return (chat.scriptstate['$' + key])?.toString() ?? 'null'
|
||||
const state = (chat.scriptstate['$' + key])
|
||||
if(state === undefined || state === null){
|
||||
const defaultVariables = parseKeyValue(char.defaultVariables).concat(parseKeyValue(db.templateDefaultVariables))
|
||||
const findResult = defaultVariables.find((f) => {
|
||||
return f[0] === key
|
||||
})
|
||||
if(findResult){
|
||||
return findResult[1]
|
||||
}
|
||||
return 'null'
|
||||
}
|
||||
return state.toString()
|
||||
}
|
||||
|
||||
export function getGlobalChatVar(key:string){
|
||||
|
||||
@@ -5,6 +5,7 @@ import { getModuleTriggers } from "./modules";
|
||||
import { get } from "svelte/store";
|
||||
import { CurrentCharacter, CurrentChat, selectedCharID } from "../stores";
|
||||
import { processMultiCommand } from "./command";
|
||||
import { parseKeyValue } from "../util";
|
||||
|
||||
export interface triggerscript{
|
||||
comment: string;
|
||||
@@ -94,13 +95,25 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
|
||||
promptend: ''
|
||||
}
|
||||
const triggers = char.triggerscript.concat(getModuleTriggers())
|
||||
const db = get(DataBase)
|
||||
const defaultVariables = parseKeyValue(char.defaultVariables).concat(parseKeyValue(db.templateDefaultVariables))
|
||||
let chat = structuredClone(arg.chat ?? char.chats[char.chatPage])
|
||||
if((!triggers) || (triggers.length === 0)){
|
||||
return null
|
||||
}
|
||||
|
||||
function getVar(key:string){
|
||||
return `${chat.scriptstate?.['$' + key] ?? "null"}`
|
||||
const state = chat.scriptstate?.['$' + key]
|
||||
if(state === undefined || state === null){
|
||||
const findResult = defaultVariables.find((f) => {
|
||||
return f[0] === key
|
||||
})
|
||||
if(findResult){
|
||||
return findResult[1]
|
||||
}
|
||||
return 'null'
|
||||
}
|
||||
return state.toString()
|
||||
}
|
||||
|
||||
function setVar(key:string, value:string){
|
||||
|
||||
@@ -402,6 +402,7 @@ export function setDatabase(data:Database){
|
||||
data.combineTranslation ??= false
|
||||
data.customPromptTemplateToggle ??= ''
|
||||
data.globalChatVariables ??= {}
|
||||
data.templateDefaultVariables ??= ''
|
||||
|
||||
changeLanguage(data.language)
|
||||
DataBase.set(data)
|
||||
@@ -661,6 +662,7 @@ export interface Database{
|
||||
dynamicAssetsEditDisplay:boolean
|
||||
customPromptTemplateToggle:string
|
||||
globalChatVariables:{[key:string]:string}
|
||||
templateDefaultVariables:string
|
||||
}
|
||||
|
||||
export interface customscript{
|
||||
@@ -789,6 +791,7 @@ export interface character{
|
||||
name: string
|
||||
ext: string
|
||||
}>
|
||||
defaultVariables?:string
|
||||
}
|
||||
|
||||
|
||||
@@ -834,6 +837,7 @@ export interface groupChat{
|
||||
lorePlus?:boolean
|
||||
trashTime?:number
|
||||
nickname?:string
|
||||
defaultVariables?:string
|
||||
}
|
||||
|
||||
export interface botPreset{
|
||||
@@ -882,6 +886,7 @@ export interface botPreset{
|
||||
openrouterProvider?:string
|
||||
useInstructPrompt?:boolean
|
||||
customPromptTemplateToggle?:string
|
||||
templateDefaultVariables?:string
|
||||
}
|
||||
|
||||
|
||||
@@ -1149,7 +1154,8 @@ export function saveCurrentPreset(){
|
||||
top_a: db.top_a,
|
||||
openrouterProvider: db.openrouterProvider,
|
||||
useInstructPrompt: db.useInstructPrompt,
|
||||
customPromptTemplateToggle: db.customPromptTemplateToggle ?? ""
|
||||
customPromptTemplateToggle: db.customPromptTemplateToggle ?? "",
|
||||
templateDefaultVariables: db.templateDefaultVariables ?? ""
|
||||
}
|
||||
db.botPresets = pres
|
||||
setDatabase(db)
|
||||
@@ -1233,6 +1239,7 @@ export function setPreset(db:Database, newPres: botPreset){
|
||||
db.openrouterProvider = newPres.openrouterProvider
|
||||
db.useInstructPrompt = newPres.useInstructPrompt ?? false
|
||||
db.customPromptTemplateToggle = newPres.customPromptTemplateToggle ?? ''
|
||||
db.templateDefaultVariables = newPres.templateDefaultVariables ?? ''
|
||||
return db
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user