Skip to content

Commit

Permalink
feat: manual refresh for title
Browse files Browse the repository at this point in the history
  • Loading branch information
skymkmk committed Sep 13, 2024
1 parent df62736 commit fc27441
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
12 changes: 12 additions & 0 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import QualityIcon from "../icons/hd.svg";
import StyleIcon from "../icons/palette.svg";
import PluginIcon from "../icons/plugin.svg";
import ShortcutkeyIcon from "../icons/shortcutkey.svg";
import ReloadIcon from "../icons/reload.svg";

import {
ChatMessage,
Expand Down Expand Up @@ -1541,6 +1542,17 @@ function _Chat() {
</div>
</div>
<div className="window-actions">
<div className="window-action-button">
<IconButton
icon={<ReloadIcon />}
bordered
title={Locale.Chat.Actions.RefreshTitle}
onClick={() => {
showToast(Locale.Chat.Actions.RefreshToast);
chatStore.summarizeSession(true);
}}
/>
</div>
{!isMobileScreen && (
<div className="window-action-button">
<IconButton
Expand Down
26 changes: 16 additions & 10 deletions app/store/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ export const useChatStore = createPersistStore(
});
},

summarizeSession() {
summarizeSession(refreshTitle: boolean = false) {
const config = useAppConfig.getState();
const session = get().currentSession();
const modelConfig = session.mask.modelConfig;
Expand All @@ -590,16 +590,22 @@ export const useChatStore = createPersistStore(
// should summarize topic after chating more than 50 words
const SUMMARIZE_MIN_LEN = 50;
if (
config.enableAutoGenerateTitle &&
session.topic === DEFAULT_TOPIC &&
countMessages(messages) >= SUMMARIZE_MIN_LEN
(config.enableAutoGenerateTitle &&
session.topic === DEFAULT_TOPIC &&
countMessages(messages) >= SUMMARIZE_MIN_LEN) ||
refreshTitle
) {
const topicMessages = messages.concat(
createMessage({
role: "user",
content: Locale.Store.Prompt.Topic,
}),
);
const topicMessages = messages
.slice(
messages.length - modelConfig.historyMessageCount,
messages.length,
)
.concat(
createMessage({
role: "user",
content: Locale.Store.Prompt.Topic,
}),
);
api.llm.chat({
messages: topicMessages,
config: {
Expand Down

0 comments on commit fc27441

Please sign in to comment.