feat: Implement HypaV3 ratio-based memory

This commit is contained in:
Bo26fhmC5M
2025-01-12 01:45:49 +09:00
parent 3b533e911f
commit 50361d7aa2
9 changed files with 1004 additions and 7 deletions

View File

@@ -16,6 +16,7 @@
import Arcodion from "src/lib/UI/Arcodion.svelte";
import CheckInput from "src/lib/UI/GUI/CheckInput.svelte";
import TextAreaInput from "src/lib/UI/GUI/TextAreaInput.svelte";
import { hypaMemoryV3 } from "src/ts/process/memory/hypav3";
$effect.pre(() => {
DBState.db.NAIImgConfig ??= {
width: 512,
@@ -387,6 +388,7 @@
<span class="text-textcolor mt-4">{language.type}</span>
<SelectInput value={
DBState.db.hypaV3 ? 'hypaV3' :
DBState.db.hypav2 ? 'hypaV2' :
DBState.db.supaModelType !== 'none' ? 'supaMemory' :
DBState.db.hanuraiEnable ? 'hanuraiMemory' : 'none'
@@ -398,27 +400,38 @@
DBState.db.memoryAlgorithmType = 'supaMemory'
DBState.db.hypav2 = false
DBState.db.hanuraiEnable = false
DBState.db.hypaV3 = false
} else if (value === 'hanuraiMemory'){
DBState.db.supaModelType = 'none'
DBState.db.memoryAlgorithmType = 'hanuraiMemory'
DBState.db.hypav2 = false
DBState.db.hanuraiEnable = true
DBState.db.hypaV3 = false
} else if (value === 'hypaV2') {
DBState.db.supaModelType = 'distilbart'
DBState.db.memoryAlgorithmType = 'hypaMemoryV2'
DBState.db.hypav2= true
DBState.db.hanuraiEnable = false
DBState.db.hypaV3 = false
} else if (value === 'hypaV3') {
DBState.db.supaModelType = 'subModel'
DBState.db.memoryAlgorithmType = 'hypaMemoryV3'
DBState.db.hypav2 = false
DBState.db.hanuraiEnable = false
DBState.db.hypaV3 = true
} else {
DBState.db.supaModelType = 'none'
DBState.db.memoryAlgorithmType = 'none'
DBState.db.hypav2 = false
DBState.db.hanuraiEnable = false
DBState.db.hypaV3 = false
}
}}>
<OptionInput value="none" >None</OptionInput>
<OptionInput value="supaMemory" >{language.SuperMemory}</OptionInput>
<OptionInput value="hypaV2" >{language.HypaMemory} V2</OptionInput>
<OptionInput value="hanuraiMemory" >{language.hanuraiMemory}</OptionInput>
<OptionInput value="hypaV3" >{language.HypaMemory} V3</OptionInput>
</SelectInput>
{#if DBState.db.hanuraiEnable}
@@ -446,7 +459,41 @@
<NumberInput size="sm" marginBottom bind:value={DBState.db.hypaChunkSize} min={100} />
<span class="text-textcolor">{language.hypaAllocatedTokens}</span>
<NumberInput size="sm" marginBottom bind:value={DBState.db.hypaAllocatedTokens} min={100} />
{:else if (DBState.db.supaModelType !== 'none' && DBState.db.hypav2 === false)}
{:else if DBState.db.hypaV3}
<span class="mb-2 text-textcolor2 text-sm text-wrap break-words max-w-full">{language.hypaV3Desc}</span>
<span class="text-textcolor mt-4">{language.SuperMemory} {language.model}</span>
<SelectInput className="mt-2 mb-2" bind:value={DBState.db.supaModelType}>
<OptionInput value="distilbart">distilbart-cnn-6-6 (Free/Local)</OptionInput>
<OptionInput value="instruct35">OpenAI 3.5 Turbo Instruct</OptionInput>
<OptionInput value="subModel">{language.submodel}</OptionInput>
</SelectInput>
{#if DBState.db.supaModelType === 'instruct35'}
<span class="text-textcolor">OpenAI API Key</span>
<TextInput size="sm" marginBottom bind:value={DBState.db.supaMemoryKey}/>
{/if}
<span class="text-textcolor">{language.summarizationPrompt} <Help key="summarizationPrompt"/></span>
<div class="mb-2">
<TextAreaInput size="sm" bind:value={DBState.db.supaMemoryPrompt} placeholder="Leave it blank to use default"/>
</div>
<span class="text-textcolor">Memory Tokens Ratio</span>
<SliderInput marginBottom min={0} max={1} step={0.01} fixed={2} bind:value={DBState.db.hypaV3Settings.memoryTokensRatio}/>
<span class="text-textcolor">Extra Summarization Ratio</span>
<SliderInput marginBottom min={0} max={1-DBState.db.hypaV3Settings.memoryTokensRatio} step={0.01} fixed={2} bind:value={DBState.db.hypaV3Settings.extraSummarizationRatio}/>
<span class="text-textcolor">Max Chats Per Summary</span>
<NumberInput size="sm" marginBottom bind:value={DBState.db.hypaV3Settings.maxChatsPerSummary} min={1} />
<span class="text-textcolor">Recent Memory Ratio</span>
<NumberInput size="sm" marginBottom value={parseFloat((1 - DBState.db.hypaV3Settings.similarMemoryRatio - DBState.db.hypaV3Settings.randomMemoryRatio).toFixed(2))} disabled/>
<span class="text-textcolor">Similar Memory Ratio</span>
<SliderInput marginBottom min={0} max={1} step={0.01} fixed={2} bind:value={DBState.db.hypaV3Settings.similarMemoryRatio}/>
<span class="text-textcolor">Random Memory Ratio</span>
<SliderInput marginBottom min={0} max={1} step={0.01} fixed={2} bind:value={DBState.db.hypaV3Settings.randomMemoryRatio}/>
<div class="flex mb-2">
<Check bind:check={DBState.db.hypaV3Settings.enableSimilarityCorrection} name="Enable Similarity Correction"/>
</div>
<div class="flex mb-2">
<Check bind:check={DBState.db.hypaV3Settings.preserveOrphanedMemory} name="Preserve Orphaned Memory"/>
</div>
{:else if (DBState.db.supaModelType !== 'none' && DBState.db.hypav2 === false && DBState.db.hypaV3 === false)}
<span class="mb-2 text-textcolor2 text-sm text-wrap break-words max-w-full">{language.supaDesc}</span>
<span class="text-textcolor mt-4">{language.SuperMemory} {language.model}</span>
<SelectInput className="mt-2 mb-2" bind:value={DBState.db.supaModelType}>