fix: 文件保存相关问题 #208

This commit is contained in:
kangfenmao 2024-10-22 17:37:22 +08:00
parent 7e477cb9c7
commit 58817ae82f
7 changed files with 16 additions and 8 deletions

View File

@ -127,7 +127,8 @@
"copy.title": "Copy Assistant", "copy.title": "Copy Assistant",
"clear.title": "Clear topics", "clear.title": "Clear topics",
"clear.content": "Clearing the topic will delete all topics and files in the assistant. Are you sure you want to continue?", "clear.content": "Clearing the topic will delete all topics and files in the assistant. Are you sure you want to continue?",
"saveto.title": "Save to agent", "save.title": "Save to agent",
"save.success": "Saved successfully",
"delete.title": "Delete Assistant", "delete.title": "Delete Assistant",
"delete.content": "Deleting an assistant will delete all topics and files under the assistant. Are you sure you want to delete it?" "delete.content": "Deleting an assistant will delete all topics and files under the assistant. Are you sure you want to delete it?"
}, },

View File

@ -127,7 +127,8 @@
"copy.title": "复制助手", "copy.title": "复制助手",
"clear.title": "清空话题", "clear.title": "清空话题",
"clear.content": "清空话题会删除助手下所有话题和文件,确定要继续吗?", "clear.content": "清空话题会删除助手下所有话题和文件,确定要继续吗?",
"saveto.title": "保存到智能体", "save.title": "保存到智能体",
"save.success": "保存成功",
"delete.title": "删除助手", "delete.title": "删除助手",
"delete.content": "删除助手会删除所有该助手下的话题和文件,确定要继续吗?" "delete.content": "删除助手会删除所有该助手下的话题和文件,确定要继续吗?"
}, },

View File

@ -127,7 +127,8 @@
"copy.title": "複製助手", "copy.title": "複製助手",
"clear.title": "清空話題", "clear.title": "清空話題",
"clear.content": "清空話題會刪除助手下所有主題和文件,確定要繼續嗎?", "clear.content": "清空話題會刪除助手下所有主題和文件,確定要繼續嗎?",
"saveto.title": "儲存到智能體", "save.title": "儲存到智能體",
"save.success": "儲存成功",
"delete.title": "删除助手", "delete.title": "删除助手",
"delete.content": "删除助手会删除所有该助手下的话题和文件,确定要繼續吗?" "delete.content": "删除助手会删除所有该助手下的话题和文件,确定要繼續吗?"
}, },

View File

@ -32,8 +32,8 @@ const Agents: React.FC<Props> = ({ onClick }) => {
onClick: () => AssistantSettingsPopup.show({ assistant: agent }) onClick: () => AssistantSettingsPopup.show({ assistant: agent })
}, },
{ {
label: t('agents.add.title'), label: t('agents.add.button'),
key: 'add', key: 'create',
icon: <PlusOutlined />, icon: <PlusOutlined />,
onClick: () => createAssistantFromAgent(agent) onClick: () => createAssistantFromAgent(agent)
}, },

View File

@ -14,6 +14,7 @@ import { EVENT_NAMES, EventEmitter } from '@renderer/services/event'
import { Message, Model } from '@renderer/types' import { Message, Model } from '@renderer/types'
import { removeTrailingDoubleSpaces } from '@renderer/utils' import { removeTrailingDoubleSpaces } from '@renderer/utils'
import { Dropdown, Popconfirm, Tooltip } from 'antd' import { Dropdown, Popconfirm, Tooltip } from 'antd'
import dayjs from 'dayjs'
import { FC, useCallback, useMemo, useState } from 'react' import { FC, useCallback, useMemo, useState } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import styled from 'styled-components' import styled from 'styled-components'
@ -72,7 +73,7 @@ const MessageMenubar: FC<Props> = (props) => {
key: 'save', key: 'save',
icon: <SaveOutlined />, icon: <SaveOutlined />,
onClick: () => { onClick: () => {
const fileName = message.createdAt + '.md' const fileName = dayjs(message.createdAt).format('YYYYMMDDHHmm') + '.md'
window.api.file.save(fileName, message.content) window.api.file.save(fileName, message.content)
} }
}, },

View File

@ -85,7 +85,7 @@ const Assistants: FC<Props> = ({
} }
}, },
{ {
label: t('assistants.saveto.title'), label: t('assistants.save.title'),
key: 'save-to-agent', key: 'save-to-agent',
icon: <SaveOutlined />, icon: <SaveOutlined />,
onClick: async () => { onClick: async () => {
@ -93,6 +93,10 @@ const Assistants: FC<Props> = ({
agent.id = uuid() agent.id = uuid()
agent.type = 'agent' agent.type = 'agent'
addAgent(agent) addAgent(agent)
window.message.success({
content: t('assistants.save.success'),
key: 'save-to-agent'
})
} }
}, },
{ type: 'divider' }, { type: 'divider' },

View File

@ -77,7 +77,7 @@ export async function estimateMessageUsage(message: Message): Promise<Completion
return { return {
prompt_tokens: promptUsedTokens, prompt_tokens: promptUsedTokens,
completion_tokens: completionUsedTokens, completion_tokens: completionUsedTokens,
total_tokens: usedTokens + imageTokens - 7 total_tokens: usedTokens + (imageTokens ? imageTokens - 7 : 0)
} }
} }