feat: add enable topic naming settings #399
This commit is contained in:
parent
7f2f3ad88a
commit
12d8f57dab
@ -36,7 +36,8 @@ const PopupContainer: React.FC<Props> = ({ title, resolve }) => {
|
||||
onOk={onOk}
|
||||
onCancel={onCancel}
|
||||
afterClose={onClose}
|
||||
transitionName="ant-move-down">
|
||||
transitionName="ant-move-down"
|
||||
centered>
|
||||
<Box mb={8}>Name</Box>
|
||||
</Modal>
|
||||
)
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -35,7 +35,7 @@ const Messages: FC<Props> = ({ assistant, topic, setActiveTopic }) => {
|
||||
const [messages, setMessages] = useState<Message[]>([])
|
||||
const containerRef = useRef<HTMLDivElement>(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<Props> = ({ 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<Props> = ({ assistant, topic, setActiveTopic }) => {
|
||||
updateTopic(data)
|
||||
}
|
||||
}
|
||||
}, [assistant, messages, setActiveTopic, topic.id, updateTopic])
|
||||
}, [assistant, enableTopicNaming, messages, setActiveTopic, topic.id, updateTopic])
|
||||
|
||||
const onDeleteMessage = useCallback(
|
||||
(message: Message) => {
|
||||
|
||||
@ -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,6 +103,7 @@ const ModelSettings: FC = () => {
|
||||
{t('settings.models.topic_naming_model')}
|
||||
</div>
|
||||
</SettingTitle>
|
||||
<HStack alignItems="center">
|
||||
<Select
|
||||
value={defaultTopicNamingModel}
|
||||
defaultValue={defaultTopicNamingModel}
|
||||
@ -110,6 +112,8 @@ const ModelSettings: FC = () => {
|
||||
options={selectOptions}
|
||||
placeholder={t('settings.models.empty')}
|
||||
/>
|
||||
<Button icon={<SettingOutlined />} style={{ marginLeft: 8 }} onClick={TopicNamingModalPopup.show} />
|
||||
</HStack>
|
||||
<SettingDescription>{t('settings.models.topic_naming_model_description')}</SettingDescription>
|
||||
</SettingGroup>
|
||||
<SettingGroup theme={theme}>
|
||||
@ -0,0 +1,79 @@
|
||||
import { HStack } from '@renderer/components/Layout'
|
||||
import { useSettings } from '@renderer/hooks/useSettings'
|
||||
import { useAppDispatch } from '@renderer/store'
|
||||
import { setEnableTopicNaming } from '@renderer/store/settings'
|
||||
import { Divider, Modal, Switch, Typography } from 'antd'
|
||||
import { useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import styled from 'styled-components'
|
||||
|
||||
import { TopView } from '../../../components/TopView'
|
||||
|
||||
interface Props {
|
||||
resolve: (data: any) => void
|
||||
}
|
||||
|
||||
const Title = styled(Typography.Title)`
|
||||
margin-bottom: 16px;
|
||||
`
|
||||
|
||||
const PopupContainer: React.FC<Props> = ({ resolve }) => {
|
||||
const [open, setOpen] = useState(true)
|
||||
const { t } = useTranslation()
|
||||
const { enableTopicNaming } = useSettings()
|
||||
const dispatch = useAppDispatch()
|
||||
|
||||
const onOk = () => {
|
||||
setOpen(false)
|
||||
}
|
||||
|
||||
const onCancel = () => {
|
||||
setOpen(false)
|
||||
}
|
||||
|
||||
const onClose = () => {
|
||||
resolve({})
|
||||
}
|
||||
|
||||
TopicNamingModalPopup.hide = onCancel
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={t('settings.models.topic_naming_model_setting_title')}
|
||||
open={open}
|
||||
onOk={onOk}
|
||||
onCancel={onCancel}
|
||||
afterClose={onClose}
|
||||
transitionName="ant-move-down"
|
||||
footer={null}
|
||||
centered>
|
||||
<Divider style={{ margin: '10px 0' }} />
|
||||
<HStack style={{ gap: 10, marginBottom: 20, marginTop: 20 }} alignItems="center">
|
||||
<div>{t('settings.models.enable_topic_naming')}</div>
|
||||
<Switch checked={enableTopicNaming} onChange={(v) => dispatch(setEnableTopicNaming(v))} />
|
||||
</HStack>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
|
||||
const TopViewKey = 'TopicNamingModalPopup'
|
||||
|
||||
export default class TopicNamingModalPopup {
|
||||
static topviewId = 0
|
||||
static hide() {
|
||||
TopView.hide(TopViewKey)
|
||||
}
|
||||
static show() {
|
||||
return new Promise<any>((resolve) => {
|
||||
TopView.show(
|
||||
<PopupContainer
|
||||
resolve={(v) => {
|
||||
resolve(v)
|
||||
TopView.hide(TopViewKey)
|
||||
}}
|
||||
/>,
|
||||
TopViewKey
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -9,7 +9,7 @@ import styled from 'styled-components'
|
||||
import AboutSettings from './AboutSettings'
|
||||
import DataSettings from './DataSettings/DataSettings'
|
||||
import GeneralSettings from './GeneralSettings'
|
||||
import ModelSettings from './ModelSettings'
|
||||
import ModelSettings from './ModalSettings/ModelSettings'
|
||||
import ProvidersList from './ProviderSettings'
|
||||
import ShortcutSettings from './ShortcutSettings'
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ const persistedReducer = persistReducer(
|
||||
{
|
||||
key: 'cherry-studio',
|
||||
storage,
|
||||
version: 44,
|
||||
version: 45,
|
||||
blacklist: ['runtime'],
|
||||
migrate
|
||||
},
|
||||
|
||||
@ -704,6 +704,10 @@ const migrateConfig = {
|
||||
'44': (state: RootState) => {
|
||||
state.settings.translateModelPrompt = TRANSLATE_PROMPT
|
||||
return state
|
||||
},
|
||||
'45': (state: RootState) => {
|
||||
state.settings.enableTopicNaming = true
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -37,6 +37,7 @@ export interface SettingsState {
|
||||
webdavPath: string
|
||||
translateModelPrompt: string
|
||||
autoTranslateWithSpace: boolean
|
||||
enableTopicNaming: boolean
|
||||
}
|
||||
|
||||
const initialState: SettingsState = {
|
||||
@ -70,7 +71,8 @@ const initialState: SettingsState = {
|
||||
webdavPass: '',
|
||||
webdavPath: '/cherry-studio',
|
||||
translateModelPrompt: TRANSLATE_PROMPT,
|
||||
autoTranslateWithSpace: false
|
||||
autoTranslateWithSpace: false,
|
||||
enableTopicNaming: true
|
||||
}
|
||||
|
||||
const settingsSlice = createSlice({
|
||||
@ -176,6 +178,9 @@ const settingsSlice = createSlice({
|
||||
},
|
||||
setAutoTranslateWithSpace: (state, action: PayloadAction<boolean>) => {
|
||||
state.autoTranslateWithSpace = action.payload
|
||||
},
|
||||
setEnableTopicNaming: (state, action: PayloadAction<boolean>) => {
|
||||
state.enableTopicNaming = action.payload
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -213,7 +218,8 @@ export const {
|
||||
setMessageStyle,
|
||||
setCodeStyle,
|
||||
setTranslateModelPrompt,
|
||||
setAutoTranslateWithSpace
|
||||
setAutoTranslateWithSpace,
|
||||
setEnableTopicNaming
|
||||
} = settingsSlice.actions
|
||||
|
||||
export default settingsSlice.reducer
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user