Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

feat(frontend): add copy action for model cards in settings

wizardchen220404348e46
diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts
index 9c4823b86..d6e7b6e7e 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 994ed95a7..42f78c017 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 b5f4f7fc2..457df95be 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 0e3205b72..79a6861aa 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 408a2dd46..05a439db3 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 = {