Enable to set historyMessageCount for each chat

This commit is contained in:
Reekin
2024-03-17 17:34:09 +08:00
parent cc0eae7153
commit c66c50908c
2 changed files with 43 additions and 4 deletions

View File

@@ -57,6 +57,8 @@ export interface ChatSession {
clearContextIndex?: number;
mask: Mask;
overrideModelConfig?: Partial<ModelConfig>;
}
export const DEFAULT_TOPIC = Locale.Store.DefaultTopic;
@@ -466,7 +468,9 @@ export const useChatStore = createPersistStore(
// short term memory
const shortTermMemoryStartIndex = Math.max(
0,
totalMessageCount - modelConfig.historyMessageCount,
totalMessageCount -
(session.overrideModelConfig?.historyMessageCount ??
modelConfig.historyMessageCount),
);
// lets concat send messages, including 4 parts:
@@ -580,7 +584,12 @@ export const useChatStore = createPersistStore(
if (historyMsgLength > modelConfig?.max_tokens ?? 4000) {
const n = toBeSummarizedMsgs.length;
toBeSummarizedMsgs = toBeSummarizedMsgs.slice(
Math.max(0, n - modelConfig.historyMessageCount),
Math.max(
0,
n -
(session.overrideModelConfig?.historyMessageCount ??
modelConfig.historyMessageCount),
),
);
}