Skip to content

Commit

Permalink
feat: remove empty memoryPrompt in ChatMessages
Browse files Browse the repository at this point in the history
  • Loading branch information
Dean-YZG authored and Dean-YZG committed May 16, 2024
1 parent 48d44ec commit 0aa807d
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions app/store/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,14 +428,13 @@ export const useChatStore = createPersistStore(
getMemoryPrompt() {
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() {
Expand Down Expand Up @@ -471,16 +470,15 @@ export const useChatStore = createPersistStore(
systemPrompts.at(0)?.content ?? "empty",
);
}

const memoryPrompt = get().getMemoryPrompt();
// long term memory
const shouldSendLongTermMemory =
modelConfig.sendMemory &&
session.memoryPrompt &&
session.memoryPrompt.length > 0 &&
session.lastSummarizeIndex > clearContextIndex;
const longTermMemoryPrompts = shouldSendLongTermMemory
? [get().getMemoryPrompt()]
: [];
const longTermMemoryPrompts =
shouldSendLongTermMemory && memoryPrompt ? [memoryPrompt] : [];
const longTermMemoryStartIndex = session.lastSummarizeIndex;

// short term memory
Expand Down Expand Up @@ -605,9 +603,11 @@ export const useChatStore = createPersistStore(
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;

Expand Down

0 comments on commit 0aa807d

Please sign in to comment.