|
@@ -402,14 +402,17 @@ export const useChatStore = create<ChatStore>()(
|
|
|
|
|
|
summarizeSession() {
|
|
|
const session = get().currentSession();
|
|
|
+
|
|
|
+ // remove error messages if any
|
|
|
+ const cleanMessages = session.messages.filter((msg) => !msg.isError);
|
|
|
|
|
|
// should summarize topic after chating more than 50 words
|
|
|
const SUMMARIZE_MIN_LEN = 50;
|
|
|
if (
|
|
|
session.topic === DEFAULT_TOPIC &&
|
|
|
- countMessages(session.messages) >= SUMMARIZE_MIN_LEN
|
|
|
+ countMessages(cleanMessages) >= SUMMARIZE_MIN_LEN
|
|
|
) {
|
|
|
- requestWithPrompt(session.messages, Locale.Store.Prompt.Topic, {
|
|
|
+ requestWithPrompt(cleanMessages, Locale.Store.Prompt.Topic, {
|
|
|
model: "gpt-3.5-turbo",
|
|
|
}).then((res) => {
|
|
|
get().updateCurrentSession(
|
|
@@ -420,12 +423,9 @@ export const useChatStore = create<ChatStore>()(
|
|
|
}
|
|
|
|
|
|
const modelConfig = session.mask.modelConfig;
|
|
|
- let toBeSummarizedMsgs = session.messages.slice(
|
|
|
+ let toBeSummarizedMsgs = cleanMessages.slice(
|
|
|
session.lastSummarizeIndex,
|
|
|
);
|
|
|
-
|
|
|
- // remove error messages if any
|
|
|
- toBeSummarizedMsgs = toBeSummarizedMsgs.filter((msg) => !msg.isError);
|
|
|
|
|
|
const historyMsgLength = countMessages(toBeSummarizedMsgs);
|
|
|
|