From 12d8f57dabfcf16983f10b9336c87af1cae5bec7 Mon Sep 17 00:00:00 2001 From: kangfenmao Date: Tue, 3 Dec 2024 10:47:43 +0800 Subject: [PATCH] feat: add enable topic naming settings #399 --- .../src/components/Popups/TemplatePopup.tsx | 3 +- src/renderer/src/i18n/locales/en-us.json | 2 + src/renderer/src/i18n/locales/ru-ru.json | 2 + src/renderer/src/i18n/locales/zh-cn.json | 2 + src/renderer/src/i18n/locales/zh-tw.json | 2 + .../src/pages/home/Messages/Messages.tsx | 9 ++- .../{ => ModalSettings}/ModelSettings.tsx | 24 +++--- .../ModalSettings/TopicNamingModalPopup.tsx | 79 +++++++++++++++++++ .../src/pages/settings/SettingsPage.tsx | 2 +- src/renderer/src/store/index.ts | 2 +- src/renderer/src/store/migrate.ts | 4 + src/renderer/src/store/settings.ts | 10 ++- 12 files changed, 124 insertions(+), 17 deletions(-) rename src/renderer/src/pages/settings/{ => ModalSettings}/ModelSettings.tsx (88%) create mode 100644 src/renderer/src/pages/settings/ModalSettings/TopicNamingModalPopup.tsx diff --git a/src/renderer/src/components/Popups/TemplatePopup.tsx b/src/renderer/src/components/Popups/TemplatePopup.tsx index c25827b6..786d01a5 100644 --- a/src/renderer/src/components/Popups/TemplatePopup.tsx +++ b/src/renderer/src/components/Popups/TemplatePopup.tsx @@ -36,7 +36,8 @@ const PopupContainer: React.FC = ({ title, resolve }) => { onOk={onOk} onCancel={onCancel} afterClose={onClose} - transitionName="ant-move-down"> + transitionName="ant-move-down" + centered> Name ) diff --git a/src/renderer/src/i18n/locales/en-us.json b/src/renderer/src/i18n/locales/en-us.json index d37f7313..ab7dc1c4 100644 --- a/src/renderer/src/i18n/locales/en-us.json +++ b/src/renderer/src/i18n/locales/en-us.json @@ -397,6 +397,8 @@ "models.translate_model_description": "Model used for translation service", "models.translate_model_prompt_message": "Please enter the translate model prompt", "models.translate_model_prompt_title": "Translate Model Prompt", + "models.topic_naming_model_setting_title": "Topic Naming Model Settings", + "models.enable_topic_naming": "Topic Auto Naming", "provider": { "add.name": "Provider Name", "add.name.placeholder": "Example: OpenAI", diff --git a/src/renderer/src/i18n/locales/ru-ru.json b/src/renderer/src/i18n/locales/ru-ru.json index a371beb0..c812169f 100644 --- a/src/renderer/src/i18n/locales/ru-ru.json +++ b/src/renderer/src/i18n/locales/ru-ru.json @@ -397,6 +397,8 @@ "models.translate_model_description": "Модель, используемая для сервиса перевода", "models.translate_model_prompt_message": "Введите модель перевода", "models.translate_model_prompt_title": "Модель перевода", + "models.topic_naming_model_setting_title": "Настройки модели именования топика", + "models.enable_topic_naming": "Автоматическое переименование топика", "provider": { "add.name": "Имя провайдера", "add.name.placeholder": "Пример: OpenAI", diff --git a/src/renderer/src/i18n/locales/zh-cn.json b/src/renderer/src/i18n/locales/zh-cn.json index e6108f63..5a1b7020 100644 --- a/src/renderer/src/i18n/locales/zh-cn.json +++ b/src/renderer/src/i18n/locales/zh-cn.json @@ -397,6 +397,8 @@ "models.translate_model_description": "翻译服务使用的模型", "models.translate_model_prompt_message": "请输入翻译模型提示词", "models.translate_model_prompt_title": "翻译模型提示词", + "models.topic_naming_model_setting_title": "话题命名模型设置", + "models.enable_topic_naming": "话题自动重命名", "provider": { "add.name": "提供商名称", "add.name.placeholder": "例如 OpenAI", diff --git a/src/renderer/src/i18n/locales/zh-tw.json b/src/renderer/src/i18n/locales/zh-tw.json index ea8518ac..02ee268f 100644 --- a/src/renderer/src/i18n/locales/zh-tw.json +++ b/src/renderer/src/i18n/locales/zh-tw.json @@ -397,6 +397,8 @@ "models.translate_model_description": "翻譯服務使用的模型", "models.translate_model_prompt_message": "請輸入翻譯模型提示詞", "models.translate_model_prompt_title": "翻譯模型提示詞", + "models.topic_naming_model_setting_title": "話題命名模型設定", + "models.enable_topic_naming": "話題自動重命名", "provider": { "add.name": "提供者名稱", "add.name.placeholder": "例如:OpenAI", diff --git a/src/renderer/src/pages/home/Messages/Messages.tsx b/src/renderer/src/pages/home/Messages/Messages.tsx index fefdbe06..577749e3 100644 --- a/src/renderer/src/pages/home/Messages/Messages.tsx +++ b/src/renderer/src/pages/home/Messages/Messages.tsx @@ -35,7 +35,7 @@ const Messages: FC = ({ assistant, topic, setActiveTopic }) => { const [messages, setMessages] = useState([]) const containerRef = useRef(null) const { updateTopic, addTopic } = useAssistant(assistant.id) - const { showTopics, topicPosition, showAssistants } = useSettings() + const { showTopics, topicPosition, showAssistants, enableTopicNaming } = useSettings() const messagesRef = useRef(messages) messagesRef.current = messages @@ -67,7 +67,12 @@ const Messages: FC = ({ assistant, topic, setActiveTopic }) => { ) const autoRenameTopic = useCallback(async () => { + if (!enableTopicNaming) { + return + } + const _topic = getTopic(assistant, topic.id) + if (_topic && _topic.name === t('chat.default.topic.name') && messages.length >= 2) { const summaryText = await fetchMessagesSummary({ messages, assistant }) if (summaryText) { @@ -76,7 +81,7 @@ const Messages: FC = ({ assistant, topic, setActiveTopic }) => { updateTopic(data) } } - }, [assistant, messages, setActiveTopic, topic.id, updateTopic]) + }, [assistant, enableTopicNaming, messages, setActiveTopic, topic.id, updateTopic]) const onDeleteMessage = useCallback( (message: Message) => { diff --git a/src/renderer/src/pages/settings/ModelSettings.tsx b/src/renderer/src/pages/settings/ModalSettings/ModelSettings.tsx similarity index 88% rename from src/renderer/src/pages/settings/ModelSettings.tsx rename to src/renderer/src/pages/settings/ModalSettings/ModelSettings.tsx index c6631051..88268870 100644 --- a/src/renderer/src/pages/settings/ModelSettings.tsx +++ b/src/renderer/src/pages/settings/ModalSettings/ModelSettings.tsx @@ -15,8 +15,9 @@ import { find, sortBy } from 'lodash' import { FC, useMemo } from 'react' import { useTranslation } from 'react-i18next' -import { SettingContainer, SettingDescription, SettingGroup, SettingTitle } from '.' -import AssistantSettingsPopup from './AssistantSettings' +import { SettingContainer, SettingDescription, SettingGroup, SettingTitle } from '..' +import AssistantSettingsPopup from '../AssistantSettings' +import TopicNamingModalPopup from './TopicNamingModalPopup' const ModelSettings: FC = () => { const { defaultModel, topicNamingModel, translateModel, setDefaultModel, setTopicNamingModel, setTranslateModel } = @@ -102,14 +103,17 @@ const ModelSettings: FC = () => { {t('settings.models.topic_naming_model')} - setTopicNamingModel(find(allModels, JSON.parse(value)) as Model)} + options={selectOptions} + placeholder={t('settings.models.empty')} + /> +