From a9f000e7ef7f0713d474f4e8a8801ce4ee7bc19f Mon Sep 17 00:00:00 2001 From: PaRaD1SE98 Date: Sun, 14 May 2023 01:24:20 +0900 Subject: [PATCH 1/2] remove error messages in toBeSummarizedMsgs --- app/store/chat.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/store/chat.ts b/app/store/chat.ts index cb11087d..b8cdecb6 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -423,7 +423,10 @@ export const useChatStore = create()( let toBeSummarizedMsgs = session.messages.slice( session.lastSummarizeIndex, ); - + + // remove error messages if any + toBeSummarizedMsgs = toBeSummarizedMsgs.filter((msg) => !msg.isError); + const historyMsgLength = countMessages(toBeSummarizedMsgs); if (historyMsgLength > modelConfig?.max_tokens ?? 4000) { From ff2589c97f00abe30d389cc5e71a6b63c561a6c1 Mon Sep 17 00:00:00 2001 From: PaRaD1SE98 Date: Sun, 14 May 2023 02:34:32 +0900 Subject: [PATCH 2/2] remove error messages for chat title summary --- app/store/chat.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/store/chat.ts b/app/store/chat.ts index b8cdecb6..d9a4af78 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -402,14 +402,17 @@ export const useChatStore = create()( 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()( } 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);