更新模型选择和设置功能

- 修改模型选择器,调整内置模型的标识逻辑,使用 `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

@@ -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) => {
// 管理员权限检查:管理员只能编辑,不能进入创作模式