@@ -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
(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(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) => {
// 管理员权限检查:管理员只能编辑,不能进入创作模式
diff --git a/src/views/settings/modelConfig/modelModule/component/editModule.vue b/src/views/settings/modelConfig/modelModule/component/editModule.vue
index 869c83d..f9a6926 100644
--- a/src/views/settings/modelConfig/modelModule/component/editModule.vue
+++ b/src/views/settings/modelConfig/modelModule/component/editModule.vue
@@ -51,7 +51,7 @@
-
+
是
diff --git a/src/views/settings/modelConfig/modelModule/index.vue b/src/views/settings/modelConfig/modelModule/index.vue
index 53797cb..6eef6b4 100644
--- a/src/views/settings/modelConfig/modelModule/index.vue
+++ b/src/views/settings/modelConfig/modelModule/index.vue
@@ -36,9 +36,14 @@
+
+
+ {{ scope.row.isOwner === 0 ? '内置模型' : '用户模型' }}
+
+
- {{ scope.row.isPrivate === 1 ? '本地模型' : '服务商模型' }}
+ {{ scope.row.isPrivate === 1 ? '服务商模型' : '本地模型' }}
@@ -97,12 +102,12 @@
-
-
+
+
- 您选择的是系统模型,需要配置您自己的 API Key。
+ 您选择的是内置模型,需要配置您自己的 API Key。
系统将为您创建一个模型副本并设置为会话模型。
@@ -156,7 +161,7 @@ const state = reactive({
},
});
-// 系统模型 API Key 配置
+// 内置模型 API Key 配置
const apiKeyDialogVisible = ref(false);
const apiKeyFormRef = ref();
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(null);
+const builtInModelToClone = ref(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);