From fa48ace39badb237728188482550ae5bb8f0e47a Mon Sep 17 00:00:00 2001 From: skymkmk Date: Sat, 14 Sep 2024 07:49:26 +0800 Subject: [PATCH] fix: prevent users from setting a extremly short history that resulting in no content being sent for the title summary --- app/store/chat.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/store/chat.ts b/app/store/chat.ts index 1609666c331..d2a1fecd619 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -595,9 +595,13 @@ export const useChatStore = createPersistStore( countMessages(messages) >= SUMMARIZE_MIN_LEN) || refreshTitle ) { + const startIndex = Math.max( + 0, + messages.length - modelConfig.historyMessageCount, + ); const topicMessages = messages .slice( - messages.length - modelConfig.historyMessageCount, + startIndex < messages.length ? startIndex : messages.length - 1, messages.length, ) .concat(