Merge pull request #1475 from PaRaD1SE98/main

remove error messages in toBeSummarizedMsgs
This commit is contained in:
Yifei Zhang 2023-05-14 14:18:27 +08:00 committed by GitHub
commit 75488e4bd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 4 deletions

View File

@ -402,14 +402,17 @@ export const useChatStore = create<ChatStore>()(
summarizeSession() { summarizeSession() {
const session = get().currentSession(); 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 // should summarize topic after chating more than 50 words
const SUMMARIZE_MIN_LEN = 50; const SUMMARIZE_MIN_LEN = 50;
if ( if (
session.topic === DEFAULT_TOPIC && 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", model: "gpt-3.5-turbo",
}).then((res) => { }).then((res) => {
get().updateCurrentSession( get().updateCurrentSession(
@ -420,10 +423,10 @@ export const useChatStore = create<ChatStore>()(
} }
const modelConfig = session.mask.modelConfig; const modelConfig = session.mask.modelConfig;
let toBeSummarizedMsgs = session.messages.slice( let toBeSummarizedMsgs = cleanMessages.slice(
session.lastSummarizeIndex, session.lastSummarizeIndex,
); );
const historyMsgLength = countMessages(toBeSummarizedMsgs); const historyMsgLength = countMessages(toBeSummarizedMsgs);
if (historyMsgLength > modelConfig?.max_tokens ?? 4000) { if (historyMsgLength > modelConfig?.max_tokens ?? 4000) {