mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-29 05:51:26 +08:00
Merge branch 'main' into feat/qwen3-support
This commit is contained in:
commit
9120136f45
@ -222,7 +222,7 @@ export async function upgradeToV7(tx: Transaction): Promise<void> {
|
||||
if (oldMessage.metadata?.webSearch) {
|
||||
hasCitationData = true
|
||||
citationDataToCreate.response = {
|
||||
results: oldMessage.metadata.webSearch?.results,
|
||||
results: oldMessage.metadata.webSearch,
|
||||
source: WebSearchSource.WEBSEARCH
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,7 +98,7 @@
|
||||
"artifacts.button.preview": "Preview",
|
||||
"artifacts.preview.openExternal.error.content": "Error opening the external browser.",
|
||||
"assistant.search.placeholder": "Search",
|
||||
"deeply_thought": "Deeply thought ({{secounds}} seconds)",
|
||||
"deeply_thought": "Deeply thought ({{seconds}} seconds)",
|
||||
"default.description": "Hello, I'm Default Assistant. You can start chatting with me right away",
|
||||
"default.name": "Default Assistant",
|
||||
"default.topic.name": "Default Topic",
|
||||
@ -183,6 +183,7 @@
|
||||
"settings.top_p": "Top-P",
|
||||
"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",
|
||||
"suggestions.title": "Suggested Questions",
|
||||
"thinking": "Thinking ({{seconds}} seconds)",
|
||||
"topics.auto_rename": "Auto Rename",
|
||||
"topics.clear.title": "Clear Messages",
|
||||
"topics.copy.image": "Copy as image",
|
||||
@ -254,7 +255,6 @@
|
||||
"input.thinking.mode.custom": "Custom",
|
||||
"input.thinking.mode.custom.tip": "The maximum number of tokens the model can think. Need to consider the context limit of the model, otherwise an error will be reported",
|
||||
"input.thinking.mode.tokens.tip": "Set the number of thinking tokens to use.",
|
||||
"thinking": "Thinking",
|
||||
"input.thinking.budget_exceeds_max": "Thinking budget exceeds the maximum token number"
|
||||
},
|
||||
"code_block": {
|
||||
|
||||
@ -98,7 +98,7 @@
|
||||
"artifacts.button.preview": "プレビュー",
|
||||
"artifacts.preview.openExternal.error.content": "外部ブラウザの起動に失敗しました。",
|
||||
"assistant.search.placeholder": "検索",
|
||||
"deeply_thought": "深く考えています({{secounds}} 秒)",
|
||||
"deeply_thought": "深く考えています({{seconds}} 秒)",
|
||||
"default.description": "こんにちは、私はデフォルトのアシスタントです。すぐにチャットを始められます。",
|
||||
"default.name": "デフォルトアシスタント",
|
||||
"default.topic.name": "デフォルトトピック",
|
||||
@ -183,7 +183,7 @@
|
||||
"settings.top_p": "Top-P",
|
||||
"settings.top_p.tip": "デフォルト値は1で、値が小さいほど回答の多様性が減り、理解しやすくなります。値が大きいほど、AIの語彙範囲が広がり、多様性が増します",
|
||||
"suggestions.title": "提案された質問",
|
||||
"thinking": "思考中...",
|
||||
"thinking": "思考中(用時 {{seconds}} 秒)",
|
||||
"topics.auto_rename": "自動リネーム",
|
||||
"topics.clear.title": "メッセージをクリア",
|
||||
"topics.copy.image": "画像としてコピー",
|
||||
|
||||
@ -97,7 +97,7 @@
|
||||
"artifacts.button.preview": "Предпросмотр",
|
||||
"artifacts.preview.openExternal.error.content": "Внешний браузер открылся с ошибкой",
|
||||
"assistant.search.placeholder": "Поиск",
|
||||
"deeply_thought": "Мыслим ({{secounds}} секунд)",
|
||||
"deeply_thought": "Мыслим ({{seconds}} секунд)",
|
||||
"default.description": "Привет, я Ассистент по умолчанию. Вы можете начать общаться со мной прямо сейчас",
|
||||
"default.name": "Ассистент по умолчанию",
|
||||
"default.topic.name": "Топик по умолчанию",
|
||||
@ -182,7 +182,7 @@
|
||||
"settings.top_p": "Top-P",
|
||||
"settings.top_p.tip": "Значение по умолчанию 1, чем меньше значение, тем меньше вариативности в ответах, тем проще понять, чем больше значение, тем больше вариативности в ответах, тем больше разнообразие",
|
||||
"suggestions.title": "Предложенные вопросы",
|
||||
"thinking": "Мыслим",
|
||||
"thinking": "Мыслим ({{seconds}} секунд)",
|
||||
"topics.auto_rename": "Автопереименование",
|
||||
"topics.clear.title": "Очистить сообщения",
|
||||
"topics.copy.image": "Скопировать как изображение",
|
||||
|
||||
@ -98,7 +98,7 @@
|
||||
"artifacts.button.preview": "预览",
|
||||
"artifacts.preview.openExternal.error.content": "外部浏览器打开出错",
|
||||
"assistant.search.placeholder": "搜索",
|
||||
"deeply_thought": "已深度思考(用时 {{secounds}} 秒)",
|
||||
"deeply_thought": "已深度思考(用时 {{seconds}} 秒)",
|
||||
"default.description": "你好,我是默认助手。你可以立刻开始跟我聊天。",
|
||||
"default.name": "默认助手",
|
||||
"default.topic.name": "默认话题",
|
||||
@ -195,7 +195,7 @@
|
||||
"settings.top_p": "Top-P",
|
||||
"settings.top_p.tip": "默认值为 1,值越小,AI 生成的内容越单调,也越容易理解;值越大,AI 回复的词汇围越大,越多样化",
|
||||
"suggestions.title": "建议的问题",
|
||||
"thinking": "思考中",
|
||||
"thinking": "思考中(用时 {{seconds}} 秒)",
|
||||
"topics.auto_rename": "生成话题名",
|
||||
"topics.clear.title": "清空消息",
|
||||
"topics.copy.image": "复制为图片",
|
||||
|
||||
@ -98,7 +98,7 @@
|
||||
"artifacts.button.preview": "預覽",
|
||||
"artifacts.preview.openExternal.error.content": "外部瀏覽器開啟出錯",
|
||||
"assistant.search.placeholder": "搜尋",
|
||||
"deeply_thought": "已深度思考(用時 {{secounds}} 秒)",
|
||||
"deeply_thought": "已深度思考(用時 {{seconds}} 秒)",
|
||||
"default.description": "你好,我是預設助手。你可以立即開始與我聊天。",
|
||||
"default.name": "預設助手",
|
||||
"default.topic.name": "預設話題",
|
||||
@ -183,7 +183,7 @@
|
||||
"settings.top_p": "Top-P",
|
||||
"settings.top_p.tip": "模型生成文字的隨機程度。值越小,AI 生成的內容越單調,也越容易理解;值越大,AI 回覆的詞彙範圍越大,越多樣化",
|
||||
"suggestions.title": "建議的問題",
|
||||
"thinking": "思考中",
|
||||
"thinking": "思考中(用時 {{seconds}} 秒)",
|
||||
"topics.auto_rename": "自動重新命名",
|
||||
"topics.clear.title": "清空訊息",
|
||||
"topics.copy.image": "複製為圖片",
|
||||
|
||||
@ -1,14 +1,149 @@
|
||||
import type { ThinkingMessageBlock } from '@renderer/types/newMessage'
|
||||
import React from 'react'
|
||||
import { CheckOutlined } from '@ant-design/icons'
|
||||
import { useSettings } from '@renderer/hooks/useSettings'
|
||||
import { MessageBlockStatus, type ThinkingMessageBlock } from '@renderer/types/newMessage'
|
||||
import { Collapse, message as antdMessage, Tooltip } from 'antd'
|
||||
import { memo, useCallback, useEffect, useMemo, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import BarLoader from 'react-spinners/BarLoader'
|
||||
import styled from 'styled-components'
|
||||
|
||||
import MessageThought from '../MessageThought'
|
||||
import Markdown from '../../Markdown/Markdown'
|
||||
interface Props {
|
||||
block: ThinkingMessageBlock
|
||||
}
|
||||
|
||||
const ThinkingBlock: React.FC<Props> = ({ block }) => {
|
||||
// 创建思考过程的显示组件
|
||||
return <MessageThought message={block} />
|
||||
const [copied, setCopied] = useState(false)
|
||||
const { t } = useTranslation()
|
||||
const { messageFont, fontSize, thoughtAutoCollapse } = useSettings()
|
||||
const [activeKey, setActiveKey] = useState<'thought' | ''>(thoughtAutoCollapse ? '' : 'thought')
|
||||
|
||||
const isThinking = useMemo(() => block.status === MessageBlockStatus.STREAMING, [block.status])
|
||||
|
||||
const fontFamily = useMemo(() => {
|
||||
return messageFont === 'serif'
|
||||
? 'serif'
|
||||
: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans","Helvetica Neue", sans-serif'
|
||||
}, [messageFont])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isThinking && thoughtAutoCollapse) {
|
||||
setActiveKey('')
|
||||
} else {
|
||||
setActiveKey('thought')
|
||||
}
|
||||
}, [isThinking, thoughtAutoCollapse])
|
||||
|
||||
const copyThought = useCallback(() => {
|
||||
if (block.content) {
|
||||
navigator.clipboard
|
||||
.writeText(block.content)
|
||||
.then(() => {
|
||||
antdMessage.success({ content: t('message.copied'), key: 'copy-message' })
|
||||
setCopied(true)
|
||||
setTimeout(() => setCopied(false), 2000)
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Failed to copy text:', error)
|
||||
antdMessage.error({ content: t('message.copy.failed'), key: 'copy-message-error' })
|
||||
})
|
||||
}
|
||||
}, [block.content, t])
|
||||
|
||||
if (!block.content) {
|
||||
return null
|
||||
}
|
||||
|
||||
const thinkingTime = block.thinking_millsec || 0
|
||||
const thinkingTimeSeconds = (thinkingTime / 1000).toFixed(1)
|
||||
|
||||
return (
|
||||
<CollapseContainer
|
||||
activeKey={activeKey}
|
||||
size="small"
|
||||
onChange={() => setActiveKey((key) => (key ? '' : 'thought'))}
|
||||
className="message-thought-container"
|
||||
items={[
|
||||
{
|
||||
key: 'thought',
|
||||
label: (
|
||||
<MessageTitleLabel>
|
||||
<ThinkingText>
|
||||
{t(isThinking ? 'chat.thinking' : 'chat.deeply_thought', {
|
||||
seconds: thinkingTimeSeconds
|
||||
})}
|
||||
</ThinkingText>
|
||||
{isThinking && <BarLoader color="#9254de" />}
|
||||
{!isThinking && (
|
||||
<Tooltip title={t('common.copy')} mouseEnterDelay={0.8}>
|
||||
<ActionButton
|
||||
className="message-action-button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
copyThought()
|
||||
}}
|
||||
aria-label={t('common.copy')}>
|
||||
{!copied && <i className="iconfont icon-copy"></i>}
|
||||
{copied && <CheckOutlined style={{ color: 'var(--color-primary)' }} />}
|
||||
</ActionButton>
|
||||
</Tooltip>
|
||||
)}
|
||||
</MessageTitleLabel>
|
||||
),
|
||||
children: (
|
||||
// FIXME: 临时兼容
|
||||
<div style={{ fontFamily, fontSize }}>
|
||||
<Markdown block={block} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
]}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export default React.memo(ThinkingBlock)
|
||||
const CollapseContainer = styled(Collapse)`
|
||||
margin-bottom: 15px;
|
||||
`
|
||||
|
||||
const MessageTitleLabel = styled.div`
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
height: 22px;
|
||||
gap: 15px;
|
||||
`
|
||||
|
||||
const ThinkingText = styled.span`
|
||||
color: var(--color-text-2);
|
||||
`
|
||||
|
||||
const ActionButton = styled.button`
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--color-text-2);
|
||||
cursor: pointer;
|
||||
padding: 4px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-left: auto;
|
||||
opacity: 0.6;
|
||||
transition: all 0.3s;
|
||||
|
||||
&:hover {
|
||||
opacity: 1;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
&:focus-visible {
|
||||
outline: 2px solid var(--color-primary);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.iconfont {
|
||||
font-size: 14px;
|
||||
}
|
||||
`
|
||||
|
||||
export default memo(ThinkingBlock)
|
||||
|
||||
@ -1,136 +0,0 @@
|
||||
import { CheckOutlined } from '@ant-design/icons'
|
||||
import { useSettings } from '@renderer/hooks/useSettings'
|
||||
import { ThinkingMessageBlock } from '@renderer/types/newMessage'
|
||||
import { Collapse, message as antdMessage, Tooltip } from 'antd'
|
||||
import { FC, useEffect, useMemo, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import BarLoader from 'react-spinners/BarLoader'
|
||||
import styled from 'styled-components'
|
||||
|
||||
import Markdown from '../Markdown/Markdown'
|
||||
|
||||
interface Props {
|
||||
message: ThinkingMessageBlock
|
||||
}
|
||||
|
||||
const MessageThought: FC<Props> = ({ message }) => {
|
||||
const [activeKey, setActiveKey] = useState<'thought' | ''>('thought')
|
||||
const [copied, setCopied] = useState(false)
|
||||
const isThinking = !message.content
|
||||
const { t } = useTranslation()
|
||||
const { messageFont, fontSize, thoughtAutoCollapse } = useSettings()
|
||||
const fontFamily = useMemo(() => {
|
||||
return messageFont === 'serif'
|
||||
? 'serif'
|
||||
: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans","Helvetica Neue", sans-serif'
|
||||
}, [messageFont])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isThinking && thoughtAutoCollapse) setActiveKey('')
|
||||
}, [isThinking, thoughtAutoCollapse])
|
||||
|
||||
if (!message.content) {
|
||||
return null
|
||||
}
|
||||
|
||||
const copyThought = () => {
|
||||
if (message.content) {
|
||||
navigator.clipboard.writeText(message.content)
|
||||
antdMessage.success({ content: t('message.copied'), key: 'copy-message' })
|
||||
setCopied(true)
|
||||
setTimeout(() => setCopied(false), 2000)
|
||||
}
|
||||
}
|
||||
|
||||
const thinkingTime = message.thinking_millsec || 0
|
||||
const thinkingTimeSeconds = (thinkingTime / 1000).toFixed(1)
|
||||
const isPaused = message.status === 'paused'
|
||||
|
||||
return (
|
||||
<CollapseContainer
|
||||
activeKey={activeKey}
|
||||
size="small"
|
||||
onChange={() => setActiveKey((key) => (key ? '' : 'thought'))}
|
||||
className="message-thought-container"
|
||||
items={[
|
||||
{
|
||||
key: 'thought',
|
||||
label: (
|
||||
<MessageTitleLabel>
|
||||
<TinkingText>
|
||||
{isThinking ? t('chat.thinking') : t('chat.deeply_thought', { secounds: thinkingTimeSeconds })}
|
||||
</TinkingText>
|
||||
{isThinking && !isPaused && <BarLoader color="#9254de" />}
|
||||
{(!isThinking || isPaused) && (
|
||||
<Tooltip title={t('common.copy')} mouseEnterDelay={0.8}>
|
||||
<ActionButton
|
||||
className="message-action-button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
copyThought()
|
||||
}}
|
||||
aria-label={t('common.copy')}>
|
||||
{!copied && <i className="iconfont icon-copy"></i>}
|
||||
{copied && <CheckOutlined style={{ color: 'var(--color-primary)' }} />}
|
||||
</ActionButton>
|
||||
</Tooltip>
|
||||
)}
|
||||
</MessageTitleLabel>
|
||||
),
|
||||
children: (
|
||||
// FIXME: 临时兼容
|
||||
<div style={{ fontFamily, fontSize }}>
|
||||
<Markdown block={{ ...message, content: message.content }} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
]}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const CollapseContainer = styled(Collapse)`
|
||||
margin-bottom: 15px;
|
||||
`
|
||||
|
||||
const MessageTitleLabel = styled.div`
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
height: 22px;
|
||||
gap: 15px;
|
||||
`
|
||||
|
||||
const TinkingText = styled.span`
|
||||
color: var(--color-text-2);
|
||||
`
|
||||
|
||||
const ActionButton = styled.button`
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--color-text-2);
|
||||
cursor: pointer;
|
||||
padding: 4px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-left: auto;
|
||||
opacity: 0.6;
|
||||
transition: all 0.3s;
|
||||
|
||||
&:hover {
|
||||
opacity: 1;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
&:focus-visible {
|
||||
outline: 2px solid var(--color-primary);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.iconfont {
|
||||
font-size: 14px;
|
||||
}
|
||||
`
|
||||
|
||||
export default MessageThought
|
||||
@ -1,5 +1,5 @@
|
||||
import { MCPPrompt } from '@renderer/types'
|
||||
import { Collapse, Descriptions, Empty, Flex, Tag, Tooltip, Typography } from 'antd'
|
||||
import { Collapse, Descriptions, Empty, Flex, Tooltip, Typography } from 'antd'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import styled from 'styled-components'
|
||||
|
||||
@ -22,11 +22,11 @@ const MCPPromptsSection = ({ prompts }: MCPPromptsSectionProps) => {
|
||||
<Descriptions.Item
|
||||
key={index}
|
||||
label={
|
||||
<Flex vertical gap={4}>
|
||||
<Flex gap={4}>
|
||||
<Typography.Text strong>{arg.name}</Typography.Text>
|
||||
{arg.required && (
|
||||
<Tooltip title="Required field">
|
||||
<Tag color="red">Required</Tag>
|
||||
<span style={{ color: '#f5222d' }}>*</span>
|
||||
</Tooltip>
|
||||
)}
|
||||
</Flex>
|
||||
|
||||
@ -51,11 +51,11 @@ const MCPToolsSection = ({ tools, server, onToggleTool }: MCPToolsSectionProps)
|
||||
<Descriptions.Item
|
||||
key={key}
|
||||
label={
|
||||
<Flex vertical gap={4}>
|
||||
<Flex gap={4}>
|
||||
<Typography.Text strong>{key}</Typography.Text>
|
||||
{tool.inputSchema.required?.includes(key) && (
|
||||
<Tooltip title="Required field">
|
||||
<Tag color="red">Required</Tag>
|
||||
<span style={{ color: '#f5222d' }}>*</span>
|
||||
</Tooltip>
|
||||
)}
|
||||
</Flex>
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import db from '@renderer/databases'
|
||||
import { autoRenameTopic } from '@renderer/hooks/useTopic'
|
||||
import { fetchChatCompletion } from '@renderer/services/ApiService'
|
||||
import { createStreamProcessor, type StreamProcessorCallbacks } from '@renderer/services/StreamProcessingService'
|
||||
import { estimateMessagesUsage } from '@renderer/services/TokenService'
|
||||
@ -590,6 +591,9 @@ const fetchAndProcessAssistantResponseImpl = async (
|
||||
const contextForUsage = userMsgIndex !== -1 ? orderedMsgs.slice(0, userMsgIndex + 1) : []
|
||||
const finalContextWithAssistant = [...contextForUsage, finalAssistantMsg]
|
||||
|
||||
// 更新topic的name
|
||||
autoRenameTopic(assistant, topicId)
|
||||
|
||||
const usage = await estimateMessagesUsage({ assistant, messages: finalContextWithAssistant })
|
||||
response.usage = usage
|
||||
}
|
||||
|
||||
@ -89,7 +89,7 @@ export type LegacyMessage = {
|
||||
// Zhipu or Hunyuan
|
||||
webSearchInfo?: any[]
|
||||
// Web search
|
||||
webSearch?: WebSearchResponse
|
||||
webSearch?: WebSearchProviderResponse
|
||||
// MCP Tools
|
||||
mcpTools?: MCPToolResponse[]
|
||||
// Generate Image
|
||||
|
||||
Loading…
Reference in New Issue
Block a user