feat: add doNotSummarizeUserChat option in HypaV3

- Add doNotSummarizeUserChat option to exclude user messages from summarization
- Add early return logic to prevent unnecessary similarity checks when summaries are empty
This commit is contained in:
Bo26fhmC5M
2025-02-07 21:08:50 +09:00
parent 7b57bdf5f1
commit 6d79f45d32
3 changed files with 47 additions and 5 deletions

View File

@@ -522,11 +522,11 @@
<div class="mb-2">
<TextAreaInput size="sm" placeholder="Leave it blank to use default" bind:value={DBState.db.supaMemoryPrompt} />
</div>
<span class="text-textcolor">Max Memory Tokens Ratio (Estimated)</span>
{#await getMaxMemoryRatio() then maxMemoryRatio}
<span class="text-textcolor">Max Memory Tokens Ratio (Estimated)</span>
<NumberInput marginBottom disabled size="sm" value={maxMemoryRatio} />
{:catch error}
<span class="text-textcolor">{error}</span>
<span class="text-red-400">Unable to calculate Max Memory Tokens Ratio</span>
{/await}
<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} />
@@ -547,8 +547,11 @@
<Check name="Preserve Orphaned Memory" bind:check={DBState.db.hypaV3Settings.preserveOrphanedMemory} />
</div>
<div class="flex mb-2">
<Check name="Process Regex Script (Reroll Only)" bind:check={DBState.db.hypaV3Settings.processRegexScript} />
</div>
<Check name="Apply Regex Script When Rerolling" bind:check={DBState.db.hypaV3Settings.processRegexScript} />
</div>
<div class="flex mb-2">
<Check name="Do Not Summarize User Chat" bind:check={DBState.db.hypaV3Settings.doNotSummarizeUserChat} />
</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>

View File

@@ -421,6 +421,12 @@ export async function hypaMemoryV3(
continue;
}
if (db.hypaV3Settings.doNotSummarizeUserChat && chat.role === "user") {
console.log(`[HypaV3] Skipping user role at index ${i}`);
continue;
}
toSummarize.push(chat);
}
@@ -469,6 +475,37 @@ export async function hypaMemoryV3(
availableMemoryTokens
);
// Early return if no summaries
if (data.summaries.length === 0) {
// Generate final memory prompt
const memory = encapsulateMemoryPrompt("");
const newChats: OpenAIChat[] = [
{
role: "system",
content: memory,
memo: "supaMemory",
},
...chats.slice(startIdx),
];
console.log(
"[HypaV3] Exiting function:",
"\nCurrent Tokens:",
currentTokens,
"\nAll chats, including memory prompt:",
newChats,
"\nMemory Data:",
data
);
return {
currentTokens,
chats: newChats,
memory: toSerializableHypaV3Data(data),
};
}
const selectedSummaries: Summary[] = [];
const randomMemoryRatio =
1 -

View File

@@ -480,7 +480,8 @@ export function setDatabase(data:Database){
similarMemoryRatio: data.hypaV3Settings?.similarMemoryRatio ?? 0.4,
enableSimilarityCorrection: data.hypaV3Settings?.enableSimilarityCorrection ?? false,
preserveOrphanedMemory: data.hypaV3Settings?.preserveOrphanedMemory ?? false,
processRegexScript: data.hypaV3Settings?.processRegexScript ?? false
processRegexScript: data.hypaV3Settings?.processRegexScript ?? false,
doNotSummarizeUserChat: data.hypaV3Settings?.doNotSummarizeUserChat ?? false
}
changeLanguage(data.language)
setDatabaseLite(data)
@@ -894,6 +895,7 @@ export interface Database{
enableSimilarityCorrection: boolean
preserveOrphanedMemory: boolean
processRegexScript: boolean
doNotSummarizeUserChat: boolean
},
OaiCompAPIKeys: {[key:string]:string}
inlayErrorResponse:boolean