feat(model-editor): enhance model type selection and localization support

- Added a new section for model type selection in ModelEditorDialog.vue, allowing users to choose between different model types with visual indicators.
- Updated the source selection logic to reflect changes in model type and ensure proper state management.
- Refactored related computed properties to utilize the active model type for better clarity and maintainability.
- Enhanced localization files (English, Korean, Russian, Chinese) to include new translations for model type and type label.
- Improved the layout and structure of ModelSettings.vue for better user experience and accessibility.
This commit is contained in:
wizardchen
2026-06-10 20:39:47 +08:00
committed by lyingbug
parent ad27ed134e
commit af08a65821
6 changed files with 273 additions and 118 deletions
+167 -45
View File
@@ -29,6 +29,25 @@
<t-form ref="formRef" :data="formData" :rules="rules" layout="vertical"> <t-form ref="formRef" :data="formData" :rules="rules" layout="vertical">
<section v-if="!isEdit" class="setting-drawer__section">
<h4 class="setting-drawer__section-title">{{ $t('model.editor.sectionType') }}</h4>
<div class="model-type-options" role="radiogroup" :aria-label="$t('model.editor.typeLabel')">
<button
v-for="opt in modelTypeChoices"
:key="opt.value"
type="button"
class="model-type-option"
:class="{ 'is-active': activeModelType === opt.value }"
role="radio"
:aria-checked="activeModelType === opt.value"
@click="selectModelType(opt.value)"
>
<t-icon :name="opt.icon" class="model-type-option__icon" />
<span class="model-type-option__label">{{ opt.label }}</span>
</button>
</div>
</section>
<!-- <!--
Section 1 — 模型来源 + 模型名称(来源直接决定下方字段,所以放一节) Section 1 — 模型来源 + 模型名称(来源直接决定下方字段,所以放一节)
--> -->
@@ -41,18 +60,6 @@
直接把分段控件作为 section 的首个内容呈现,避免「双标题」感。 直接把分段控件作为 section 的首个内容呈现,避免「双标题」感。
--> -->
<div class="source-options" role="radiogroup" :aria-label="$t('model.editor.sourceLabel')"> <div class="source-options" role="radiogroup" :aria-label="$t('model.editor.sourceLabel')">
<button
type="button"
class="source-option"
:class="{ 'is-active': formData.source === 'local', 'is-disabled': ollamaServiceStatus === false || modelType === 'rerank' }"
:disabled="ollamaServiceStatus === false || modelType === 'rerank'"
role="radio"
:aria-checked="formData.source === 'local'"
@click="formData.source = 'local'"
>
<t-icon name="server" class="source-option__icon" />
<span class="source-option__label">{{ $t('model.editor.sourceLocal') }}</span>
</button>
<button <button
type="button" type="button"
class="source-option" class="source-option"
@@ -64,16 +71,28 @@
<t-icon name="cloud" class="source-option__icon" /> <t-icon name="cloud" class="source-option__icon" />
<span class="source-option__label">{{ $t('model.editor.sourceRemote') }}</span> <span class="source-option__label">{{ $t('model.editor.sourceRemote') }}</span>
</button> </button>
<button
type="button"
class="source-option"
:class="{ 'is-active': formData.source === 'local', 'is-disabled': ollamaServiceStatus === false || activeModelType === 'rerank' }"
:disabled="ollamaServiceStatus === false || activeModelType === 'rerank'"
role="radio"
:aria-checked="formData.source === 'local'"
@click="formData.source = 'local'"
>
<t-icon name="server" class="source-option__icon" />
<span class="source-option__label">{{ $t('model.editor.sourceLocal') }}</span>
</button>
</div> </div>
<!-- ReRank模型不支持Ollama的提示信息 --> <!-- ReRank模型不支持Ollama的提示信息 -->
<div v-if="modelType === 'rerank'" class="ollama-unavailable-tip rerank-tip"> <div v-if="activeModelType === 'rerank'" class="ollama-unavailable-tip rerank-tip">
<t-icon name="info-circle-filled" class="tip-icon info" /> <t-icon name="info-circle-filled" class="tip-icon info" />
<span class="tip-text">{{ $t('model.editor.ollamaNotSupportRerank') }}</span> <span class="tip-text">{{ $t('model.editor.ollamaNotSupportRerank') }}</span>
</div> </div>
<!-- Ollama不可用时的提示信息 --> <!-- Ollama不可用时的提示信息 -->
<div v-else-if="shouldShowOllamaUnavailableTip(formData.source, modelType, ollamaServiceStatus)" <div v-else-if="shouldShowOllamaUnavailableTip(formData.source, activeModelType, ollamaServiceStatus)"
class="ollama-unavailable-tip"> class="ollama-unavailable-tip">
<t-icon name="error-circle-filled" class="tip-icon" /> <t-icon name="error-circle-filled" class="tip-icon" />
<span class="tip-text">{{ $t('model.editor.ollamaUnavailable') }}</span> <span class="tip-text">{{ $t('model.editor.ollamaUnavailable') }}</span>
@@ -294,11 +313,11 @@
</template> </template>
<!-- Section 3 — 高级选项(仅在有内容时渲染,避免空 section 出现底部分隔线) --> <!-- Section 3 — 高级选项(仅在有内容时渲染,避免空 section 出现底部分隔线) -->
<section v-if="modelType === 'embedding' || modelType === 'chat'" class="setting-drawer__section"> <section v-if="activeModelType === 'embedding' || activeModelType === 'chat'" class="setting-drawer__section">
<h4 class="setting-drawer__section-title">{{ $t('model.editor.sectionAdvanced') }}</h4> <h4 class="setting-drawer__section-title">{{ $t('model.editor.sectionAdvanced') }}</h4>
<!-- Embedding 专用:维度 --> <!-- Embedding 专用:维度 -->
<div v-if="modelType === 'embedding'" class="form-item"> <div v-if="activeModelType === 'embedding'" class="form-item">
<label class="form-label">{{ $t('model.editor.dimensionLabel') }}</label> <label class="form-label">{{ $t('model.editor.dimensionLabel') }}</label>
<div class="dimension-control"> <div class="dimension-control">
<t-input v-model.number="formData.dimension" type="number" :min="128" :max="4096" <t-input v-model.number="formData.dimension" type="number" :min="128" :max="4096"
@@ -317,7 +336,7 @@
</div> </div>
<!-- Chat: supports vision toggle (VLLM models are inherently multimodal) --> <!-- Chat: supports vision toggle (VLLM models are inherently multimodal) -->
<div v-if="modelType === 'chat'" class="form-item"> <div v-if="activeModelType === 'chat'" class="form-item">
<label class="form-label">{{ $t('model.editor.supportsVisionLabel') }}</label> <label class="form-label">{{ $t('model.editor.supportsVisionLabel') }}</label>
<div class="vision-toggle"> <div class="vision-toggle">
<t-switch v-model="formData.supportsVision" /> <t-switch v-model="formData.supportsVision" />
@@ -407,9 +426,11 @@ interface ModelFormData {
lkeapRegion?: string lkeapRegion?: string
} }
type EditorModelType = 'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr'
interface Props { interface Props {
visible: boolean visible: boolean
modelType: 'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr' modelType: EditorModelType
modelData?: ModelFormData | null modelData?: ModelFormData | null
} }
@@ -423,9 +444,25 @@ const props = withDefaults(defineProps<Props>(), {
const emit = defineEmits<{ const emit = defineEmits<{
'update:visible': [value: boolean] 'update:visible': [value: boolean]
'confirm': [data: ModelFormData] 'confirm': [data: ModelFormData & { modelType?: EditorModelType }]
}>() }>()
const draftModelType = ref<EditorModelType>(props.modelType)
const isEdit = computed(() => !!props.modelData)
const activeModelType = computed(() => (
isEdit.value ? props.modelType : draftModelType.value
))
const modelTypeChoices = computed(() => ([
{ value: 'chat' as const, label: t('modelSettings.typeShort.chat'), icon: 'chat' },
{ value: 'embedding' as const, label: t('modelSettings.typeShort.embedding'), icon: 'chart-bubble' },
{ value: 'rerank' as const, label: t('modelSettings.typeShort.rerank'), icon: 'filter-sort' },
{ value: 'vllm' as const, label: t('modelSettings.typeShort.vllm'), icon: 'image' },
{ value: 'asr' as const, label: t('modelSettings.typeShort.asr'), icon: 'sound' },
]))
// API 返回的 Provider 列表 // API 返回的 Provider 列表
const apiProviderOptions = ref<ModelProviderOption[]>([]) const apiProviderOptions = ref<ModelProviderOption[]>([])
const loadingProviders = ref(false) const loadingProviders = ref(false)
@@ -557,7 +594,7 @@ const fallbackProviderOptions = computed(() => [
const loadProviders = async () => { const loadProviders = async () => {
loadingProviders.value = true loadingProviders.value = true
try { try {
const providers = await listModelProviders(props.modelType) const providers = await listModelProviders(activeModelType.value)
if (providers.length > 0) { if (providers.length > 0) {
apiProviderOptions.value = providers apiProviderOptions.value = providers
} }
@@ -585,7 +622,7 @@ const providerOptions = computed(() => {
} }
// 回退到硬编码值,按 modelTypes 过滤 // 回退到硬编码值,按 modelTypes 过滤
return fallbackProviderOptions.value.filter(p => return fallbackProviderOptions.value.filter(p =>
p.modelTypes.includes(props.modelType) p.modelTypes.includes(activeModelType.value)
) )
}) })
@@ -594,10 +631,8 @@ const dialogVisible = computed({
set: (val) => emit('update:visible', val) set: (val) => emit('update:visible', val)
}) })
const isEdit = computed(() => !!props.modelData)
const showThinkingControlField = computed(() => const showThinkingControlField = computed(() =>
props.modelType === 'chat' && formData.value.source === 'remote', activeModelType.value === 'chat' && formData.value.source === 'remote',
) )
const resolvedThinkingControl = (): ThinkingControlValue => const resolvedThinkingControl = (): ThinkingControlValue =>
@@ -622,7 +657,7 @@ const syncThinkingControlToForm = (force = false) => {
} }
const applyThinkingControlFromModelData = () => { const applyThinkingControlFromModelData = () => {
if (!props.modelData || props.modelType !== 'chat' || formData.value.source !== 'remote') return if (!props.modelData || activeModelType.value !== 'chat' || formData.value.source !== 'remote') return
thinkingControlManual.value = !!props.modelData.thinkingControl thinkingControlManual.value = !!props.modelData.thinkingControl
formData.value.thinkingControl = resolveThinkingControl( formData.value.thinkingControl = resolveThinkingControl(
props.modelData.thinkingControl, props.modelData.thinkingControl,
@@ -652,11 +687,11 @@ const modelTypeIcon = computed(() => {
vllm: 'image', vllm: 'image',
asr: 'sound', asr: 'sound',
} }
return map[props.modelType] || 'setting' return map[activeModelType.value] || 'setting'
}) })
const isLkeapRerank = computed( const isLkeapRerank = computed(
() => props.modelType === 'rerank' && formData.value.provider === 'lkeap', () => activeModelType.value === 'rerank' && formData.value.provider === 'lkeap',
) )
// Credential resource binding for the shared <CredentialResource> component. // Credential resource binding for the shared <CredentialResource> component.
@@ -764,8 +799,8 @@ const goToWeKnoraCloudSettings = async () => {
const formData = ref<ModelFormData>({ const formData = ref<ModelFormData>({
id: '', id: '',
name: '', name: '',
source: 'local', source: 'remote',
provider: 'openai', provider: 'generic',
modelName: '', modelName: '',
displayName: '', displayName: '',
baseUrl: '', baseUrl: '',
@@ -822,18 +857,18 @@ const rules = computed(() => ({
// 获取弹窗描述文字 // 获取弹窗描述文字
const getModalDescription = () => { const getModalDescription = () => {
const key = `model.editor.description.${props.modelType}` as const const key = `model.editor.description.${activeModelType.value}` as const
return t(key) || t('model.editor.description.default') return t(key) || t('model.editor.description.default')
} }
// 获取模型名称占位符 // 获取模型名称占位符
const getModelNamePlaceholder = () => { const getModelNamePlaceholder = () => {
if (props.modelType === 'vllm') { if (activeModelType.value === 'vllm') {
return formData.value.source === 'local' return formData.value.source === 'local'
? t('model.editor.modelNamePlaceholder.localVllm') ? t('model.editor.modelNamePlaceholder.localVllm')
: t('model.editor.modelNamePlaceholder.remoteVllm') : t('model.editor.modelNamePlaceholder.remoteVllm')
} }
if (props.modelType === 'asr') { if (activeModelType.value === 'asr') {
return t('model.editor.modelNamePlaceholder.remoteAsr') return t('model.editor.modelNamePlaceholder.remoteAsr')
} }
return formData.value.source === 'local' return formData.value.source === 'local'
@@ -842,10 +877,10 @@ const getModelNamePlaceholder = () => {
} }
const getBaseUrlPlaceholder = () => { const getBaseUrlPlaceholder = () => {
if (props.modelType === 'vllm') { if (activeModelType.value === 'vllm') {
return t('model.editor.baseUrlPlaceholderVllm') return t('model.editor.baseUrlPlaceholderVllm')
} }
if (props.modelType === 'asr') { if (activeModelType.value === 'asr') {
return t('model.editor.baseUrlPlaceholderAsr') return t('model.editor.baseUrlPlaceholderAsr')
} }
return t('model.editor.baseUrlPlaceholder') return t('model.editor.baseUrlPlaceholder')
@@ -894,6 +929,41 @@ const goToOllamaSettings = async () => {
// 上一次打开时的 modelData id:用来判断切换模型/新增 vs. 同一次新增的连续打开 // 上一次打开时的 modelData id:用来判断切换模型/新增 vs. 同一次新增的连续打开
const lastOpenedModelId = ref<string | null>(null) const lastOpenedModelId = ref<string | null>(null)
const selectModelType = async (type: EditorModelType) => {
if (isEdit.value || draftModelType.value === type) return
draftModelType.value = type
if (type === 'rerank') {
formData.value.source = 'remote'
}
if (type !== 'embedding') {
formData.value.dimension = undefined
dimensionChecked.value = false
dimensionSuccess.value = false
dimensionMessage.value = ''
}
if (type !== 'chat') {
formData.value.supportsVision = false
thinkingControlManual.value = false
}
remoteChecked.value = false
remoteAvailable.value = false
remoteMessage.value = ''
await loadProviders()
const supported = providerOptions.value.some(p => p.value === formData.value.provider)
if (!supported) {
formData.value.provider = 'generic'
formData.value.baseUrl = ''
} else {
handleProviderChange(formData.value.provider)
}
if (showThinkingControlField.value && !isEdit.value) {
thinkingControlManual.value = false
syncThinkingControlToForm(true)
}
}
// 监听 visible 变化,初始化表单 // 监听 visible 变化,初始化表单
watch(() => props.visible, (val) => { watch(() => props.visible, (val) => {
if (val) { if (val) {
@@ -915,6 +985,7 @@ watch(() => props.visible, (val) => {
dimensionMessage.value = '' dimensionMessage.value = ''
const currentId = props.modelData?.id ?? null const currentId = props.modelData?.id ?? null
draftModelType.value = props.modelType
hydratingForm.value = true hydratingForm.value = true
try { try {
@@ -939,7 +1010,7 @@ watch(() => props.visible, (val) => {
lastOpenedModelId.value = currentId lastOpenedModelId.value = currentId
// ReRank 模型强制使用 remote 来源(Ollama 不支持 ReRank) // ReRank 模型强制使用 remote 来源(Ollama 不支持 ReRank)
if (props.modelType === 'rerank') { if (activeModelType.value === 'rerank') {
formData.value.source = 'remote' formData.value.source = 'remote'
} }
@@ -966,7 +1037,7 @@ const resetForm = () => {
formData.value = { formData.value = {
id: generateId(), id: generateId(),
name: '', // 保留字段但不使用,保存时用 modelName name: '', // 保留字段但不使用,保存时用 modelName
source: 'local', source: 'remote',
provider: 'generic', provider: 'generic',
modelName: '', modelName: '',
displayName: '', displayName: '',
@@ -997,11 +1068,11 @@ const handleProviderChange = (value: string) => {
const provider = providerOptions.value.find(opt => opt.value === value) const provider = providerOptions.value.find(opt => opt.value === value)
if (provider && provider.defaultUrls) { if (provider && provider.defaultUrls) {
// 根据当前模型类型获取对应的默认 URL // 根据当前模型类型获取对应的默认 URL
const defaultUrl = provider.defaultUrls[props.modelType] const defaultUrl = provider.defaultUrls[activeModelType.value]
if (defaultUrl) { if (defaultUrl) {
formData.value.baseUrl = defaultUrl formData.value.baseUrl = defaultUrl
} }
if (value === 'lkeap' && props.modelType === 'rerank' && !formData.value.modelName?.trim()) { if (value === 'lkeap' && activeModelType.value === 'rerank' && !formData.value.modelName?.trim()) {
formData.value.modelName = 'lke-reranker-base' formData.value.modelName = 'lke-reranker-base'
} }
// 重置校验状态 // 重置校验状态
@@ -1014,7 +1085,7 @@ const handleProviderChange = (value: string) => {
checkWkcCredentialStatus() checkWkcCredentialStatus()
} }
if (hydratingForm.value) return if (hydratingForm.value) return
if (props.modelType !== 'chat' || formData.value.source !== 'remote') return if (activeModelType.value !== 'chat' || formData.value.source !== 'remote') return
if (!isEdit.value) { if (!isEdit.value) {
thinkingControlManual.value = false thinkingControlManual.value = false
syncThinkingControlToForm(true) syncThinkingControlToForm(true)
@@ -1029,7 +1100,7 @@ watch(
() => [formData.value.source, formData.value.provider, formData.value.modelName] as const, () => [formData.value.source, formData.value.provider, formData.value.modelName] as const,
([source, provider, modelName], [prevSource, prevProvider, prevModelName]) => { ([source, provider, modelName], [prevSource, prevProvider, prevModelName]) => {
if (hydratingForm.value || isEdit.value) return if (hydratingForm.value || isEdit.value) return
if (props.modelType !== 'chat' || source !== 'remote') return if (activeModelType.value !== 'chat' || source !== 'remote') return
if (source === prevSource && provider === prevProvider && modelName === prevModelName) return if (source === prevSource && provider === prevProvider && modelName === prevModelName) return
const providerChanged = provider !== prevProvider const providerChanged = provider !== prevProvider
@@ -1152,7 +1223,7 @@ const checkModelStatus = async () => {
// 检查 Ollama 本地 Embedding 模型维度 // 检查 Ollama 本地 Embedding 模型维度
const checkOllamaDimension = async () => { const checkOllamaDimension = async () => {
if (!formData.value.modelName || formData.value.source !== 'local' || props.modelType !== 'embedding') { if (!formData.value.modelName || formData.value.source !== 'local' || activeModelType.value !== 'embedding') {
return return
} }
@@ -1230,7 +1301,7 @@ const checkRemoteAPI = async () => {
? { modelId: props.modelData.id as string } ? { modelId: props.modelData.id as string }
: {} : {}
switch (props.modelType) { switch (activeModelType.value) {
case 'chat': case 'chat':
// 对话模型(KnowledgeQA) // 对话模型(KnowledgeQA)
result = await checkRemoteModel({ result = await checkRemoteModel({
@@ -1388,7 +1459,10 @@ const handleConfirm = async () => {
formData.value.id = generateId() formData.value.id = generateId()
} }
emit('confirm', { ...formData.value }) emit('confirm', {
...formData.value,
...(isEdit.value ? {} : { modelType: activeModelType.value }),
})
dialogVisible.value = false dialogVisible.value = false
// 保存成功后重置草稿,下次打开新增模型时是空白 // 保存成功后重置草稿,下次打开新增模型时是空白
resetForm() resetForm()
@@ -1419,7 +1493,7 @@ watch(() => formData.value.modelName, async (newValue, oldValue) => {
} }
// 如果是 embedding 模型且选择的是 Ollama 本地模型,且模型名称发生了实际变化 // 如果是 embedding 模型且选择的是 Ollama 本地模型,且模型名称发生了实际变化
if (props.modelType === 'embedding' && if (activeModelType.value === 'embedding' &&
formData.value.source === 'local' && formData.value.source === 'local' &&
newValue !== oldValue && newValue !== oldValue &&
oldValue !== '') { oldValue !== '') {
@@ -1521,7 +1595,7 @@ watch(() => formData.value.source, () => {
!hydratingForm.value !hydratingForm.value
&& !isEdit.value && !isEdit.value
&& formData.value.source === 'remote' && formData.value.source === 'remote'
&& props.modelType === 'chat' && activeModelType.value === 'chat'
) { ) {
thinkingControlManual.value = false thinkingControlManual.value = false
syncThinkingControlToForm(true) syncThinkingControlToForm(true)
@@ -1578,6 +1652,54 @@ const handleCancel = () => {
} }
} }
.model-type-options {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.model-type-option {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 6px 12px;
min-height: 32px;
border: 1px solid var(--td-component-stroke);
border-radius: 8px;
background: var(--td-bg-color-container);
color: var(--td-text-color-secondary);
font-size: 13px;
line-height: 1.4;
cursor: pointer;
transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
&__icon {
font-size: 15px;
flex-shrink: 0;
}
&__label {
white-space: nowrap;
}
&:hover:not(.is-active) {
border-color: var(--td-brand-color-3, var(--td-brand-color));
color: var(--td-text-color-primary);
}
&.is-active {
border-color: var(--td-brand-color);
background: color-mix(in srgb, var(--td-brand-color) 10%, transparent);
color: var(--td-brand-color);
font-weight: 500;
}
&:focus-visible {
outline: 2px solid var(--td-brand-color);
outline-offset: 2px;
}
}
// 模型来源分段:紧凑单行 pill 形 segmented。容器自身是浅底圆角条, // 模型来源分段:紧凑单行 pill 形 segmented。容器自身是浅底圆角条,
// 选中按钮通过实色背景 + 主题色描边浮出,未选中态接近透明,节省纵向空间。 // 选中按钮通过实色背景 + 主题色描边浮出,未选中态接近透明,节省纵向空间。
.source-options { .source-options {
+2
View File
@@ -3378,6 +3378,8 @@ export default {
editor: { editor: {
addTitle: 'Add Model', addTitle: 'Add Model',
editTitle: 'Edit Model', editTitle: 'Edit Model',
sectionType: 'Model Type',
typeLabel: 'Model Type',
sectionSource: 'Source', sectionSource: 'Source',
sectionProvider: 'Provider Settings', sectionProvider: 'Provider Settings',
sectionAdvanced: 'Advanced Options', sectionAdvanced: 'Advanced Options',
+2
View File
@@ -2605,6 +2605,8 @@ export default {
editor: { editor: {
addTitle: "모델 추가", addTitle: "모델 추가",
editTitle: "모델 편집", editTitle: "모델 편집",
sectionType: "모델 유형",
typeLabel: "모델 유형",
sectionSource: "모델 소스", sectionSource: "모델 소스",
sectionProvider: "연결 설정", sectionProvider: "연결 설정",
sectionAdvanced: "고급 옵션", sectionAdvanced: "고급 옵션",
+2
View File
@@ -2322,6 +2322,8 @@ export default {
editor: { editor: {
addTitle: 'Добавить модель', addTitle: 'Добавить модель',
editTitle: 'Редактировать модель', editTitle: 'Редактировать модель',
sectionType: 'Тип модели',
typeLabel: 'Тип модели',
sectionSource: 'Источник', sectionSource: 'Источник',
sectionProvider: 'Настройки провайдера', sectionProvider: 'Настройки провайдера',
sectionAdvanced: 'Дополнительные параметры', sectionAdvanced: 'Дополнительные параметры',
+2
View File
@@ -2595,6 +2595,8 @@ export default {
editor: { editor: {
addTitle: "添加模型", addTitle: "添加模型",
editTitle: "编辑模型", editTitle: "编辑模型",
sectionType: "模型类型",
typeLabel: "模型类型",
sectionSource: "模型来源", sectionSource: "模型来源",
sectionProvider: "接入配置", sectionProvider: "接入配置",
sectionAdvanced: "高级选项", sectionAdvanced: "高级选项",
+98 -73
View File
@@ -1,19 +1,8 @@
<template> <template>
<div class="model-settings"> <div class="model-settings">
<div class="section-header"> <div class="section-header">
<div class="section-header__top" data-guide="settings-models"> <h2>{{ $t('modelSettings.title') }}</h2>
<div class="section-header__text"> <p class="section-description">{{ $t('modelSettings.description') }}</p>
<h2>{{ $t('modelSettings.title') }}</h2>
<p class="section-description">{{ $t('modelSettings.description') }}</p>
</div>
<t-dropdown v-if="authStore.hasRole('admin')" :options="addModelOptions" placement="bottom-right"
@click="(data: any) => openAddDialog(data.value)">
<t-button theme="primary" variant="outline" size="small" data-guide="settings-add-model">
<template #icon><add-icon /></template>
{{ $t('modelSettings.actions.addModel') }}
</t-button>
</t-dropdown>
</div>
<div class="builtin-models-hint" role="note"> <div class="builtin-models-hint" role="note">
<p class="builtin-hint-label">{{ $t('modelSettings.builtinModels.title') }}</p> <p class="builtin-hint-label">{{ $t('modelSettings.builtinModels.title') }}</p>
@@ -26,7 +15,7 @@
</div> </div>
</div> </div>
<t-tabs v-model="activeTypeFilter" class="model-type-tabs"> <t-tabs v-model="activeTypeFilter" class="model-type-tabs" data-guide="settings-models">
<t-tab-panel value="all" :label="`${$t('common.all')}(${allLegacyModels.length})`" /> <t-tab-panel value="all" :label="`${$t('common.all')}(${allLegacyModels.length})`" />
<t-tab-panel value="chat" :label="`${$t('modelSettings.typeShort.chat')}(${countByType('chat')})`" /> <t-tab-panel value="chat" :label="`${$t('modelSettings.typeShort.chat')}(${countByType('chat')})`" />
<t-tab-panel value="embedding" <t-tab-panel value="embedding"
@@ -104,16 +93,26 @@
</p> </p>
</div> </div>
</div> </div>
<button
v-if="authStore.hasRole('admin')"
type="button"
class="model-card model-card--add"
data-guide="settings-add-model"
@click="openAddDialog"
>
<span class="model-card--add__icon" aria-hidden="true">
<add-icon />
</span>
<span class="model-card--add__label">{{ $t('modelSettings.actions.addModel') }}</span>
</button>
</div> </div>
<div v-else-if="!loading" class="empty-state"> <div v-else-if="!loading" class="empty-state">
<t-empty :description="emptyHint"> <t-empty :description="emptyHint">
<t-dropdown v-if="authStore.hasRole('admin')" :options="addModelOptions" placement="bottom" <t-button v-if="authStore.hasRole('admin')" theme="primary" variant="outline" size="small"
@click="(data: any) => openAddDialog(data.value)"> data-guide="settings-add-model" @click="openAddDialog">
<t-button theme="primary" variant="outline" size="small"> <template #icon><add-icon /></template>
<template #icon><add-icon /></template> {{ $t('modelSettings.actions.addModel') }}
{{ $t('modelSettings.actions.addModel') }} </t-button>
</t-button>
</t-dropdown>
</t-empty> </t-empty>
</div> </div>
</t-loading> </t-loading>
@@ -197,15 +196,6 @@ const filteredModels = computed(() => {
const countByType = (type: ModelType) => allLegacyModels.value.filter(m => m._modelType === type).length const countByType = (type: ModelType) => allLegacyModels.value.filter(m => m._modelType === type).length
// "+新增模型" 下拉菜单
const addModelOptions = computed(() => ([
{ content: t('modelSettings.typeShort.chat'), value: 'chat' },
{ content: t('modelSettings.typeShort.embedding'), value: 'embedding' },
{ content: t('modelSettings.typeShort.rerank'), value: 'rerank' },
{ content: t('modelSettings.typeShort.vllm'), value: 'vllm' },
{ content: t('modelSettings.typeShort.asr'), value: 'asr' }
]))
// 类型徽章图标。沿用 TDesign 自带 icon name,避免再引第三方图标包。 // 类型徽章图标。沿用 TDesign 自带 icon name,避免再引第三方图标包。
const typeIcon = (type: ModelType): string => { const typeIcon = (type: ModelType): string => {
const map: Record<ModelType, string> = { const map: Record<ModelType, string> = {
@@ -298,9 +288,9 @@ const loadModels = async () => {
} }
} }
// 打开添加对话框 // 打开添加对话框;类型在抽屉内选择,此处仅按当前 Tab 预填默认值
const openAddDialog = (type: ModelType) => { const openAddDialog = () => {
currentModelType.value = type currentModelType.value = activeTypeFilter.value === 'all' ? 'chat' : activeTypeFilter.value
editingModel.value = null editingModel.value = null
showDialog.value = true showDialog.value = true
} }
@@ -340,6 +330,9 @@ const editModel = (type: ModelType, model: any) => {
// 保存模型 // 保存模型
const handleModelSave = async (modelData: any) => { const handleModelSave = async (modelData: any) => {
const saveType: ModelType = modelData.modelType ?? currentModelType.value
currentModelType.value = saveType
try { try {
if (!modelData.modelName || !modelData.modelName.trim()) { if (!modelData.modelName || !modelData.modelName.trim()) {
MessagePlugin.warning(t('modelSettings.toasts.nameRequired')) MessagePlugin.warning(t('modelSettings.toasts.nameRequired'))
@@ -370,7 +363,7 @@ const handleModelSave = async (modelData: any) => {
} }
} }
if (currentModelType.value === 'embedding') { if (saveType === 'embedding') {
if (!modelData.dimension || modelData.dimension < 128 || modelData.dimension > 4096) { if (!modelData.dimension || modelData.dimension < 128 || modelData.dimension > 4096) {
MessagePlugin.warning(t('modelSettings.toasts.dimensionInvalid')) MessagePlugin.warning(t('modelSettings.toasts.dimensionInvalid'))
return return
@@ -398,11 +391,11 @@ const handleModelSave = async (modelData: any) => {
const appSecretFields: { app_secret?: string } = const appSecretFields: { app_secret?: string } =
!editingModel.value && trimmedAppSecret ? { app_secret: trimmedAppSecret } : {} !editingModel.value && trimmedAppSecret ? { app_secret: trimmedAppSecret } : {}
const extraConfig: Record<string, string> = {} const extraConfig: Record<string, string> = {}
if (modelData.provider === 'lkeap' && currentModelType.value === 'rerank') { if (modelData.provider === 'lkeap' && saveType === 'rerank') {
extraConfig.region = (modelData.lkeapRegion || 'ap-guangzhou').trim() extraConfig.region = (modelData.lkeapRegion || 'ap-guangzhou').trim()
} }
if ( if (
currentModelType.value === 'chat' saveType === 'chat'
&& modelData.source === 'remote' && modelData.source === 'remote'
&& modelData.thinkingControl && modelData.thinkingControl
) { ) {
@@ -415,7 +408,7 @@ const handleModelSave = async (modelData: any) => {
const apiModelData: ModelConfig = { const apiModelData: ModelConfig = {
name: modelData.modelName.trim(), name: modelData.modelName.trim(),
display_name: modelData.displayName?.trim() || '', display_name: modelData.displayName?.trim() || '',
type: getModelType(currentModelType.value), type: getModelType(saveType),
source: modelData.source, source: modelData.source,
description: '', description: '',
parameters: { parameters: {
@@ -425,15 +418,15 @@ const handleModelSave = async (modelData: any) => {
provider: modelData.provider || '', provider: modelData.provider || '',
...extraConfigFields, ...extraConfigFields,
...(Object.keys(customHeadersMap).length > 0 ? { custom_headers: customHeadersMap } : {}), ...(Object.keys(customHeadersMap).length > 0 ? { custom_headers: customHeadersMap } : {}),
...(currentModelType.value === 'embedding' && modelData.dimension ? { ...(saveType === 'embedding' && modelData.dimension ? {
embedding_parameters: { embedding_parameters: {
dimension: modelData.dimension, dimension: modelData.dimension,
truncate_prompt_tokens: 0 truncate_prompt_tokens: 0
} }
} : {}), } : {}),
...(currentModelType.value === 'vllm' ? { ...(saveType === 'vllm' ? {
supports_vision: true supports_vision: true
} : currentModelType.value === 'chat' ? { } : saveType === 'chat' ? {
supports_vision: modelData.supportsVision ?? false supports_vision: modelData.supportsVision ?? false
} : {}) } : {})
} }
@@ -580,10 +573,24 @@ onMounted(() => {
.section-header { .section-header {
margin-bottom: 28px; margin-bottom: 28px;
h2 {
font-size: 20px;
font-weight: 600;
color: var(--td-text-color-primary);
margin: 0 0 8px 0;
}
.section-description {
font-size: 14px;
color: var(--td-text-color-secondary);
margin: 0;
line-height: 1.6;
}
} }
.builtin-models-hint { .builtin-models-hint {
margin-top: 4px; margin-top: 12px;
padding: 10px 12px; padding: 10px 12px;
background: var(--td-bg-color-secondarycontainer); background: var(--td-bg-color-secondarycontainer);
border: 1px solid var(--td-component-stroke); border: 1px solid var(--td-component-stroke);
@@ -609,38 +616,6 @@ onMounted(() => {
font-size: 13px; font-size: 13px;
} }
.section-header__top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
margin-bottom: 8px;
.section-header__text {
flex: 1;
min-width: 0;
}
h2 {
font-size: 20px;
font-weight: 600;
color: var(--td-text-color-primary);
margin: 0 0 8px 0;
}
.section-description {
font-size: 14px;
color: var(--td-text-color-secondary);
margin: 0;
line-height: 1.6;
}
:deep(.t-button) {
flex-shrink: 0;
margin-top: 4px;
}
}
.model-list-loading { .model-list-loading {
min-height: 120px; min-height: 120px;
} }
@@ -679,6 +654,11 @@ onMounted(() => {
display: grid; display: grid;
grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
gap: 12px; gap: 12px;
.model-card--add {
width: 100%;
height: 100%;
}
} }
// 模型卡片 —— 可选类型徽章(仅「全部」Tab)+ 标题 + 一行副标题 // 模型卡片 —— 可选类型徽章(仅「全部」Tab)+ 标题 + 一行副标题
@@ -699,6 +679,51 @@ onMounted(() => {
box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06); box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
} }
&--add {
flex-direction: column;
align-items: center;
justify-content: center;
gap: 8px;
min-height: 68px;
border-style: dashed;
background: transparent;
color: var(--td-text-color-placeholder);
cursor: pointer;
font: inherit;
text-align: center;
&:hover,
&:focus-visible {
color: var(--td-brand-color);
border-color: var(--td-brand-color);
background: color-mix(in srgb, var(--td-brand-color) 6%, transparent);
box-shadow: none;
}
&:focus-visible {
outline: 2px solid var(--td-brand-color);
outline-offset: 2px;
}
&__icon {
display: flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
border-radius: 8px;
background: color-mix(in srgb, var(--td-brand-color) 10%, transparent);
color: var(--td-brand-color);
font-size: 18px;
}
&__label {
font-size: 13px;
font-weight: 500;
line-height: 1.4;
}
}
&--builtin { &--builtin {
background: var(--td-bg-color-secondarycontainer); background: var(--td-bg-color-secondarycontainer);