feat(frontend): add copy action for model cards in settings
Allow users to duplicate non-builtin models (chat / embedding / rerank / VLLM / ASR) from the model card dropdown. The copied model inherits all parameters (base_url, api_key, provider, embedding params, custom headers, vision flag, etc.) and gets a non-conflicting name with a localized suffix, so users can quickly fork and tweak an existing configuration without re-entering every field. Adds matching i18n entries (copySuffix / toasts.copied / toasts.copyFailed / toasts.builtinCannotCopy) for zh-CN, en-US, ko-KR and ru-RU.
This commit is contained in:
@@ -2871,7 +2871,11 @@ export default {
|
||||
setDefaultFailed: 'Failed to set default model',
|
||||
builtinCannotEdit: 'Built-in models cannot be edited',
|
||||
builtinCannotDelete: 'Built-in models cannot be deleted',
|
||||
builtinCannotCopy: 'Built-in models cannot be copied',
|
||||
copied: 'Model copied',
|
||||
copyFailed: 'Failed to copy model',
|
||||
},
|
||||
copySuffix: ' Copy',
|
||||
builtinModels: {
|
||||
title: 'Built-in Models',
|
||||
description: 'Built-in models are visible to all tenants. Sensitive information is hidden, and they cannot be edited or deleted.',
|
||||
|
||||
@@ -2866,7 +2866,11 @@ export default {
|
||||
setDefaultFailed: "기본 모델 설정 실패",
|
||||
builtinCannotEdit: "기본 제공 모델은 편집할 수 없습니다",
|
||||
builtinCannotDelete: "기본 제공 모델은 삭제할 수 없습니다",
|
||||
builtinCannotCopy: "기본 제공 모델은 복사할 수 없습니다",
|
||||
copied: "모델이 복사되었습니다",
|
||||
copyFailed: "모델 복사에 실패했습니다",
|
||||
},
|
||||
copySuffix: " 사본",
|
||||
builtinModels: {
|
||||
title: "기본 제공 모델",
|
||||
description: "기본 제공 모델은 모든 테넌트에게 표시됩니다. 민감한 정보는 숨겨지며, 편집하거나 삭제할 수 없습니다.",
|
||||
|
||||
@@ -2629,8 +2629,12 @@ export default {
|
||||
setDefault: 'Установлено по умолчанию',
|
||||
setDefaultFailed: 'Не удалось установить по умолчанию',
|
||||
builtinCannotEdit: 'Встроенные модели нельзя редактировать',
|
||||
builtinCannotDelete: 'Встроенные модели нельзя удалить'
|
||||
builtinCannotDelete: 'Встроенные модели нельзя удалить',
|
||||
builtinCannotCopy: 'Встроенные модели нельзя копировать',
|
||||
copied: 'Модель скопирована',
|
||||
copyFailed: 'Не удалось скопировать модель'
|
||||
},
|
||||
copySuffix: ' копия',
|
||||
builtinModels: {
|
||||
title: 'Встроенные модели',
|
||||
description: 'Встроенные модели видны всем тенантам. Конфиденциальная информация скрыта, их нельзя редактировать или удалять.',
|
||||
|
||||
@@ -2869,7 +2869,11 @@ export default {
|
||||
setDefaultFailed: "设置默认模型失败",
|
||||
builtinCannotEdit: "内置模型不能编辑",
|
||||
builtinCannotDelete: "内置模型不能删除",
|
||||
builtinCannotCopy: "内置模型不能复制",
|
||||
copied: "模型已复制",
|
||||
copyFailed: "复制模型失败",
|
||||
},
|
||||
copySuffix: " 副本",
|
||||
builtinModels: {
|
||||
title: "内置模型",
|
||||
description: "内置模型对所有租户可见,敏感信息会被隐藏,且不可编辑或删除。",
|
||||
|
||||
@@ -520,6 +520,12 @@ const getModelOptions = (type: 'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr',
|
||||
value: `edit-${type}-${model.id}`
|
||||
})
|
||||
|
||||
// 复制选项
|
||||
options.push({
|
||||
content: t('common.copy'),
|
||||
value: `copy-${type}-${model.id}`
|
||||
})
|
||||
|
||||
// 删除选项
|
||||
options.push({
|
||||
content: t('common.delete'),
|
||||
@@ -536,6 +542,8 @@ const handleMenuAction = (data: { value: string }, type: 'chat' | 'embedding' |
|
||||
|
||||
if (value.indexOf('edit-') === 0) {
|
||||
editModel(type, model)
|
||||
} else if (value.indexOf('copy-') === 0) {
|
||||
copyModel(type, model.id)
|
||||
} else if (value.indexOf('delete-') === 0) {
|
||||
// 使用确认对话框进行确认
|
||||
if (confirm(t('modelSettings.confirmDelete'))) {
|
||||
@@ -544,6 +552,48 @@ const handleMenuAction = (data: { value: string }, type: 'chat' | 'embedding' |
|
||||
}
|
||||
}
|
||||
|
||||
// 生成不重复的复制名称:原名 + 复制后缀(若已存在则追加序号)
|
||||
const generateCopyName = (originalName: string): string => {
|
||||
const suffix = t('modelSettings.copySuffix')
|
||||
const existingNames = new Set(allModels.value.map(m => m.name))
|
||||
let candidate = `${originalName}${suffix}`
|
||||
let counter = 2
|
||||
while (existingNames.has(candidate)) {
|
||||
candidate = `${originalName}${suffix} ${counter}`
|
||||
counter += 1
|
||||
}
|
||||
return candidate
|
||||
}
|
||||
|
||||
// 复制模型
|
||||
const copyModel = async (_type: 'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr', modelId: string) => {
|
||||
const source = allModels.value.find(m => m.id === modelId)
|
||||
if (!source) {
|
||||
return
|
||||
}
|
||||
if (source.is_builtin) {
|
||||
MessagePlugin.warning(t('modelSettings.toasts.builtinCannotCopy'))
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const newModel: ModelConfig = {
|
||||
name: generateCopyName(source.name),
|
||||
type: source.type,
|
||||
source: source.source,
|
||||
description: source.description || '',
|
||||
parameters: JSON.parse(JSON.stringify(source.parameters || {}))
|
||||
}
|
||||
|
||||
await createModel(newModel)
|
||||
MessagePlugin.success(t('modelSettings.toasts.copied'))
|
||||
await loadModels()
|
||||
} catch (error: any) {
|
||||
console.error('复制模型失败:', error)
|
||||
MessagePlugin.error(error.message || t('modelSettings.toasts.copyFailed'))
|
||||
}
|
||||
}
|
||||
|
||||
// 获取后端模型类型
|
||||
function getModelType(type: 'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr'): 'KnowledgeQA' | 'Embedding' | 'Rerank' | 'VLLM' | 'ASR' {
|
||||
const typeMap = {
|
||||
|
||||
Reference in New Issue
Block a user