From 32da853f2734eec0b2b52529d79c015f100c8660 Mon Sep 17 00:00:00 2001 From: ousugo Date: Wed, 19 Feb 2025 23:22:54 +0800 Subject: [PATCH] feat: Add thought content auto-collapse setting --- src/renderer/src/i18n/locales/en-us.json | 2 ++ src/renderer/src/i18n/locales/ja-jp.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 ++ .../pages/home/Messages/MessageThought.tsx | 6 +++--- .../src/pages/home/Tabs/SettingsTab.tsx | 20 +++++++++++++++++-- src/renderer/src/store/settings.ts | 10 ++++++++-- 8 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/renderer/src/i18n/locales/en-us.json b/src/renderer/src/i18n/locales/en-us.json index fe7d4845..1b61eabf 100644 --- a/src/renderer/src/i18n/locales/en-us.json +++ b/src/renderer/src/i18n/locales/en-us.json @@ -121,6 +121,8 @@ "settings.top_p.tip": "Default value is 1, the smaller the value, the less variety in the answers, the easier to understand, the larger the value, the larger the range of the AI's vocabulary, the more diverse", "settings.max_tokens.confirm": "Enable max tokens limit", "settings.max_tokens.confirm_content": "Enable max tokens limit, affects the length of the result. Need to consider the context limit of the model, otherwise an error will be reported", + "settings.thought_auto_collapse": "Automatically Collapse Thought Content", + "settings.thought_auto_collapse.tip": "Automatically collapse thought content after thinking ends", "suggestions.title": "Suggested Questions", "thinking": "Thinking", "topics.auto_rename": "Auto Rename", diff --git a/src/renderer/src/i18n/locales/ja-jp.json b/src/renderer/src/i18n/locales/ja-jp.json index 3910e62b..89c9d7d0 100644 --- a/src/renderer/src/i18n/locales/ja-jp.json +++ b/src/renderer/src/i18n/locales/ja-jp.json @@ -121,6 +121,8 @@ "settings.top_p.tip": "デフォルト値は1で、値が小さいほど回答の多様性が減り、理解しやすくなります。値が大きいほど、AIの語彙範囲が広がり、多様性が増します", "settings.max_tokens.confirm": "最大トークン制限を有効にする", "settings.max_tokens.confirm_content": "最大トークン制限を有効にすると、モデルが生成できる最大トークン数が制限されます。これにより、返される結果の長さに影響が出る可能性があります。モデルのコンテキスト制限に基づいて設定する必要があります。そうしないとエラーが発生します", + "settings.thought_auto_collapse": "思考内容を自動的に折りたたむ", + "settings.thought_auto_collapse.tip": "思考が終了したら思考内容を自動的に折りたたみます", "suggestions.title": "提案された質問", "thinking": "思考中...", "topics.auto_rename": "自動リネーム", diff --git a/src/renderer/src/i18n/locales/ru-ru.json b/src/renderer/src/i18n/locales/ru-ru.json index c0ba5b19..b98332d6 100644 --- a/src/renderer/src/i18n/locales/ru-ru.json +++ b/src/renderer/src/i18n/locales/ru-ru.json @@ -121,6 +121,8 @@ "settings.top_p.tip": "Значение по умолчанию 1, чем меньше значение, тем меньше вариативности в ответах, тем проще понять, чем больше значение, тем больше вариативности в ответах, тем больше разнообразие", "settings.max_tokens.confirm": "Включить лимит максимальных токенов", "settings.max_tokens.confirm_content": "Включить лимит максимальных токенов, влияет на длину результата. Нужно учитывать контекст модели, иначе будет ошибка", + "settings.thought_auto_collapse": "Автоматически сворачивать содержание мыслей", + "settings.thought_auto_collapse.tip": "Автоматически сворачивать содержание мыслей после завершения размышления", "suggestions.title": "Предложенные вопросы", "thinking": "Мыслим", "topics.auto_rename": "Автопереименование", diff --git a/src/renderer/src/i18n/locales/zh-cn.json b/src/renderer/src/i18n/locales/zh-cn.json index d74752ad..4f3b1fcf 100644 --- a/src/renderer/src/i18n/locales/zh-cn.json +++ b/src/renderer/src/i18n/locales/zh-cn.json @@ -123,6 +123,8 @@ "settings.top_p.tip": "默认值为 1,值越小,AI 生成的内容越单调,也越容易理解;值越大,AI 回复的词汇围越大,越多样化", "settings.max_tokens.confirm": "开启消息长度限制", "settings.max_tokens.confirm_content": "开启消息长度限制后,单次交互所用的最大 Token 数, 会影响返回结果的长度。要根据模型上下文限制来设置,否则会报错", + "settings.thought_auto_collapse": "思考内容自动折叠", + "settings.thought_auto_collapse.tip": "思考结束后思考内容自动折叠", "suggestions.title": "建议的问题", "thinking": "思考中", "topics.auto_rename": "生成话题名", diff --git a/src/renderer/src/i18n/locales/zh-tw.json b/src/renderer/src/i18n/locales/zh-tw.json index a43f5b03..3dc4ab99 100644 --- a/src/renderer/src/i18n/locales/zh-tw.json +++ b/src/renderer/src/i18n/locales/zh-tw.json @@ -121,6 +121,8 @@ "settings.top_p.tip": "模型生成文本的隨機程度。值越小,AI 生成的內容越單調,也越容易理解;值越大,AI 回覆的詞彙範圍越大,越多樣化", "settings.max_tokens.confirm": "啟用消息長度限制", "settings.max_tokens.confirm_content": "啟用消息長度限制後,單次交互所用的最大 Token 數, 會影響返回結果的長度。要根據模型上下文限制來設置,否則會報錯", + "settings.thought_auto_collapse": "思考內容自動折疊", + "settings.thought_auto_collapse.tip": "思考結束後思考內容自動折疊", "suggestions.title": "建議的問題", "thinking": "思考中", "topics.auto_rename": "自動重新命名", diff --git a/src/renderer/src/pages/home/Messages/MessageThought.tsx b/src/renderer/src/pages/home/Messages/MessageThought.tsx index 38b72957..332633c1 100644 --- a/src/renderer/src/pages/home/Messages/MessageThought.tsx +++ b/src/renderer/src/pages/home/Messages/MessageThought.tsx @@ -18,7 +18,7 @@ const MessageThought: FC = ({ message }) => { const [copied, setCopied] = useState(false) const isThinking = !message.content const { t } = useTranslation() - const { messageFont, fontSize } = useSettings() + const { messageFont, fontSize, thoughtAutoCollapse } = useSettings() const fontFamily = useMemo(() => { return messageFont === 'serif' ? 'serif' @@ -26,8 +26,8 @@ const MessageThought: FC = ({ message }) => { }, [messageFont]) useEffect(() => { - if (!isThinking) setActiveKey('') - }, [isThinking]) + if (!isThinking && thoughtAutoCollapse) setActiveKey('') + }, [isThinking, thoughtAutoCollapse]) if (!message.reasoning_content) { return null diff --git a/src/renderer/src/pages/home/Tabs/SettingsTab.tsx b/src/renderer/src/pages/home/Tabs/SettingsTab.tsx index af91b896..616454f1 100644 --- a/src/renderer/src/pages/home/Tabs/SettingsTab.tsx +++ b/src/renderer/src/pages/home/Tabs/SettingsTab.tsx @@ -27,7 +27,8 @@ import { setPasteLongTextThreshold, setRenderInputMessageAsMarkdown, setShowInputEstimatedTokens, - setShowMessageDivider + setShowMessageDivider, + setThoughtAutoCollapse } from '@renderer/store/settings' import { Assistant, AssistantSettings, ThemeMode, TranslateLanguageVarious } from '@renderer/types' import { modalConfirm } from '@renderer/utils' @@ -69,7 +70,8 @@ const SettingsTab: FC = (props) => { mathEngine, autoTranslateWithSpace, pasteLongTextThreshold, - multiModelMessageStyle + multiModelMessageStyle, + thoughtAutoCollapse } = useSettings() const onUpdateAssistantSettings = (settings: Partial) => { @@ -261,6 +263,20 @@ const SettingsTab: FC = (props) => { /> + + + {t('chat.settings.thought_auto_collapse')} + + + + + dispatch(setThoughtAutoCollapse(checked))} + /> + + {t('message.message.style')}