更新模型选择和设置功能

- 修改模型选择器,调整内置模型的标识逻辑,使用 `isOwner` 属性替代 `apiKey` 判断。
- 新增内置模型 API Key 输入弹窗,支持用户为内置模型配置 API Key 并创建模型副本。
- 更新模型配置页面,优化内置模型的 API Key 配置逻辑,确保用户体验流畅。
This commit is contained in:
2026-05-14 11:36:41 +08:00
parent 812b11bb68
commit caa5cc71c7
4 changed files with 176 additions and 63 deletions

View File

@@ -19,13 +19,13 @@
v-for="model in modelList"
:key="model.id"
class="model-card"
:class="{ selected: selectedModel?.id === model.id, 'builtin-model': !model.apiKey }"
:class="{ selected: selectedModel?.id === model.id }"
@click="handleSelectModel(model)"
>
<div class="model-card-header">
<div class="model-type">{{ getModelTypeName(model.modelType) }}</div>
<div class="model-badges">
<el-tag v-if="!model.apiKey" type="warning" size="small">内置模型</el-tag>
<el-tag v-if="model.isOwner === 0" type="warning" size="small">内置模型</el-tag>
<el-icon v-if="selectedModel?.id === model.id" class="check-icon" color="#67c23a"><CircleCheck /></el-icon>
</div>
</div>
@@ -165,7 +165,7 @@ const apiKeyRules: FormRules = {
apiKey: [{ required: true, message: '请输入 API Key', trigger: 'blur' }],
};
const creatingModel = ref(false);
const systemModelToClone = ref<ModelItem | null>(null);
const builtInModelToClone = ref<ModelItem | null>(null);
// 检查是否为管理员
const checkAdminStatus = async () => {
@@ -240,10 +240,10 @@ const handleSelectModel = (model: ModelItem) => {
return;
}
// 非管理员:判断是否是内置模型(apiKey 为空
if (!model.apiKey) {
// 内置模型,需要用户配置 API Key
systemModelToClone.value = model;
// 非管理员:判断是否是内置模型(isOwner === 0 表示管理员创建的内置模型
if (model.isOwner === 0) {
// 内置模型,需要用户配置 API Key 创建副本
builtInModelToClone.value = model;
apiKeyForm.modelName = model.modelName;
apiKeyForm.apiKey = '';
apiKeyDialogVisible.value = true;
@@ -254,7 +254,7 @@ const handleSelectModel = (model: ModelItem) => {
};
const handleCreatePrivateModel = async () => {
if (!apiKeyFormRef.value || !systemModelToClone.value) return;
if (!apiKeyFormRef.value || !builtInModelToClone.value) return;
try {
await apiKeyFormRef.value.validate();
@@ -262,30 +262,30 @@ const handleCreatePrivateModel = async () => {
creatingModel.value = true;
// 基于内置模型创建新模型(继承原模型的所有配置,只替换 apiKey
const systemModel = systemModelToClone.value;
const builtInModel = builtInModelToClone.value;
const createParams = {
modelName: apiKeyForm.modelName,
modelType: systemModel.modelType,
baseUrl: systemModel.baseUrl,
httpMethod: systemModel.httpMethod || 'POST',
headMsg: systemModel.headMsg || '',
isPrivate: systemModel.isPrivate ?? 1, // 继承原模型的公有/私有属性
enabled: systemModel.enabled ?? 1,
isChatModel: systemModel.isChatModel || 0,
modelType: builtInModel.modelType,
baseUrl: builtInModel.baseUrl,
httpMethod: builtInModel.httpMethod || 'POST',
headMsg: builtInModel.headMsg || '',
isPrivate: builtInModel.isPrivate ?? 1, // 继承原模型的公有/私有属性
enabled: builtInModel.enabled ?? 1,
isChatModel: builtInModel.isChatModel || 0,
apiKey: apiKeyForm.apiKey, // 使用用户输入的新 API Key
form: systemModel.form || {},
requestMapping: systemModel.requestMapping || {},
responseMapping: systemModel.responseMapping || {},
responseBody: systemModel.responseBody || {}, // 杩斿洖涓讳綋瀛楁
maxConcurrency: systemModel.maxConcurrency || 10,
queueLimit: systemModel.queueLimit || 100,
timeoutSeconds: systemModel.timeoutSeconds || 30,
expectedSeconds: systemModel.expectedSeconds || 15,
retryTimes: systemModel.retryTimes || 3,
retryQueueMaxSeconds: systemModel.retryQueueMaxSeconds || 60,
autoCleanSeconds: systemModel.autoCleanSeconds || 300,
remark: systemModel.remark || '',
tokenMapping: systemModel.tokenMapping || '', // Token鏄犲皠瀛楁
form: builtInModel.form || {},
requestMapping: builtInModel.requestMapping || {},
responseMapping: builtInModel.responseMapping || {},
responseBody: builtInModel.responseBody || {}, // 杩斿洖涓讳綋瀛楁
maxConcurrency: builtInModel.maxConcurrency || 10,
queueLimit: builtInModel.queueLimit || 100,
timeoutSeconds: builtInModel.timeoutSeconds || 30,
expectedSeconds: builtInModel.expectedSeconds || 15,
retryTimes: builtInModel.retryTimes || 3,
retryQueueMaxSeconds: builtInModel.retryQueueMaxSeconds || 60,
autoCleanSeconds: builtInModel.autoCleanSeconds || 300,
remark: builtInModel.remark || '',
tokenMapping: builtInModel.tokenMapping || '', // Token鏄犲皠瀛楁
};
const res: any = await addModelModule(createParams);
@@ -334,7 +334,7 @@ const handleClose = () => {
visible.value = false;
selectedModel.value = null;
apiKeyDialogVisible.value = false;
systemModelToClone.value = null;
builtInModelToClone.value = null;
};
// 鍔犺浇妯″瀷绫诲瀷鍒楄〃

View File

@@ -552,6 +552,30 @@
</template>
</el-dialog>
<!-- 内置对话模型 API Key 输入弹窗 -->
<el-dialog v-model="chatModelApiKeyDialogVisible" title="配置内置模型" width="500px" :close-on-click-modal="false" append-to-body>
<el-alert type="info" :closable="false" style="margin-bottom: 16px">
<template #title>
<div style="line-height: 1.6">
您选择的是内置模型,需要配置您自己的 API Key。<br />
系统将为您创建一个模型副本并设置为会话模型。
</div>
</template>
</el-alert>
<el-form :model="chatModelApiKeyForm" :rules="chatModelApiKeyRules" ref="chatModelApiKeyFormRef" label-width="100px">
<el-form-item label="模型名称" prop="modelName">
<el-input v-model="chatModelApiKeyForm.modelName" placeholder="请输入模型名称" />
</el-form-item>
<el-form-item label="API Key" prop="apiKey">
<el-input v-model="chatModelApiKeyForm.apiKey" type="password" show-password placeholder="请输入您的 API Key" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="chatModelApiKeyDialogVisible = false">取消</el-button>
<el-button type="primary" @click="handleCreateChatModelFromBuiltIn" :loading="creatingChatModel">确定</el-button>
</template>
</el-dialog>
<!-- 预览弹窗 -->
<el-dialog v-model="previewDialogVisible" title="预览" width="95%" top="2vh" :close-on-click-modal="false" destroy-on-close>
<div class="preview-container">
@@ -591,7 +615,7 @@ import {
type ExecuteFlowParams,
} from '/@/api/settings/creation';
import { uploadFile } from '/@/api/common/upload';
import { getModelModuleList, updateChatModel, getIsChatModel } from '/@/api/settings/modelConfig/modelModule';
import { getModelModuleList, updateChatModel, getIsChatModel, addModelModule } from '/@/api/settings/modelConfig/modelModule';
import { checkIsSuperAdmin } from '/@/api/system/user';
type NodeType = 'date' | 'contentType' | 'theme' | 'title' | 'html' | 'image';
@@ -677,6 +701,19 @@ const chatModelPagination = reactive({
pageSize: 10,
total: 0,
});
// 内置对话模型 API Key 配置
const chatModelApiKeyDialogVisible = ref(false);
const chatModelApiKeyFormRef = ref<any>(null);
const chatModelApiKeyForm = reactive({
modelName: '',
apiKey: '',
});
const chatModelApiKeyRules = {
modelName: [{ required: true, message: '请输入模型名称', trigger: 'blur' }],
apiKey: [{ required: true, message: '请输入 API Key', trigger: 'blur' }],
};
const creatingChatModel = ref(false);
const builtInChatModelToClone = ref<any>(null);
const filteredChatModels = computed(() => {
return chatModelList.value;
});
@@ -1043,6 +1080,17 @@ const handleChatModelSearch = () => {
const handleSetChatModel = async () => {
if (!selectedChatModel.value) return;
// 判断是否是内置模型isOwner === 0 表示管理员创建的内置模型)
if (selectedChatModel.value.isOwner === 0) {
// 内置模型,需要用户配置 API Key 创建副本
builtInChatModelToClone.value = selectedChatModel.value;
chatModelApiKeyForm.modelName = selectedChatModel.value.modelName;
chatModelApiKeyForm.apiKey = '';
chatModelApiKeyDialogVisible.value = true;
return;
}
// 用户模型,直接设置为对话模型
settingChatModel.value = true;
try {
await updateChatModel({
@@ -1058,6 +1106,63 @@ const handleSetChatModel = async () => {
settingChatModel.value = false;
}
};
// 创建内置对话模型副本并设置为会话模型
const handleCreateChatModelFromBuiltIn = async () => {
if (!chatModelApiKeyFormRef.value || !builtInChatModelToClone.value) return;
try {
await chatModelApiKeyFormRef.value.validate();
creatingChatModel.value = true;
// 基于内置模型创建新模型(继承原模型的所有配置,只替换 apiKey
const builtInModel = builtInChatModelToClone.value;
const createParams = {
modelName: chatModelApiKeyForm.modelName,
modelType: builtInModel.modelType,
baseUrl: builtInModel.baseUrl,
httpMethod: builtInModel.httpMethod || 'POST',
headMsg: builtInModel.headMsg || '',
isPrivate: builtInModel.isPrivate ?? 1,
enabled: builtInModel.enabled ?? 1,
isChatModel: 1, // 设置为会话模型
apiKey: chatModelApiKeyForm.apiKey,
form: builtInModel.form || {},
requestMapping: builtInModel.requestMapping || {},
responseMapping: builtInModel.responseMapping || {},
responseBody: builtInModel.responseBody || {},
tokenMapping: builtInModel.tokenMapping || '',
prompt: builtInModel.prompt || '',
maxConcurrency: builtInModel.maxConcurrency || 10,
queueLimit: builtInModel.queueLimit || 100,
timeoutSeconds: builtInModel.timeoutSeconds || 30,
expectedSeconds: builtInModel.expectedSeconds || 15,
retryTimes: builtInModel.retryTimes || 3,
retryQueueMaxSeconds: builtInModel.retryQueueMaxSeconds || 60,
autoCleanSeconds: builtInModel.autoCleanSeconds || 300,
remark: builtInModel.remark || '',
};
await addModelModule(createParams);
ElMessage.success('模型创建成功并已设置为会话模型');
// 关闭对话框
chatModelApiKeyDialogVisible.value = false;
showChatModelSelector.value = false;
// 清空表单
chatModelApiKeyForm.modelName = '';
chatModelApiKeyForm.apiKey = '';
builtInChatModelToClone.value = null;
} catch (error: any) {
if (error !== 'cancel') {
ElMessage.error(error?.message || '创建模型失败');
}
} finally {
creatingChatModel.value = false;
}
};
// 使用工作流
const useWorkflow = async (workflow: WorkflowItem) => {
// 管理员权限检查:管理员只能编辑,不能进入创作模式

View File

@@ -51,7 +51,7 @@
<el-input v-model="state.ruleForm.apiKey" type="password" show-password placeholder="请输入 API 密钥字符串" clearable></el-input>
</el-form-item>
</el-col>
<el-col v-if="!props.isSuperAdmin" :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
<el-col v-if="!props.isSuperAdmin && state.dialog.type === 'add'" :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
<el-form-item label="是否对话模型" prop="isChatModel">
<el-radio-group v-model="state.ruleForm.isChatModel">
<el-radio :label="1"></el-radio>

View File

@@ -36,9 +36,14 @@
</template>
</el-table-column>
<!-- <el-table-column prop="baseUrl" label="模型服务地址" show-overflow-tooltip width="200"></el-table-column> -->
<el-table-column prop="isOwner" label="模型归属" width="100">
<template #default="scope">
<el-tag :type="scope.row.isOwner === 0 ? 'warning' : 'success'">{{ scope.row.isOwner === 0 ? '内置模型' : '用户模型' }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="isPrivate" label="访问类型" width="100">
<template #default="scope">
<el-tag :type="scope.row.isPrivate === 1 ? 'primary' : 'info'">{{ scope.row.isPrivate === 1 ? '本地模型' : '服务商模型' }}</el-tag>
<el-tag :type="scope.row.isPrivate === 1 ? 'primary' : 'info'">{{ scope.row.isPrivate === 1 ? '服务商模型' : '本地模型' }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="httpMethod" label="请求方式" width="100"></el-table-column>
@@ -97,12 +102,12 @@
</el-card>
<EditModule ref="editModuleRef" :model-types="state.modelTypes" :is-super-admin="isSuperAdmin" @refresh="getTableData()" />
<!-- 系统模型 API Key 输入弹窗 -->
<el-dialog v-model="apiKeyDialogVisible" title="配置系统模型" width="500px" :close-on-click-modal="false">
<!-- 内置模型 API Key 输入弹窗 -->
<el-dialog v-model="apiKeyDialogVisible" title="配置内置模型" width="500px" :close-on-click-modal="false">
<el-alert type="info" :closable="false" style="margin-bottom: 16px">
<template #title>
<div style="line-height: 1.6">
您选择的是系统模型需要配置您自己的 API Key<br />
您选择的是内置模型需要配置您自己的 API Key<br />
系统将为您创建一个模型副本并设置为会话模型
</div>
</template>
@@ -156,7 +161,7 @@ const state = reactive({
},
});
// 系统模型 API Key 配置
// 内置模型 API Key 配置
const apiKeyDialogVisible = ref(false);
const apiKeyFormRef = ref<FormInstance>();
const apiKeyForm = reactive({
@@ -168,7 +173,7 @@ const apiKeyRules: FormRules = {
apiKey: [{ required: true, message: '请输入 API Key', trigger: 'blur' }],
};
const creatingModel = ref(false);
const systemModelToClone = ref<any>(null);
const builtInModelToClone = ref<any>(null);
// 检查是否为管理员
const checkAdminStatus = async () => {
@@ -192,15 +197,15 @@ const isInferenceModel = (modelType: number | string | undefined | null) => {
// 设置为会话模型
const onSetChatModel = async (row: any) => {
// 判断是否是系统模型(tenantId === 1
if (row.tenantId === 1) {
// 系统模型,需要用户配置 API Key
systemModelToClone.value = row;
// 判断是否是内置模型(isOwner === 0 表示管理员创建的内置模型
if (row.isOwner === 0) {
// 内置模型,需要用户配置 API Key 创建副本
builtInModelToClone.value = row;
apiKeyForm.modelName = row.modelName;
apiKeyForm.apiKey = '';
apiKeyDialogVisible.value = true;
} else {
// 非系统模型,直接设置为会话模型
// 用户自己的模型,直接设置为会话模型
try {
await updateChatModel({
id: row.id!,
@@ -216,36 +221,39 @@ const onSetChatModel = async (row: any) => {
// 创建私有模型并设置为会话模型
const handleCreatePrivateModelAndSetChat = async () => {
if (!apiKeyFormRef.value || !systemModelToClone.value) return;
if (!apiKeyFormRef.value || !builtInModelToClone.value) return;
try {
await apiKeyFormRef.value.validate();
creatingModel.value = true;
// 基于系统模型创建新模型(继承原模型的所有配置,只替换 apiKey
const systemModel = systemModelToClone.value;
// 基于内置模型创建新模型(继承原模型的所有配置,只替换 apiKey
const builtInModel = builtInModelToClone.value;
const createParams = {
modelName: apiKeyForm.modelName,
modelType: systemModel.modelType,
baseUrl: systemModel.baseUrl,
httpMethod: systemModel.httpMethod || 'POST',
headMsg: systemModel.headMsg || '',
isPrivate: systemModel.isPrivate ?? 1,
enabled: systemModel.enabled ?? 1,
modelType: builtInModel.modelType,
baseUrl: builtInModel.baseUrl,
httpMethod: builtInModel.httpMethod || 'POST',
headMsg: builtInModel.headMsg || '',
isPrivate: builtInModel.isPrivate ?? 1,
enabled: builtInModel.enabled ?? 1,
isChatModel: 1, // 设置为会话模型
apiKey: apiKeyForm.apiKey,
form: systemModel.form || [],
requestMapping: systemModel.requestMapping || {},
responseMapping: systemModel.responseMapping || {},
maxConcurrency: systemModel.maxConcurrency || 10,
queueLimit: systemModel.queueLimit || 100,
timeoutSeconds: systemModel.timeoutSeconds || 30,
expectedSeconds: systemModel.expectedSeconds || 15,
retryTimes: systemModel.retryTimes || 3,
retryQueueMaxSeconds: systemModel.retryQueueMaxSeconds || 60,
autoCleanSeconds: systemModel.autoCleanSeconds || 300,
remark: systemModel.remark || '',
form: builtInModel.form || {},
requestMapping: builtInModel.requestMapping || {},
responseMapping: builtInModel.responseMapping || {},
responseBody: builtInModel.responseBody || {},
tokenMapping: builtInModel.tokenMapping || '',
prompt: builtInModel.prompt || '',
maxConcurrency: builtInModel.maxConcurrency || 10,
queueLimit: builtInModel.queueLimit || 100,
timeoutSeconds: builtInModel.timeoutSeconds || 30,
expectedSeconds: builtInModel.expectedSeconds || 15,
retryTimes: builtInModel.retryTimes || 3,
retryQueueMaxSeconds: builtInModel.retryQueueMaxSeconds || 60,
autoCleanSeconds: builtInModel.autoCleanSeconds || 300,
remark: builtInModel.remark || '',
};
await addModelModule(createParams);