|
@@ -428,14 +428,13 @@ export const useChatStore = createPersistStore(
|
|
|
getMemoryPrompt() {
|
|
getMemoryPrompt() {
|
|
|
const session = get().currentSession();
|
|
const session = get().currentSession();
|
|
|
|
|
|
|
|
- return {
|
|
|
|
|
- role: "system",
|
|
|
|
|
- content:
|
|
|
|
|
- session.memoryPrompt.length > 0
|
|
|
|
|
- ? Locale.Store.Prompt.History(session.memoryPrompt)
|
|
|
|
|
- : "",
|
|
|
|
|
- date: "",
|
|
|
|
|
- } as ChatMessage;
|
|
|
|
|
|
|
+ if (session.memoryPrompt.length) {
|
|
|
|
|
+ return {
|
|
|
|
|
+ role: "system",
|
|
|
|
|
+ content: Locale.Store.Prompt.History(session.memoryPrompt),
|
|
|
|
|
+ date: "",
|
|
|
|
|
+ } as ChatMessage;
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
getMessagesWithMemory() {
|
|
getMessagesWithMemory() {
|
|
@@ -471,16 +470,15 @@ export const useChatStore = createPersistStore(
|
|
|
systemPrompts.at(0)?.content ?? "empty",
|
|
systemPrompts.at(0)?.content ?? "empty",
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ const memoryPrompt = get().getMemoryPrompt();
|
|
|
// long term memory
|
|
// long term memory
|
|
|
const shouldSendLongTermMemory =
|
|
const shouldSendLongTermMemory =
|
|
|
modelConfig.sendMemory &&
|
|
modelConfig.sendMemory &&
|
|
|
session.memoryPrompt &&
|
|
session.memoryPrompt &&
|
|
|
session.memoryPrompt.length > 0 &&
|
|
session.memoryPrompt.length > 0 &&
|
|
|
session.lastSummarizeIndex > clearContextIndex;
|
|
session.lastSummarizeIndex > clearContextIndex;
|
|
|
- const longTermMemoryPrompts = shouldSendLongTermMemory
|
|
|
|
|
- ? [get().getMemoryPrompt()]
|
|
|
|
|
- : [];
|
|
|
|
|
|
|
+ const longTermMemoryPrompts =
|
|
|
|
|
+ shouldSendLongTermMemory && memoryPrompt ? [memoryPrompt] : [];
|
|
|
const longTermMemoryStartIndex = session.lastSummarizeIndex;
|
|
const longTermMemoryStartIndex = session.lastSummarizeIndex;
|
|
|
|
|
|
|
|
// short term memory
|
|
// short term memory
|
|
@@ -605,9 +603,11 @@ export const useChatStore = createPersistStore(
|
|
|
Math.max(0, n - modelConfig.historyMessageCount),
|
|
Math.max(0, n - modelConfig.historyMessageCount),
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // add memory prompt
|
|
|
|
|
- toBeSummarizedMsgs.unshift(get().getMemoryPrompt());
|
|
|
|
|
|
|
+ const memoryPrompt = get().getMemoryPrompt();
|
|
|
|
|
+ if (memoryPrompt) {
|
|
|
|
|
+ // add memory prompt
|
|
|
|
|
+ toBeSummarizedMsgs.unshift(memoryPrompt);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
const lastSummarizeIndex = session.messages.length;
|
|
const lastSummarizeIndex = session.messages.length;
|
|
|
|
|
|