diff --git a/src/renderer/src/hooks/useTopic.ts b/src/renderer/src/hooks/useTopic.ts index 0c41a8019d..7cc7eb26f3 100644 --- a/src/renderer/src/hooks/useTopic.ts +++ b/src/renderer/src/hooks/useTopic.ts @@ -17,8 +17,10 @@ export function useActiveTopic(_assistant: Assistant, topic?: Topic) { useEffect(() => { // activeTopic not in assistant.topics - if (assistant && !find(assistant.topics, { id: activeTopic?.id })) { - setActiveTopic(assistant.topics[0]) + const topicTarget = find(assistant.topics, { id: activeTopic?.id }) + // if (assistant && !find(assistant.topics, { id: activeTopic?.id })) { + if (assistant) { + setActiveTopic(topicTarget || assistant.topics[0]) } }, [activeTopic?.id, assistant]) diff --git a/src/renderer/src/i18n/locales/en-us.json b/src/renderer/src/i18n/locales/en-us.json index c501f0cd4e..bf3401ab7e 100644 --- a/src/renderer/src/i18n/locales/en-us.json +++ b/src/renderer/src/i18n/locales/en-us.json @@ -136,7 +136,10 @@ "topics.pinned": "Pinned Topics", "topics.title": "Topics", "topics.unpinned": "Unpinned Topics", - "translate": "Translate" + "translate": "Translate", + "topics.prompt": "Topic Prompts", + "topics.prompt.tips": "Topic Prompts: Additional supplementary prompts provided for the current topic", + "topics.prompt.edit.title": "Edit Topic Prompts" }, "common": { "add": "Add", diff --git a/src/renderer/src/i18n/locales/ja-jp.json b/src/renderer/src/i18n/locales/ja-jp.json index cdb84b2ef6..b71ecc1165 100644 --- a/src/renderer/src/i18n/locales/ja-jp.json +++ b/src/renderer/src/i18n/locales/ja-jp.json @@ -136,7 +136,10 @@ "topics.pinned": "トピックを固定", "topics.title": "トピック", "topics.unpinned": "固定解除", - "translate": "翻訳" + "translate": "翻訳", + "topics.prompt": "トピック提示語", + "topics.prompt.tips": "トピック提示語:現在のトピックに対して追加の補足提示語を提供", + "topics.prompt.edit.title": "トピック提示語を編集する" }, "common": { "add": "追加", diff --git a/src/renderer/src/i18n/locales/ru-ru.json b/src/renderer/src/i18n/locales/ru-ru.json index e69f480292..738f3ec4e6 100644 --- a/src/renderer/src/i18n/locales/ru-ru.json +++ b/src/renderer/src/i18n/locales/ru-ru.json @@ -136,7 +136,10 @@ "topics.pinned": "Закрепленные темы", "topics.title": "Топики", "topics.unpinned": "Открепленные темы", - "translate": "Перевести" + "translate": "Перевести", + "topics.prompt": "Тематические подсказки", + "topics.prompt.tips": "Тематические подсказки: Дополнительные подсказки, предоставленные для текущей темы", + "topics.prompt.edit.title": "Редактировать подсказки темы" }, "common": { "add": "Добавить", diff --git a/src/renderer/src/i18n/locales/zh-cn.json b/src/renderer/src/i18n/locales/zh-cn.json index 24123d0aa0..262b0c9db5 100644 --- a/src/renderer/src/i18n/locales/zh-cn.json +++ b/src/renderer/src/i18n/locales/zh-cn.json @@ -136,7 +136,10 @@ "topics.pinned": "固定话题", "topics.title": "话题", "topics.unpinned": "取消固定", - "translate": "翻译" + "translate": "翻译", + "topics.prompt": "话题提示词", + "topics.prompt.tips": "话题提示词: 针对当前话题提供额外的补充提示词", + "topics.prompt.edit.title": "编辑话题提示词" }, "common": { "add": "添加", diff --git a/src/renderer/src/i18n/locales/zh-tw.json b/src/renderer/src/i18n/locales/zh-tw.json index 4291d19502..20f9dd6419 100644 --- a/src/renderer/src/i18n/locales/zh-tw.json +++ b/src/renderer/src/i18n/locales/zh-tw.json @@ -136,7 +136,10 @@ "topics.pinned": "固定話題", "topics.title": "話題", "topics.unpinned": "取消固定", - "translate": "翻譯" + "translate": "翻譯", + "topics.prompt": "話題提示詞", + "topics.prompt.tips": "話題提示詞:針對目前話題提供額外的補充提示詞", + "topics.prompt.edit.title": "編輯話題提示詞" }, "common": { "add": "添加", diff --git a/src/renderer/src/pages/home/Messages/Message.tsx b/src/renderer/src/pages/home/Messages/Message.tsx index 14d9758cb8..3fcabb2f3d 100644 --- a/src/renderer/src/pages/home/Messages/Message.tsx +++ b/src/renderer/src/pages/home/Messages/Message.tsx @@ -118,8 +118,12 @@ const MessageItem: FC = ({ useEffect(() => { if (topic && onGetMessages && onSetMessages) { if (message.status === 'sending') { + const _assistant = { + ...assistant, + prompt: `${assistant?.prompt || ''}\n${topic?.prompt || ''}` + } const messages = onGetMessages() - const assistantWithModel = message.model ? { ...assistant, model: message.model } : assistant + const assistantWithModel = message.model ? { ..._assistant, model: message.model } : _assistant fetchChatCompletion({ message, diff --git a/src/renderer/src/pages/home/Messages/Messages.tsx b/src/renderer/src/pages/home/Messages/Messages.tsx index 22bf8ad272..7d91b1a5ad 100644 --- a/src/renderer/src/pages/home/Messages/Messages.tsx +++ b/src/renderer/src/pages/home/Messages/Messages.tsx @@ -315,7 +315,7 @@ const Messages: FC = ({ assistant, topic, setActiveTopic }) => { ))} - + ) @@ -349,8 +349,7 @@ interface ContainerProps { const Container = styled(Scrollbar)` display: flex; flex-direction: column-reverse; - padding: 10px 0; - padding-bottom: 20px; + padding: 10px 0 20px; overflow-x: hidden; background-color: var(--color-background); ` diff --git a/src/renderer/src/pages/home/Messages/Prompt.tsx b/src/renderer/src/pages/home/Messages/Prompt.tsx index 6af3ab7e97..5d0c2c6f02 100644 --- a/src/renderer/src/pages/home/Messages/Prompt.tsx +++ b/src/renderer/src/pages/home/Messages/Prompt.tsx @@ -1,22 +1,22 @@ import AssistantSettingsPopup from '@renderer/pages/settings/AssistantSettings' -import { Assistant } from '@renderer/types' +import { Assistant, Topic } from '@renderer/types' import { FC } from 'react' import { useTranslation } from 'react-i18next' import styled from 'styled-components' interface Props { assistant: Assistant + topic?: Topic } -const Prompt: FC = ({ assistant }) => { +const Prompt: FC = ({ assistant, topic }) => { const { t } = useTranslation() const prompt = assistant.prompt || t('chat.default.description') - - if (!prompt) { + const topicPrompt = topic?.prompt || '' + if (!prompt && !topicPrompt) { return null } - return ( AssistantSettingsPopup.show({ assistant })}> {prompt} diff --git a/src/renderer/src/pages/home/Tabs/TopicsTab.tsx b/src/renderer/src/pages/home/Tabs/TopicsTab.tsx index fdbdda9960..4a662ff850 100644 --- a/src/renderer/src/pages/home/Tabs/TopicsTab.tsx +++ b/src/renderer/src/pages/home/Tabs/TopicsTab.tsx @@ -5,6 +5,7 @@ import { EditOutlined, FolderOutlined, PushpinOutlined, + QuestionCircleOutlined, UploadOutlined } from '@ant-design/icons' import DragableList from '@renderer/components/DragableList' @@ -20,7 +21,7 @@ import store from '@renderer/store' import { setGenerating } from '@renderer/store/runtime' import { Assistant, Topic } from '@renderer/types' import { exportTopicAsMarkdown, exportTopicToNotion, topicToMarkdown } from '@renderer/utils/export' -import { Dropdown, MenuProps } from 'antd' +import { Dropdown, MenuProps, Tooltip } from 'antd' import dayjs from 'dayjs' import { findIndex } from 'lodash' import { FC, useCallback } from 'react' @@ -115,6 +116,28 @@ const Topics: FC = ({ assistant: _assistant, activeTopic, setActiveTopic } } }, + { + label: t('chat.topics.prompt'), + key: 'topic-prompt', + icon: , + extra: ( + + + + ), + async onClick() { + const prompt = await PromptPopup.show({ + title: t('chat.topics.prompt.edit.title'), + message: '', + defaultValue: topic?.prompt || '', + inputProps: { + rows: 8, + allowClear: true + } + }) + if (prompt !== null) updateTopic({ ...topic, prompt }) + } + }, { label: topic.pinned ? t('chat.topics.unpinned') : t('chat.topics.pinned'), key: 'pin', @@ -211,6 +234,11 @@ const Topics: FC = ({ assistant: _assistant, activeTopic, setActiveTopic onClick={() => onSwitchTopic(topic)} style={{ borderRadius }}> {topic.name.replace('`', '')} + {topic.prompt && ( + + {t('common.prompt')}: {topic.prompt} + + )} {showTopicTime && ( {dayjs(topic.createdAt).format('MM/DD HH:mm')} )} @@ -291,6 +319,18 @@ const TopicName = styled.div` font-size: 13px; ` +const TopicPromptText = styled.div` + color: var(--color-text-2); + font-size: 12px; + display: -webkit-box; + -webkit-line-clamp: 2; + -webkit-box-orient: vertical; + overflow: hidden; + ~ .prompt-text { + margin-top: 10px; + } +` + const TopicTime = styled.div` color: var(--color-text-3); font-size: 11px; @@ -310,5 +350,10 @@ const MenuButton = styled.div` font-size: 12px; } ` +const QuestionIcon = styled(QuestionCircleOutlined)` + font-size: 14px; + cursor: pointer; + color: var(--color-text-3); +` export default Topics diff --git a/src/renderer/src/types/index.ts b/src/renderer/src/types/index.ts index ba801eeef8..b77f5b55ac 100644 --- a/src/renderer/src/types/index.ts +++ b/src/renderer/src/types/index.ts @@ -89,6 +89,7 @@ export type Topic = { updatedAt: string messages: Message[] pinned?: boolean + prompt?: string } export type User = {