@ -424,6 +424,9 @@ export const useChatStore = create<ChatStore>()(
session.lastSummarizeIndex,
);
// remove error messages if any
toBeSummarizedMsgs = toBeSummarizedMsgs.filter((msg) => !msg.isError);
const historyMsgLength = countMessages(toBeSummarizedMsgs);
if (historyMsgLength > modelConfig?.max_tokens ?? 4000) {