From c7152f5d923229855d797ed9e03fbe026fbbe987 Mon Sep 17 00:00:00 2001 From: 2910410219 <2910410219@qq.com> Date: Mon, 11 May 2026 21:06:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=A8=A1=E5=9E=8B=E4=BC=9A?= =?UTF-8?q?=E8=AF=9D=E5=BC=80=E5=85=B3=E5=8A=9F=E8=83=BD=E5=92=8CToken?= =?UTF-8?q?=E6=98=A0=E5=B0=84=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在模型模块中添加更新会话模型状态的API,支持会话模型的管理。 - 更新模型选择器,保存模型的表单数据和响应体,提升用户体验。 - 在编辑模块中新增Token映射字段,增强模型配置的灵活性。 - 优化会话模型开关的逻辑,确保状态切换后能正确更新列表数据。 --- .../modelConfig/modelModule/index.ts | 11 +++ src/views/digitalHuman/creation/index.vue | 36 +++++----- .../modelModule/component/editModule.vue | 71 ++++--------------- .../modelConfig/modelModule/index.vue | 47 ++++++------ 4 files changed, 66 insertions(+), 99 deletions(-) diff --git a/src/api/digitalHuman/modelConfig/modelModule/index.ts b/src/api/digitalHuman/modelConfig/modelModule/index.ts index 2113952..fa7f743 100644 --- a/src/api/digitalHuman/modelConfig/modelModule/index.ts +++ b/src/api/digitalHuman/modelConfig/modelModule/index.ts @@ -217,3 +217,14 @@ export function getModelModuleDetail(id: number | string) { // export function updateModelChatSessionSwitch(data: { id: number | string; chatSessionEnabled: 0 | 1 }) { // return request({ url: '/model-gateway/model/...', method: 'post', data }); // } + +/** + * 更新模型会话开关状态 + */ +export function updateChatModel(data: { id: number | string; chatSessionEnabled: 0 | 1 }) { + return request({ + url: '/model-gateway/model/updateChatModel', + method: 'post', + data, + }); +} diff --git a/src/views/digitalHuman/creation/index.vue b/src/views/digitalHuman/creation/index.vue index bad11ce..f3f9ff8 100644 --- a/src/views/digitalHuman/creation/index.vue +++ b/src/views/digitalHuman/creation/index.vue @@ -742,6 +742,7 @@ const workflowDsl = computed(() => ({ inputSource: n.properties?.inputSource || null, formConfig: n.properties?.formConfig || null, modelConfig: n.properties?.modelConfig || null, + modelResponse: n.properties?.modelResponse || null, outputResult: null, })), edges: flowDsl.value.edges.map((e) => ({ @@ -884,7 +885,12 @@ const handleRemoveSkill = () => { // 处理模型选择确认(只更新临时状态,不保存到节点) const handleModelConfirm = (model: any) => { selectedModel.value = model.modelName; - selectedModelData.value = model; + selectedModelData.value = { + ...model, + // 保存模型的 form 和 responseBody,用于后续保存到节点 + modelFormData: model.form || [], + responseBody: model.responseMapping || model.responseBody || {}, + }; }; // 移除已选择的模型(只更新临时状态) const handleRemoveModel = () => { @@ -1707,35 +1713,29 @@ const applySelected = () => { // 保存选中的模型和模型相关配置 if (selectedModel.value) { - // 获取当前模型的表单字段 - const currentModelFields = currentModelForm.value; - const modelForm: Array = []; - - // 保存模型相关的字段配置和值 - currentModelFields.forEach((fieldItem) => { - const value = dynamicFormValues[fieldItem.field]; - modelForm.push({ - type: fieldItem.type, - field: fieldItem.field, - label: fieldItem.label, - value: value !== undefined && value !== null ? value : fieldItem.default || '', - required: fieldItem.required || false, - }); - }); + // 从 selectedModelData 中获取模型的 form 数据 + const modelFormFromData = selectedModelData.value?.modelFormData || selectedModelData.value?.form || []; // 保存到 modelConfig p.modelConfig = { modelName: selectedModel.value, modelApiKey: dynamicFormValues.modelApiKey || '', - modelForm: modelForm, + modelForm: modelFormFromData, // 使用模型列表数据里的 form }; + // 保存模型的 responseBody 到 modelResponse(与 modelConfig 平级) + const responseBody = selectedModelData.value?.responseBody || selectedModelData.value?.responseMapping || {}; + if (Object.keys(responseBody).length > 0) { + p.modelResponse = responseBody; + } + // 保存模型选择状态 p.selectedModel = selectedModel.value; p.modelData = selectedModelData.value; } else { - // 如果没有选择模型,删除 modelConfig 和模型状态 + // 如果没有选择模型,删除 modelConfig、modelResponse 和模型状态 delete p.modelConfig; + delete p.modelResponse; delete p.selectedModel; delete p.modelData; } diff --git a/src/views/digitalHuman/modelConfig/modelModule/component/editModule.vue b/src/views/digitalHuman/modelConfig/modelModule/component/editModule.vue index 640904d..b2012d5 100644 --- a/src/views/digitalHuman/modelConfig/modelModule/component/editModule.vue +++ b/src/views/digitalHuman/modelConfig/modelModule/component/editModule.vue @@ -145,6 +145,11 @@ + + + + + @@ -220,12 +225,7 @@ = - + {{ field.isMainBody ? '✓ 返回主体' : '设置返回主体' }} 删除 @@ -291,6 +291,7 @@ const state = reactive({ retryQueueMaxSeconds: 60, autoCleanSeconds: 300, remark: '', + tokenMapping: '', }, rules: { modelName: [{ required: true, message: '请输入模型名称', trigger: 'blur' }], @@ -490,7 +491,7 @@ const ensureKeyValueRows = (rows: Array<{ key: string; value: string }>) => (row const ensureResponseMappingRows = (rows: Array<{ key: string; value: string; isMainBody?: boolean }>) => { if (!rows.length) return [{ key: '', value: '', isMainBody: false }]; - return rows.map(row => ({ ...row, isMainBody: row.isMainBody || false })); + return rows.map((row) => ({ ...row, isMainBody: row.isMainBody || false })); }; /** 从 getModel 返回的 data 中取出单条模型对象 */ @@ -539,18 +540,19 @@ const fillFormFromDetailRow = (row: Record) => { retryQueueMaxSeconds: Number(row.retryQueueMaxSeconds ?? 60), autoCleanSeconds: Number(row.autoCleanSeconds ?? 300), remark: String(row.remark || ''), + tokenMapping: String(row.tokenMapping || ''), }; state.headers = ensureKeyValueRows(parseHeaders(String(row.headMsg || ''))); state.formFields = ensureKeyValueRows(parseFormFields(row.form)); // 解析请求映射和响应映射 state.requestMappingFields = ensureKeyValueRows(parseRequestMappingFields(row.requestMapping)); state.responseMappingFields = ensureResponseMappingRows(parseResponseMappingFields(row.responseMapping)); - + // 根据 responseBody 字段设置返回主体标记 (responseBody 是对象 {key: value}) if (row.responseBody && typeof row.responseBody === 'object') { const responseBodyKey = Object.keys(row.responseBody)[0]; if (responseBodyKey) { - const mainBodyIndex = state.responseMappingFields.findIndex(f => f.key === responseBodyKey); + const mainBodyIndex = state.responseMappingFields.findIndex((f) => f.key === responseBodyKey); if (mainBodyIndex !== -1) { state.responseMappingFields[mainBodyIndex].isMainBody = true; state.mainBodyIndex = mainBodyIndex; @@ -615,6 +617,7 @@ const openDialog = async (type: string, row?: Record) => { retryQueueMaxSeconds: 60, autoCleanSeconds: 300, remark: '', + tokenMapping: '', }; state.headers = [{ key: '', value: '' }]; state.formFields = [{ key: '', value: '' }]; @@ -648,7 +651,7 @@ const onSubmit = () => { const requestMapping = fieldsToObject(state.requestMappingFields); const responseMapping = fieldsToObject(state.responseMappingFields); // 获取被设置为返回主体的字段 {key: value} - const responseBodyField = state.responseMappingFields.find(f => f.isMainBody); + const responseBodyField = state.responseMappingFields.find((f) => f.isMainBody); const responseBody = responseBodyField ? { [responseBodyField.key.trim()]: responseBodyField.value } : {}; const submitData = { modelName: state.ruleForm.modelName, @@ -672,6 +675,7 @@ const onSubmit = () => { retryQueueMaxSeconds: state.ruleForm.retryQueueMaxSeconds, autoCleanSeconds: state.ruleForm.autoCleanSeconds, remark: state.ruleForm.remark || '', + tokenMapping: state.ruleForm.tokenMapping || '', }; if (state.dialog.type === 'edit') { @@ -743,50 +747,3 @@ defineExpose({ color: #606266; } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/views/digitalHuman/modelConfig/modelModule/index.vue b/src/views/digitalHuman/modelConfig/modelModule/index.vue index 215510f..733d9cf 100644 --- a/src/views/digitalHuman/modelConfig/modelModule/index.vue +++ b/src/views/digitalHuman/modelConfig/modelModule/index.vue @@ -32,23 +32,13 @@ - + - - - @@ -94,6 +84,7 @@ import { getModelTypeList, deleteModelModule, normalizeModelTypeOptions, + updateChatModel, } from '/@/api/digitalHuman/modelConfig/modelModule/index'; const EditModule = defineAsyncComponent(() => import('/@/views/digitalHuman/modelConfig/modelModule/component/editModule.vue')); @@ -113,14 +104,22 @@ const state = reactive({ }, }); -/** 列表行与会话开关接口约定字段 chatSessionEnabled(0/1);接口未就绪前占位 */ -const chatSessionSwitchOn = (row: { chatSessionEnabled?: number }) => Number(row.chatSessionEnabled) === 1; - -const onChatSessionSwitchRequest = (_row: { id?: number | string }) => { - return new Promise((resolve) => { - ElMessage.info('会话开关接口接入后即可生效'); - resolve(false); - }); +// 会话模型开关切换 +const onChatModelSwitchRequest = async (row: { id?: number | string; isChatModel?: number }) => { + try { + const newStatus = Number(row.isChatModel) === 1 ? 0 : 1; + await updateChatModel({ + id: row.id!, + chatSessionEnabled: newStatus as 0 | 1, + }); + ElMessage.success(newStatus === 1 ? '已设置为会话模型' : '已取消会话模型'); + // 重新获取列表数据 + await getTableData(); + return true; + } catch { + // 接口错误由 request 全局提示后端 message + return false; + } }; const resolveModelTypeLabel = (modelsType: number | string | undefined | null) => {