From 220404348e46d8209d6085eb4c474e5041815f33 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Fri, 24 Apr 2026 00:12:03 +0800 Subject: [PATCH] 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. --- frontend/src/i18n/locales/en-US.ts | 4 ++ frontend/src/i18n/locales/ko-KR.ts | 4 ++ frontend/src/i18n/locales/ru-RU.ts | 6 ++- frontend/src/i18n/locales/zh-CN.ts | 4 ++ frontend/src/views/settings/ModelSettings.vue | 50 +++++++++++++++++++ 5 files changed, 67 insertions(+), 1 deletion(-) diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index 9c4823b8..d6e7b6e7 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -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.', diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index 994ed95a..42f78c01 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -2866,7 +2866,11 @@ export default { setDefaultFailed: "기본 모델 설정 실패", builtinCannotEdit: "기본 제공 모델은 편집할 수 없습니다", builtinCannotDelete: "기본 제공 모델은 삭제할 수 없습니다", + builtinCannotCopy: "기본 제공 모델은 복사할 수 없습니다", + copied: "모델이 복사되었습니다", + copyFailed: "모델 복사에 실패했습니다", }, + copySuffix: " 사본", builtinModels: { title: "기본 제공 모델", description: "기본 제공 모델은 모든 테넌트에게 표시됩니다. 민감한 정보는 숨겨지며, 편집하거나 삭제할 수 없습니다.", diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index b5f4f7fc..457df95b 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -2629,8 +2629,12 @@ export default { setDefault: 'Установлено по умолчанию', setDefaultFailed: 'Не удалось установить по умолчанию', builtinCannotEdit: 'Встроенные модели нельзя редактировать', - builtinCannotDelete: 'Встроенные модели нельзя удалить' + builtinCannotDelete: 'Встроенные модели нельзя удалить', + builtinCannotCopy: 'Встроенные модели нельзя копировать', + copied: 'Модель скопирована', + copyFailed: 'Не удалось скопировать модель' }, + copySuffix: ' копия', builtinModels: { title: 'Встроенные модели', description: 'Встроенные модели видны всем тенантам. Конфиденциальная информация скрыта, их нельзя редактировать или удалять.', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index 0e3205b7..79a6861a 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -2869,7 +2869,11 @@ export default { setDefaultFailed: "设置默认模型失败", builtinCannotEdit: "内置模型不能编辑", builtinCannotDelete: "内置模型不能删除", + builtinCannotCopy: "内置模型不能复制", + copied: "模型已复制", + copyFailed: "复制模型失败", }, + copySuffix: " 副本", builtinModels: { title: "内置模型", description: "内置模型对所有租户可见,敏感信息会被隐藏,且不可编辑或删除。", diff --git a/frontend/src/views/settings/ModelSettings.vue b/frontend/src/views/settings/ModelSettings.vue index 408a2dd4..05a439db 100644 --- a/frontend/src/views/settings/ModelSettings.vue +++ b/frontend/src/views/settings/ModelSettings.vue @@ -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 = {