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:
@@ -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