feat: improved translation features and settings
This commit is contained in:
parent
09e6756efe
commit
aa72794967
@ -47,8 +47,21 @@ export const AGENT_PROMPT = `
|
|||||||
export const SUMMARIZE_PROMPT =
|
export const SUMMARIZE_PROMPT =
|
||||||
'你是一名擅长会话的助理,你需要将用户的会话总结为 10 个字以内的标题,标题语言与用户的首要语言一致,不要使用标点符号和其他特殊符号'
|
'你是一名擅长会话的助理,你需要将用户的会话总结为 10 个字以内的标题,标题语言与用户的首要语言一致,不要使用标点符号和其他特殊符号'
|
||||||
|
|
||||||
export const TRANSLATE_PROMPT =
|
export const TRANSLATE_PROMPT = `You are a translation expert.
|
||||||
'You are a translation expert. Translate from input language to {{target_language}}, provide the translation result directly without any explanation and keep original format. Do not translate if the target language is the same as the source language.'
|
|
||||||
|
Translate from input language to {{target_language}}
|
||||||
|
|
||||||
|
Requirements:
|
||||||
|
|
||||||
|
1. provide the translation result directly without any explanation and keep original format.
|
||||||
|
2. Do not translate if the target language is the same as the source language.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
input: 你好,今天天气怎么样?
|
||||||
|
target_language: english
|
||||||
|
output: Hello, how is the weather today?
|
||||||
|
`
|
||||||
|
|
||||||
export const REFERENCE_PROMPT = `请根据参考资料回答问题,并使用脚注格式引用数据来源。请忽略无关的参考资料。
|
export const REFERENCE_PROMPT = `请根据参考资料回答问题,并使用脚注格式引用数据来源。请忽略无关的参考资料。
|
||||||
|
|
||||||
|
|||||||
@ -156,51 +156,9 @@ const MessageMenubar: FC<Props> = (props) => {
|
|||||||
key: 'edit',
|
key: 'edit',
|
||||||
icon: <EditOutlined />,
|
icon: <EditOutlined />,
|
||||||
onClick: onEdit
|
onClick: onEdit
|
||||||
},
|
|
||||||
{
|
|
||||||
label: t('chat.translate'),
|
|
||||||
key: 'translate',
|
|
||||||
icon: isTranslating ? <SyncOutlined spin /> : <TranslationOutlined />,
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
label: '🇨🇳 ' + t('languages.chinese'),
|
|
||||||
key: 'translate-chinese',
|
|
||||||
onClick: () => handleTranslate('chinese')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '🇭🇰 ' + t('languages.chinese-traditional'),
|
|
||||||
key: 'translate-chinese-traditional',
|
|
||||||
onClick: () => handleTranslate('chinese-traditional')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '🇬🇧 ' + t('languages.english'),
|
|
||||||
key: 'translate-english',
|
|
||||||
onClick: () => handleTranslate('english')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '🇯🇵 ' + t('languages.japanese'),
|
|
||||||
key: 'translate-japanese',
|
|
||||||
onClick: () => handleTranslate('japanese')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '🇰🇷 ' + t('languages.korean'),
|
|
||||||
key: 'translate-korean',
|
|
||||||
onClick: () => handleTranslate('korean')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '🇷🇺 ' + t('languages.russian'),
|
|
||||||
key: 'translate-russian',
|
|
||||||
onClick: () => handleTranslate('russian')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '✖ ' + t('translate.close'),
|
|
||||||
key: 'translate-close',
|
|
||||||
onClick: () => onEditMessage?.({ ...message, translatedContent: undefined })
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
[handleTranslate, isTranslating, message, onEdit, onEditMessage, t]
|
[message, onEdit, t]
|
||||||
)
|
)
|
||||||
|
|
||||||
const onAtModelRegenerate = async () => {
|
const onAtModelRegenerate = async () => {
|
||||||
@ -261,6 +219,57 @@ const MessageMenubar: FC<Props> = (props) => {
|
|||||||
</ActionButton>
|
</ActionButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
|
{!isUserMessage && (
|
||||||
|
<Dropdown
|
||||||
|
menu={{
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
label: '🇨🇳 ' + t('languages.chinese'),
|
||||||
|
key: 'translate-chinese',
|
||||||
|
onClick: () => handleTranslate('chinese')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '🇭🇰 ' + t('languages.chinese-traditional'),
|
||||||
|
key: 'translate-chinese-traditional',
|
||||||
|
onClick: () => handleTranslate('chinese-traditional')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '🇬🇧 ' + t('languages.english'),
|
||||||
|
key: 'translate-english',
|
||||||
|
onClick: () => handleTranslate('english')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '🇯🇵 ' + t('languages.japanese'),
|
||||||
|
key: 'translate-japanese',
|
||||||
|
onClick: () => handleTranslate('japanese')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '🇰🇷 ' + t('languages.korean'),
|
||||||
|
key: 'translate-korean',
|
||||||
|
onClick: () => handleTranslate('korean')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '🇷🇺 ' + t('languages.russian'),
|
||||||
|
key: 'translate-russian',
|
||||||
|
onClick: () => handleTranslate('russian')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '✖ ' + t('translate.close'),
|
||||||
|
key: 'translate-close',
|
||||||
|
onClick: () => onEditMessage?.({ ...message, translatedContent: undefined })
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}}
|
||||||
|
trigger={['click']}
|
||||||
|
placement="topRight"
|
||||||
|
arrow>
|
||||||
|
<Tooltip title={t('chat.translate')} mouseEnterDelay={1.2}>
|
||||||
|
<ActionButton className="message-action-button">
|
||||||
|
<TranslationOutlined />
|
||||||
|
</ActionButton>
|
||||||
|
</Tooltip>
|
||||||
|
</Dropdown>
|
||||||
|
)}
|
||||||
<Popconfirm
|
<Popconfirm
|
||||||
title={t('message.message.delete.content')}
|
title={t('message.message.delete.content')}
|
||||||
okButtonProps={{ danger: true }}
|
okButtonProps={{ danger: true }}
|
||||||
|
|||||||
@ -198,7 +198,8 @@ export default class OpenAIProvider extends BaseProvider {
|
|||||||
model: model.id,
|
model: model.id,
|
||||||
messages: messages as ChatCompletionMessageParam[],
|
messages: messages as ChatCompletionMessageParam[],
|
||||||
stream: false,
|
stream: false,
|
||||||
keep_alive: this.keepAliveTime
|
keep_alive: this.keepAliveTime,
|
||||||
|
temperature: assistant?.settings?.temperature
|
||||||
})
|
})
|
||||||
|
|
||||||
return response.choices[0].message?.content || ''
|
return response.choices[0].message?.content || ''
|
||||||
|
|||||||
@ -23,6 +23,11 @@ export function getDefaultTranslateAssistant(targetLanguage: string, text: strin
|
|||||||
const translateModel = getTranslateModel()
|
const translateModel = getTranslateModel()
|
||||||
const assistant: Assistant = getDefaultAssistant()
|
const assistant: Assistant = getDefaultAssistant()
|
||||||
assistant.model = translateModel
|
assistant.model = translateModel
|
||||||
|
|
||||||
|
assistant.settings = {
|
||||||
|
temperature: 0.7
|
||||||
|
}
|
||||||
|
|
||||||
assistant.prompt = store
|
assistant.prompt = store
|
||||||
.getState()
|
.getState()
|
||||||
.settings.translateModelPrompt.replace('{{target_language}}', targetLanguage)
|
.settings.translateModelPrompt.replace('{{target_language}}', targetLanguage)
|
||||||
|
|||||||
20
yarn.lock
20
yarn.lock
@ -2639,6 +2639,13 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"@types/trusted-types@npm:^2.0.7":
|
||||||
|
version: 2.0.7
|
||||||
|
resolution: "@types/trusted-types@npm:2.0.7"
|
||||||
|
checksum: 10c0/4c4855f10de7c6c135e0d32ce462419d8abbbc33713b31d294596c0cc34ae1fa6112a2f9da729c8f7a20707782b0d69da3b1f8df6645b0366d08825ca1522e0c
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"@types/unist@npm:*, @types/unist@npm:^3.0.0":
|
"@types/unist@npm:*, @types/unist@npm:^3.0.0":
|
||||||
version: 3.0.3
|
version: 3.0.3
|
||||||
resolution: "@types/unist@npm:3.0.3"
|
resolution: "@types/unist@npm:3.0.3"
|
||||||
@ -2888,6 +2895,7 @@ __metadata:
|
|||||||
dexie: "npm:^4.0.8"
|
dexie: "npm:^4.0.8"
|
||||||
dexie-react-hooks: "npm:^1.1.7"
|
dexie-react-hooks: "npm:^1.1.7"
|
||||||
docx: "npm:^9.0.2"
|
docx: "npm:^9.0.2"
|
||||||
|
dompurify: "npm:^3.2.3"
|
||||||
dotenv-cli: "npm:^7.4.2"
|
dotenv-cli: "npm:^7.4.2"
|
||||||
electron: "npm:31.7.6"
|
electron: "npm:31.7.6"
|
||||||
electron-builder: "npm:^24.13.3"
|
electron-builder: "npm:^24.13.3"
|
||||||
@ -4982,6 +4990,18 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"dompurify@npm:^3.2.3":
|
||||||
|
version: 3.2.3
|
||||||
|
resolution: "dompurify@npm:3.2.3"
|
||||||
|
dependencies:
|
||||||
|
"@types/trusted-types": "npm:^2.0.7"
|
||||||
|
dependenciesMeta:
|
||||||
|
"@types/trusted-types":
|
||||||
|
optional: true
|
||||||
|
checksum: 10c0/0ce5cb89b76f396d800751bcb48e0d137792891d350ccc049f1bc9a5eca7332cc69030c25007ff4962e0824a5696904d4d74264df9277b5ad955642dfb6f313f
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"domutils@npm:^3.0.1":
|
"domutils@npm:^3.0.1":
|
||||||
version: 3.1.0
|
version: 3.1.0
|
||||||
resolution: "domutils@npm:3.1.0"
|
resolution: "domutils@npm:3.1.0"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user