diff --git a/app/store/chat.ts b/app/store/chat.ts index 5bb94d1c718..90dcbd6b76f 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -574,9 +574,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(