Skip to content

Commit

Permalink
✨ feat: support auto rename topic
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Jan 4, 2024
1 parent acae827 commit 4c5a345
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/app/chat/features/TopicListContent/Topic/TopicContent.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -33,12 +33,14 @@ interface TopicContentProps {
const TopicContent = memo<TopicContentProps>(({ 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) => {
Expand All @@ -57,6 +59,14 @@ const TopicContent = memo<TopicContentProps>(({ id, title, fav, showMore }) => {
toggleEditing(true);
},
},
{
icon: <Icon icon={Wand2} />,
key: 'autoRename',
label: t('topic.actions.autoRename', { ns: 'chat' }),
onClick: () => {
autoRenameTopicTitle(id);
},
},
// {
// icon: <Icon icon={Share2} />,
// key: 'share',
Expand Down
3 changes: 3 additions & 0 deletions src/locales/default/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ export default {
used: '使用',
},
topic: {
actions: {
autoRename: '智能重命名',
},
confirmRemoveAll: '即将删除全部话题,删除后将不可恢复,请谨慎操作。',
confirmRemoveTopic: '即将删除该话题,删除后将不可恢复,请谨慎操作。',
confirmRemoveUnstarred: '即将删除未收藏话题,删除后将不可恢复,请谨慎操作。',
Expand Down
8 changes: 8 additions & 0 deletions src/store/chat/slices/topic/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface ChatTopicAction {
removeTopic: (id: string) => Promise<void>;
removeUnstarredTopic: () => void;
saveToTopic: () => Promise<string | undefined>;
autoRenameTopicTitle: (id: string) => Promise<void>;
summaryTopicTitle: (topicId: string, messages: ChatMessage[]) => Promise<void>;
switchTopic: (id?: string) => Promise<void>;
updateTopicTitleInSummary: (id: string, title: string) => void;
Expand Down Expand Up @@ -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);
},

Check warning on line 125 in src/store/chat/slices/topic/action.ts

View check run for this annotation

Codecov / codecov/patch

src/store/chat/slices/topic/action.ts#L121-L125

Added lines #L121 - L125 were not covered by tests
// query
useFetchTopics: (sessionId) =>
useSWR<ChatTopic[]>(sessionId, async (sessionId) => topicService.getTopics({ sessionId }), {
Expand Down

0 comments on commit 4c5a345

Please sign in to comment.