From a5679d458377f7af3b5dc302139876d3fa45d9a0 Mon Sep 17 00:00:00 2001 From: skymkmk Date: Fri, 13 Sep 2024 21:27:14 +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 | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/store/chat.ts b/app/store/chat.ts index 4332c2246adf..15ddac671148 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -569,12 +569,21 @@ export const useChatStore = createPersistStore( session.topic === DEFAULT_TOPIC && countMessages(messages) >= SUMMARIZE_MIN_LEN ) { - const topicMessages = messages.concat( - createMessage({ - role: "user", - content: Locale.Store.Prompt.Topic, - }), + const startIndex = Math.max( + 0, + messages.length - modelConfig.historyMessageCount, ); + const topicMessages = messages + .slice( + startIndex < messages.length ? startIndex : messages.length - 1, + messages.length, + ) + .concat( + createMessage({ + role: "user", + content: Locale.Store.Prompt.Topic, + }), + ); api.llm.chat({ messages: topicMessages, config: {