Skip to content

Commit

Permalink
fix: prevent users from setting a extremly short history that resulti…
Browse files Browse the repository at this point in the history
…ng in no content being sent for the title summary
  • Loading branch information
skymkmk committed Sep 13, 2024
1 parent 1b869d9 commit a5679d4
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions app/store/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit a5679d4

Please sign in to comment.