diff --git a/src/renderer/src/pages/home/Assistants.tsx b/src/renderer/src/pages/home/Assistants.tsx index 03d7e83c..34eec238 100644 --- a/src/renderer/src/pages/home/Assistants.tsx +++ b/src/renderer/src/pages/home/Assistants.tsx @@ -1,5 +1,6 @@ -import { CopyOutlined, DeleteOutlined, EditOutlined, MinusCircleOutlined } from '@ant-design/icons' +import { DeleteOutlined, EditOutlined, MinusCircleOutlined } from '@ant-design/icons' import DragableList from '@renderer/components/DragableList' +import CopyIcon from '@renderer/components/Icons/CopyIcon' import AssistantSettingPopup from '@renderer/components/Popups/AssistantSettingPopup' import { useAssistant, useAssistants } from '@renderer/hooks/useAssistant' import { useShowTopics } from '@renderer/hooks/useStore' @@ -58,7 +59,7 @@ const Assistants: FC = ({ activeAssistant, setActiveAssistant, onCreateAs { label: t('common.duplicate'), key: 'duplicate', - icon: , + icon: , onClick: async () => { const _assistant: Assistant = { ...assistant, id: uuid(), topics: [getDefaultTopic()] } addAssistant(_assistant) diff --git a/src/renderer/src/pages/home/Chat.tsx b/src/renderer/src/pages/home/Chat.tsx index 9f901317..a7127330 100644 --- a/src/renderer/src/pages/home/Chat.tsx +++ b/src/renderer/src/pages/home/Chat.tsx @@ -1,6 +1,5 @@ import { useAssistant } from '@renderer/hooks/useAssistant' import { useSettings } from '@renderer/hooks/useSettings' -import { useShowTopics } from '@renderer/hooks/useStore' import { Assistant, Topic } from '@renderer/types' import { Flex } from 'antd' import { FC } from 'react' @@ -8,7 +7,7 @@ import styled from 'styled-components' import Inputbar from './Inputbar/Inputbar' import Messages from './Messages/Messages' -import Topics from './Topics' +import RightSidebar from './RightSidebar' interface Props { assistant: Assistant @@ -18,20 +17,19 @@ interface Props { const Chat: FC = (props) => { const { assistant } = useAssistant(props.assistant.id) - const { showTopics } = useShowTopics() const { topicPosition } = useSettings() return ( - {showTopics && topicPosition === 'left' && ( - + {topicPosition === 'left' && ( + )}
- {showTopics && topicPosition === 'right' && ( - + {topicPosition === 'right' && ( + )}
) diff --git a/src/renderer/src/pages/home/Inputbar/Inputbar.tsx b/src/renderer/src/pages/home/Inputbar/Inputbar.tsx index f44a9ef4..f00a5da9 100644 --- a/src/renderer/src/pages/home/Inputbar/Inputbar.tsx +++ b/src/renderer/src/pages/home/Inputbar/Inputbar.tsx @@ -1,17 +1,15 @@ import { ClearOutlined, ControlOutlined, - FormOutlined, FullscreenExitOutlined, FullscreenOutlined, HistoryOutlined, PauseCircleOutlined, + PlusCircleOutlined, QuestionCircleOutlined } from '@ant-design/icons' -import { isWindows } from '@renderer/config/constant' import { useAssistant } from '@renderer/hooks/useAssistant' import { useSettings } from '@renderer/hooks/useSettings' -import { useShowTopics } from '@renderer/hooks/useStore' import { getDefaultTopic } from '@renderer/services/assistant' import { EVENT_NAMES, EventEmitter } from '@renderer/services/event' import { estimateInputTokenCount } from '@renderer/services/messages' @@ -19,7 +17,7 @@ import store, { useAppSelector } from '@renderer/store' import { setGenerating } from '@renderer/store/runtime' import { Assistant, Message, Topic } from '@renderer/types' import { delay, uuid } from '@renderer/utils' -import { Button, Divider, Popconfirm, Popover, Tag, Tooltip } from 'antd' +import { Button, Popconfirm, Tooltip } from 'antd' import TextArea, { TextAreaRef } from 'antd/es/input/TextArea' import dayjs from 'dayjs' import { debounce, isEmpty } from 'lodash' @@ -27,8 +25,8 @@ import { CSSProperties, FC, useCallback, useEffect, useMemo, useRef, useState } import { useTranslation } from 'react-i18next' import styled from 'styled-components' -import SettingsTab from '../Settings' import SendMessageButton from './SendMessageButton' +import TokenCount from './TokenCount' interface Props { assistant: Assistant @@ -41,7 +39,7 @@ const Inputbar: FC = ({ assistant, setActiveTopic }) => { const [text, setText] = useState(_text) const [inputFocus, setInputFocus] = useState(false) const { addTopic } = useAssistant(assistant.id) - const { sendMessageShortcut, showInputEstimatedTokens, fontSize } = useSettings() + const { sendMessageShortcut, fontSize } = useSettings() const [expended, setExpend] = useState(false) const [estimateTokenCount, setEstimateTokenCount] = useState(0) const [contextCount, setContextCount] = useState(0) @@ -50,7 +48,6 @@ const Inputbar: FC = ({ assistant, setActiveTopic }) => { const [files, setFiles] = useState([]) const { t } = useTranslation() const containerRef = useRef(null) - const { toggleShowTopics } = useShowTopics() _text = text @@ -221,12 +218,7 @@ const Inputbar: FC = ({ assistant, setActiveTopic }) => { - - - - - - + @@ -243,36 +235,28 @@ const Inputbar: FC = ({ assistant, setActiveTopic }) => { - + EventEmitter.emit(EVENT_NAMES.SHOW_TOPIC_SIDEBAR)}> - } trigger="click" placement="topRight"> - - - - - - + + EventEmitter.emit(EVENT_NAMES.SHOW_CHAT_SETTINGS)}> + + + {/* */} {expended ? : } - {showInputEstimatedTokens && ( - - - - - {contextCount} - ↑{inputTokenCount} - / - {estimateTokenCount} - - - - )} + {generating && ( @@ -291,8 +275,7 @@ const Inputbar: FC = ({ assistant, setActiveTopic }) => { const TextareaStyle: CSSProperties = { paddingLeft: 0, - padding: '10px 15px 8px', - transition: 'all 0.3s ease' + padding: '10px 15px 8px' } const Container = styled.div` @@ -346,9 +329,6 @@ const ToolbarButton = styled(Button)` justify-content: center; align-items: center; padding: 0; - .iconfont { - font-size: 17px; - } &.anticon, &.iconfont { transition: all 0.3s ease; @@ -364,26 +344,4 @@ const ToolbarButton = styled(Button)` } ` -const TextCount = styled.div` - font-size: 11px; - color: var(--color-text-3); - z-index: 10; - padding: 2px; - border-top-left-radius: 7px; - user-select: none; -` - -const StyledTag = styled(Tag)` - cursor: pointer; - border-radius: 20px; - display: flex; - align-items: center; - padding: 2px 8px; - border-width: 0.5; - margin: 0; - height: 25px; - font-size: 12px; - line-height: 16px; -` - export default Inputbar diff --git a/src/renderer/src/pages/home/Inputbar/TokenCount.tsx b/src/renderer/src/pages/home/Inputbar/TokenCount.tsx new file mode 100644 index 00000000..7d53f335 --- /dev/null +++ b/src/renderer/src/pages/home/Inputbar/TokenCount.tsx @@ -0,0 +1,83 @@ +import { ArrowUpOutlined, MenuOutlined, PicCenterOutlined } from '@ant-design/icons' +import { HStack, VStack } from '@renderer/components/Layout' +import { useSettings } from '@renderer/hooks/useSettings' +import { Divider, Popover, Tooltip } from 'antd' +import { FC } from 'react' +import { useTranslation } from 'react-i18next' +import styled from 'styled-components' + +type Props = { + estimateTokenCount: number + inputTokenCount: number + contextCount: number + ToolbarButton: any +} & React.HTMLAttributes + +const TokenCount: FC = ({ estimateTokenCount, inputTokenCount, contextCount, ToolbarButton, ...props }) => { + const { t } = useTranslation() + const { showInputEstimatedTokens } = useSettings() + + if (!showInputEstimatedTokens) { + return null + } + + const PopoverContent = () => { + return ( + + + {t('chat.input.context_count.tip')} + {contextCount} + + + + {t('chat.input.estimated_tokens.tip')} + {estimateTokenCount} + + + ) + } + + return ( + <> + + + + + + + + {contextCount} + + + {inputTokenCount} / {estimateTokenCount} + + + + ) +} + +const Container = styled.div` + font-size: 11px; + line-height: 16px; + color: var(--color-text-2); + z-index: 10; + padding: 3px 10px; + user-select: none; + font-family: Ubuntu; + border: 0.5px solid var(--color-text-3); + border-radius: 20px; + display: flex; + align-items: center; + cursor: pointer; + .anticon { + font-size: 10px; + margin-right: 3px; + } +` + +const Text = styled.div` + font-size: 12px; + color: var(--color-text-1); +` + +export default TokenCount diff --git a/src/renderer/src/pages/home/Markdown/CodeBlock.tsx b/src/renderer/src/pages/home/Markdown/CodeBlock.tsx index 67108795..855a045e 100644 --- a/src/renderer/src/pages/home/Markdown/CodeBlock.tsx +++ b/src/renderer/src/pages/home/Markdown/CodeBlock.tsx @@ -72,7 +72,7 @@ const CodeHeader = styled.div` font-size: 14px; font-weight: bold; background-color: var(--color-code-background); - height: 40px; + height: 36px; padding: 0 10px; border-top-left-radius: 8px; border-top-right-radius: 8px; diff --git a/src/renderer/src/pages/home/Navbar.tsx b/src/renderer/src/pages/home/Navbar.tsx index 2a77fb9e..a7b585e4 100644 --- a/src/renderer/src/pages/home/Navbar.tsx +++ b/src/renderer/src/pages/home/Navbar.tsx @@ -103,7 +103,6 @@ const HeaderNavbar: FC = ({ activeAssistant, setActiveAssistant, setActiv unCheckedChildren={} checked={theme === 'dark'} onChange={toggleTheme} - style={{ opacity: theme === 'dark' ? 0.6 : 1 }} /> {topicPosition === 'right' && ( diff --git a/src/renderer/src/pages/home/RightSidebar.tsx b/src/renderer/src/pages/home/RightSidebar.tsx index 4b4b3ce8..84419d17 100644 --- a/src/renderer/src/pages/home/RightSidebar.tsx +++ b/src/renderer/src/pages/home/RightSidebar.tsx @@ -1,4 +1,5 @@ import { BarsOutlined, SettingOutlined } from '@ant-design/icons' +import { useSettings } from '@renderer/hooks/useSettings' import { useShowTopics } from '@renderer/hooks/useStore' import { EVENT_NAMES, EventEmitter } from '@renderer/services/event' import { Assistant, Topic } from '@renderer/types' @@ -19,9 +20,12 @@ interface Props { const RightSidebar: FC = (props) => { const [tab, setTab] = useState<'topic' | 'settings'>('topic') const { showTopics, setShowTopics } = useShowTopics() + const { topicPosition } = useSettings() const { t } = useTranslation() + const isTopicTab = tab === 'topic' const isSettingsTab = tab === 'settings' + const borderStyle = '0.5px solid var(--color-border)' useEffect(() => { const unsubscribes = [ @@ -55,7 +59,7 @@ const RightSidebar: FC = (props) => { } return ( - + = ({ assistant: _assistant, activeTopic, setActiveTopic const { assistant, removeTopic, updateTopic, updateTopics } = useAssistant(_assistant.id) const { t } = useTranslation() const generating = useAppSelector((state) => state.runtime.generating) - const { topicPosition } = useSettings() - - const borderStyle = '0.5px solid var(--color-border)' const getTopicMenuItems = useCallback( (topic: Topic) => { @@ -92,7 +88,7 @@ const Topics: FC = ({ assistant: _assistant, activeTopic, setActiveTopic ) return ( - + {(topic) => { const isActive = topic.id === activeTopic?.id