From 4c5a345e6597067fbb015dbbce0f008ebee07f69 Mon Sep 17 00:00:00 2001 From: arvinxx Date: Thu, 4 Jan 2024 14:00:28 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20support=20auto=20rename=20t?= =?UTF-8?q?opic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TopicListContent/Topic/TopicContent.tsx | 24 +++++++++++++------ src/locales/default/chat.ts | 3 +++ src/store/chat/slices/topic/action.ts | 8 +++++++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/app/chat/features/TopicListContent/Topic/TopicContent.tsx b/src/app/chat/features/TopicListContent/Topic/TopicContent.tsx index dcf95a9df439..778977385459 100644 --- a/src/app/chat/features/TopicListContent/Topic/TopicContent.tsx +++ b/src/app/chat/features/TopicListContent/Topic/TopicContent.tsx @@ -1,7 +1,7 @@ import { ActionIcon, EditableText, Icon } from '@lobehub/ui'; import { App, Dropdown, type MenuProps, Typography } from 'antd'; import { createStyles } from 'antd-style'; -import { MoreVertical, PencilLine, Star, Trash } from 'lucide-react'; +import { MoreVertical, PencilLine, Star, Trash, Wand2 } from 'lucide-react'; import { memo, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { Flexbox } from 'react-layout-kit'; @@ -33,12 +33,14 @@ interface TopicContentProps { const TopicContent = memo(({ id, title, fav, showMore }) => { const { t } = useTranslation('common'); - const [editing, favoriteTopic, updateTopicTitle, removeTopic] = useChatStore((s) => [ - s.topicRenamingId === id, - s.favoriteTopic, - s.updateTopicTitle, - s.removeTopic, - ]); + const [editing, favoriteTopic, updateTopicTitle, removeTopic, autoRenameTopicTitle] = + useChatStore((s) => [ + s.topicRenamingId === id, + s.favoriteTopic, + s.updateTopicTitle, + s.removeTopic, + s.autoRenameTopicTitle, + ]); const { styles, theme } = useStyles(); const toggleEditing = (visible?: boolean) => { @@ -57,6 +59,14 @@ const TopicContent = memo(({ id, title, fav, showMore }) => { toggleEditing(true); }, }, + { + icon: , + key: 'autoRename', + label: t('topic.actions.autoRename', { ns: 'chat' }), + onClick: () => { + autoRenameTopicTitle(id); + }, + }, // { // icon: , // key: 'share', diff --git a/src/locales/default/chat.ts b/src/locales/default/chat.ts index 8e9d8111c94b..a4ffb1672ee9 100644 --- a/src/locales/default/chat.ts +++ b/src/locales/default/chat.ts @@ -56,6 +56,9 @@ export default { used: '使用', }, topic: { + actions: { + autoRename: '智能重命名', + }, confirmRemoveAll: '即将删除全部话题,删除后将不可恢复,请谨慎操作。', confirmRemoveTopic: '即将删除该话题,删除后将不可恢复,请谨慎操作。', confirmRemoveUnstarred: '即将删除未收藏话题,删除后将不可恢复,请谨慎操作。', diff --git a/src/store/chat/slices/topic/action.ts b/src/store/chat/slices/topic/action.ts index f3fe43f0da29..fafa70a6d3bf 100644 --- a/src/store/chat/slices/topic/action.ts +++ b/src/store/chat/slices/topic/action.ts @@ -30,6 +30,7 @@ export interface ChatTopicAction { removeTopic: (id: string) => Promise; removeUnstarredTopic: () => void; saveToTopic: () => Promise; + autoRenameTopicTitle: (id: string) => Promise; summaryTopicTitle: (topicId: string, messages: ChatMessage[]) => Promise; switchTopic: (id?: string) => Promise; updateTopicTitleInSummary: (id: string, title: string) => void; @@ -115,6 +116,13 @@ export const chatTopic: StateCreator< await topicService.updateTitle(id, title); await get().refreshTopic(); }, + + autoRenameTopicTitle: async (id) => { + const { activeId: sessionId, summaryTopicTitle } = get(); + const messages = await messageService.getMessages(sessionId, id); + console.log(messages); + await summaryTopicTitle(id, messages); + }, // query useFetchTopics: (sessionId) => useSWR(sessionId, async (sessionId) => topicService.getTopics({ sessionId }), {