From dc6124d2abb025ee152a8d7015b1aa7db294840d Mon Sep 17 00:00:00 2001 From: Bo26fhmC5M <88071760+Bo26fhmC5M@users.noreply.github.com> Date: Fri, 31 Jan 2025 23:33:57 +0900 Subject: [PATCH] feat: display estimated max memory tokens ratio in HypaV3 settings --- src/lib/Setting/Pages/OtherBotSettings.svelte | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/lib/Setting/Pages/OtherBotSettings.svelte b/src/lib/Setting/Pages/OtherBotSettings.svelte index 42c05a1f..fe450fc4 100644 --- a/src/lib/Setting/Pages/OtherBotSettings.svelte +++ b/src/lib/Setting/Pages/OtherBotSettings.svelte @@ -17,6 +17,9 @@ import CheckInput from "src/lib/UI/GUI/CheckInput.svelte"; import TextAreaInput from "src/lib/UI/GUI/TextAreaInput.svelte"; import { untrack } from "svelte"; + import { tokenizePreset } from "src/ts/process/prompt"; + import { getCharToken } from "src/ts/tokenizer"; + import { selectedCharID } from "src/ts/stores.svelte"; $effect.pre(() => { DBState.db.NAIImgConfig ??= { @@ -53,7 +56,7 @@ DBState.db.hypaV3Settings.similarMemoryRatio = 1 - newValue; } }) - }) + }); $effect(() => { const newValue = Math.min(DBState.db.hypaV3Settings.similarMemoryRatio, 1); @@ -66,6 +69,24 @@ } }) }); + + async function getMaxMemoryRatio(): Promise { + const promptTemplateToken = await tokenizePreset(DBState.db.promptTemplate); + const char = DBState.db.characters[$selectedCharID]; + const charToken = await getCharToken(char); + const maxLoreToken = char.loreSettings?.tokenBudget ?? DBState.db.loreBookToken; + const maxResponse = DBState.db.maxResponse; + const requiredToken = promptTemplateToken + charToken.persistant + Math.min(charToken.dynamic, maxLoreToken) + maxResponse * 3; + const maxContext = DBState.db.maxContext; + + if (maxContext === 0) { + return 0; + } + + const maxMemoryRatio = Math.max((maxContext - requiredToken) / maxContext, 0); + + return parseFloat(maxMemoryRatio.toFixed(2)); + } // End HypaV3

{language.otherBots}

@@ -500,7 +521,13 @@ {language.summarizationPrompt}
-
+ + Max Memory Tokens Ratio (Estimated) + {#await getMaxMemoryRatio() then maxMemoryRatio} + + {:catch error} + {error} + {/await} Memory Tokens Ratio Extra Summarization Ratio