fix(knowledge): 修复语言模型选择后无法回显且提交为空的问题

V2 模型 spec 格式为 provider_id:model_id(冒号分隔),
但 handleLLMSelect 使用斜杠拆分,导致 provider 和 model_name 均为空。
新增 model_spec 字段直接存储完整 spec,抽取 parseModelSpec/buildDisplaySpec
工具函数统一处理 V1/V2 两种格式,消除 3 处重复逻辑。
This commit is contained in:
郭诣 2026-05-02 01:08:09 +08:00
parent f7cf7788a5
commit 86904332bc
4 changed files with 51 additions and 55 deletions

View File

@ -75,7 +75,7 @@
import { ref, reactive, computed } from 'vue'
import { useRouter } from 'vue-router'
import { useDatabaseStore } from '@/stores/database'
import { getKbTypeLabel, getKbTypeIcon, getKbTypeColor } from '@/utils/kb_utils'
import { getKbTypeLabel, getKbTypeIcon, getKbTypeColor, parseModelSpec, buildDisplaySpec } from '@/utils/kb_utils'
import { LeftOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons-vue'
import HeaderComponent from '@/components/HeaderComponent.vue'
import ModelSelectorComponent from '@/components/ModelSelectorComponent.vue'
@ -94,6 +94,7 @@ const editForm = reactive({
name: '',
description: '',
llm_info: {
model_spec: '',
provider: '',
model_name: ''
}
@ -113,6 +114,7 @@ const showEditModal = () => {
// LightRAG LLM
if (database.value.kb_type === 'lightrag') {
const llmInfo = database.value.llm_info || {}
editForm.llm_info.model_spec = llmInfo.model_spec || ''
editForm.llm_info.provider = llmInfo.provider || ''
editForm.llm_info.model_name = llmInfo.model_name || ''
}
@ -131,6 +133,7 @@ const handleEditSubmit = () => {
// LightRAG llm_info
if (database.value.kb_type === 'lightrag') {
updateData.llm_info = {
model_spec: editForm.llm_info.model_spec,
provider: editForm.llm_info.provider,
model_name: editForm.llm_info.model_name
}
@ -145,25 +148,12 @@ const handleEditSubmit = () => {
}
// LLM
const llmModelSpec = computed(() => {
const provider = editForm.llm_info?.provider || ''
const modelName = editForm.llm_info?.model_name || ''
if (provider && modelName) {
return `${provider}/${modelName}`
}
return ''
})
const llmModelSpec = computed(() => buildDisplaySpec(editForm.llm_info))
const handleLLMSelect = (spec) => {
console.log('LLM选择:', spec)
if (typeof spec !== 'string' || !spec) return
const index = spec.indexOf('/')
const provider = index !== -1 ? spec.slice(0, index) : ''
const modelName = index !== -1 ? spec.slice(index + 1) : ''
editForm.llm_info.provider = provider
editForm.llm_info.model_name = modelName
const parsed = parseModelSpec(spec)
if (!parsed) return
Object.assign(editForm.llm_info, parsed)
}
const deleteDatabase = () => {

View File

@ -158,7 +158,7 @@ import { ref, reactive, computed, h, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useDatabaseStore } from '@/stores/database'
import { useUserStore } from '@/stores/user'
import { getKbTypeLabel, getKbTypeColor } from '@/utils/kb_utils'
import { getKbTypeLabel, getKbTypeColor, parseModelSpec, buildDisplaySpec } from '@/utils/kb_utils'
import {
CHUNK_PRESET_OPTIONS,
CHUNK_PRESET_LABEL_MAP,
@ -264,6 +264,7 @@ const editForm = reactive({
auto_generate_questions: false,
chunk_preset_id: 'general',
llm_info: {
model_spec: '',
provider: '',
model_name: ''
},
@ -296,6 +297,7 @@ const showEditModal = () => {
// LightRAG LLM
if (database.value.kb_type === 'lightrag') {
const llmInfo = database.value.llm_info || {}
editForm.llm_info.model_spec = llmInfo.model_spec || ''
editForm.llm_info.provider = llmInfo.provider || ''
editForm.llm_info.model_name = llmInfo.model_name || ''
}
@ -376,6 +378,7 @@ const handleEditSubmit = () => {
// LightRAG llm_info
if (database.value.kb_type === 'lightrag') {
updateData.llm_info = {
model_spec: editForm.llm_info.model_spec,
provider: editForm.llm_info.provider,
model_name: editForm.llm_info.model_name
}
@ -390,25 +393,12 @@ const handleEditSubmit = () => {
}
// LLM
const llmModelSpec = computed(() => {
const provider = editForm.llm_info?.provider || ''
const modelName = editForm.llm_info?.model_name || ''
if (provider && modelName) {
return `${provider}/${modelName}`
}
return ''
})
const llmModelSpec = computed(() => buildDisplaySpec(editForm.llm_info))
const handleLLMSelect = (spec) => {
console.log('LLM选择:', spec)
if (typeof spec !== 'string' || !spec) return
const index = spec.indexOf('/')
const provider = index !== -1 ? spec.slice(0, index) : ''
const modelName = index !== -1 ? spec.slice(index + 1) : ''
editForm.llm_info.provider = provider
editForm.llm_info.model_name = modelName
const parsed = parseModelSpec(spec)
if (!parsed) return
Object.assign(editForm.llm_info, parsed)
}
const deleteDatabase = () => {

View File

@ -26,3 +26,25 @@ export const getKbTypeColor = (type) => {
}
return colors[type] || 'blue'
}
// 解析模型 spec 为 { model_spec, provider, model_name }
// V2 格式: provider_id:model_id冒号分隔
// V1 格式: provider/model_name斜杠分隔
export const parseModelSpec = (spec) => {
if (typeof spec !== 'string' || !spec) return null
const sep = spec.includes(':') ? ':' : '/'
const index = spec.indexOf(sep)
return {
model_spec: spec,
provider: index !== -1 ? spec.slice(0, index) : '',
model_name: index !== -1 ? spec.slice(index + 1) : ''
}
}
// 从 llm_info 构造显示用的 spec 字符串
export const buildDisplaySpec = (llmInfo) => {
if (llmInfo?.model_spec) return llmInfo.model_spec
const provider = llmInfo?.provider || ''
const modelName = llmInfo?.model_name || ''
return provider && modelName ? `${provider}/${modelName}` : ''
}

View File

@ -250,7 +250,7 @@ import ExtensionCardGrid from '@/components/extensions/ExtensionCardGrid.vue'
import InfoCard from '@/components/shared/InfoCard.vue'
import dayjs, { parseToShanghai } from '@/utils/time'
import AiTextarea from '@/components/AiTextarea.vue'
import { getKbTypeLabel, getKbTypeIcon, getKbTypeColor } from '@/utils/kb_utils'
import { getKbTypeLabel, getKbTypeIcon, getKbTypeColor, parseModelSpec, buildDisplaySpec } from '@/utils/kb_utils'
import { CHUNK_PRESET_OPTIONS, getChunkPresetDescription } from '@/utils/chunk_presets'
const route = useRoute()
@ -324,6 +324,7 @@ const createEmptyDatabaseForm = () => ({
chunk_preset_id: 'general',
language: 'Chinese',
llm_info: {
model_spec: '',
provider: '',
model_name: ''
},
@ -338,14 +339,7 @@ const selectedPresetDescription = computed(() =>
getChunkPresetDescription(newDatabase.chunk_preset_id)
)
const llmModelSpec = computed(() => {
const provider = newDatabase.llm_info?.provider || ''
const modelName = newDatabase.llm_info?.model_name || ''
if (provider && modelName) {
return `${provider}/${modelName}`
}
return ''
})
const llmModelSpec = computed(() => buildDisplaySpec(newDatabase.llm_info))
//
const supportedKbTypes = ref({})
@ -427,15 +421,9 @@ const handleKbTypeChange = (type) => {
// LLM
const handleLLMSelect = (spec) => {
console.log('LLM选择:', spec)
if (typeof spec !== 'string' || !spec) return
const index = spec.indexOf('/')
const provider = index !== -1 ? spec.slice(0, index) : ''
const modelName = index !== -1 ? spec.slice(index + 1) : ''
newDatabase.llm_info.provider = provider
newDatabase.llm_info.model_name = modelName
const parsed = parseModelSpec(spec)
if (!parsed) return
Object.assign(newDatabase.llm_info, parsed)
}
//
@ -470,7 +458,13 @@ const buildRequestData = () => {
if (newDatabase.kb_type === 'lightrag') {
requestData.additional_params.language = newDatabase.language || 'English'
if (newDatabase.llm_info.provider && newDatabase.llm_info.model_name) {
if (newDatabase.llm_info.model_spec) {
requestData.llm_info = {
model_spec: newDatabase.llm_info.model_spec,
provider: newDatabase.llm_info.provider,
model_name: newDatabase.llm_info.model_name
}
} else if (newDatabase.llm_info.provider && newDatabase.llm_info.model_name) {
requestData.llm_info = {
provider: newDatabase.llm_info.provider,
model_name: newDatabase.llm_info.model_name