feat: 增强模型配置与创建表单功能
- 在 NodeLibraryFormItem 和 WorkflowItem 接口中添加了新的字段,如 value、options、expand 和 outputParams,以支持更复杂的表单配置。 - 新增 getOperatorList 函数以获取服务商列表,并在 editModule.vue 中集成了运营商选择功能。 - 更新了模型创建和编辑逻辑,支持 tokenConfig 的 JSON 格式配置,确保更灵活的模型设置。 - 优化了文件上传处理,增加了上传状态管理,提升用户体验。
This commit is contained in:
@@ -110,6 +110,9 @@ interface ModelItem {
|
||||
isPrivate?: number;
|
||||
isChatModel?: number;
|
||||
headMsg?: string;
|
||||
operatorName?: string;
|
||||
responseBody?: Record<string, unknown>;
|
||||
tokenConfig?: Record<string, unknown> | string;
|
||||
form?: any;
|
||||
requestMapping?: any;
|
||||
responseMapping?: any;
|
||||
@@ -150,8 +153,8 @@ const modelList = ref<ModelItem[]>([]);
|
||||
const loading = ref(false);
|
||||
const selectedModel = ref<ModelItem | null>(null);
|
||||
const editModuleRef = ref();
|
||||
const isSuperAdmin = ref(false); // 鏄惁涓虹鐞嗗憳
|
||||
const modelTypes = ref<Array<{ id: number | string; label: string }>>([]); // 妯″瀷绫诲瀷鍒楄〃
|
||||
const isSuperAdmin = ref(false);
|
||||
const modelTypes = ref<Array<{ id: number | string; label: string }>>([]);
|
||||
|
||||
// 内置模型 API Key 配置
|
||||
const apiKeyDialogVisible = ref(false);
|
||||
@@ -194,6 +197,15 @@ watch(visible, (val) => {
|
||||
}
|
||||
});
|
||||
|
||||
watch(
|
||||
() => props.modelType,
|
||||
() => {
|
||||
if (!visible.value) return;
|
||||
pagination.pageNum = 1;
|
||||
fetchModelList();
|
||||
}
|
||||
);
|
||||
|
||||
const getModelTypeName = (type: number) => {
|
||||
const typeMap: Record<number, string> = {
|
||||
1: '推理模型',
|
||||
@@ -210,14 +222,13 @@ const fetchModelList = async () => {
|
||||
pageNum: pagination.pageNum,
|
||||
pageSize: pagination.pageSize,
|
||||
modelName: searchParams.modelName || undefined,
|
||||
modelType: props.modelType, // 使用传入的 modelType
|
||||
modelType: props.modelType,
|
||||
enabled: 1,
|
||||
};
|
||||
const res: any = await getModelModuleList(params);
|
||||
modelList.value = res.data?.list || [];
|
||||
pagination.total = res.data?.total || 0;
|
||||
} catch {
|
||||
// 接口错误由 request 全局提示后端 message
|
||||
modelList.value = [];
|
||||
pagination.total = 0;
|
||||
} finally {
|
||||
@@ -235,21 +246,17 @@ const handlePageChange = () => {
|
||||
};
|
||||
|
||||
const handleSelectModel = (model: ModelItem) => {
|
||||
// 如果是管理员,直接选中任何模型,不需要配置 API Key
|
||||
if (isSuperAdmin.value) {
|
||||
selectedModel.value = model;
|
||||
return;
|
||||
}
|
||||
|
||||
// 非管理员:判断是否是内置模型(isOwner === 0 表示管理员创建的内置模型)
|
||||
if (model.isOwner === 0) {
|
||||
// 内置模型,需要用户配置 API Key 创建副本
|
||||
builtInModelToClone.value = model;
|
||||
apiKeyForm.modelName = model.modelName;
|
||||
apiKeyForm.apiKey = '';
|
||||
apiKeyDialogVisible.value = true;
|
||||
} else {
|
||||
// 用户模型,直接选中
|
||||
selectedModel.value = model;
|
||||
}
|
||||
};
|
||||
@@ -262,22 +269,22 @@ const handleCreatePrivateModel = async () => {
|
||||
|
||||
creatingModel.value = true;
|
||||
|
||||
// 基于内置模型创建新模型(继承原模型的所有配置,只替换 apiKey)
|
||||
const builtInModel = builtInModelToClone.value;
|
||||
const createParams = {
|
||||
modelName: apiKeyForm.modelName,
|
||||
modelType: builtInModel.modelType,
|
||||
operatorName: builtInModel.operatorName || '',
|
||||
baseUrl: builtInModel.baseUrl,
|
||||
httpMethod: builtInModel.httpMethod || 'POST',
|
||||
headMsg: builtInModel.headMsg || '',
|
||||
isPrivate: builtInModel.isPrivate ?? 1, // 继承原模型的公有/私有属性
|
||||
isPrivate: builtInModel.isPrivate ?? 1,
|
||||
enabled: builtInModel.enabled ?? 1,
|
||||
isChatModel: builtInModel.isChatModel || 0,
|
||||
apiKey: apiKeyForm.apiKey, // 使用用户输入的新 API Key
|
||||
apiKey: apiKeyForm.apiKey,
|
||||
form: builtInModel.form || {},
|
||||
requestMapping: builtInModel.requestMapping || {},
|
||||
responseMapping: builtInModel.responseMapping || {},
|
||||
responseBody: builtInModel.responseBody || {}, // 杩斿洖涓讳綋瀛楁
|
||||
responseBody: builtInModel.responseBody || {},
|
||||
maxConcurrency: builtInModel.maxConcurrency || 10,
|
||||
queueLimit: builtInModel.queueLimit || 100,
|
||||
timeoutSeconds: builtInModel.timeoutSeconds || 30,
|
||||
@@ -286,20 +293,15 @@ const handleCreatePrivateModel = async () => {
|
||||
retryQueueMaxSeconds: builtInModel.retryQueueMaxSeconds || 60,
|
||||
autoCleanSeconds: builtInModel.autoCleanSeconds || 300,
|
||||
remark: builtInModel.remark || '',
|
||||
tokenMapping: builtInModel.tokenMapping || '', // Token鏄犲皠瀛楁
|
||||
tokenMapping: builtInModel.tokenMapping || '',
|
||||
tokenConfig: builtInModel.tokenConfig || {},
|
||||
};
|
||||
|
||||
const res: any = await addModelModule(createParams);
|
||||
|
||||
ElMessage.success('模型创建成功');
|
||||
|
||||
// 关闭对话框
|
||||
apiKeyDialogVisible.value = false;
|
||||
|
||||
// 刷新列表
|
||||
await fetchModelList();
|
||||
|
||||
// 选中新创建的模型
|
||||
const newModelId = res.data?.id || res.data;
|
||||
if (newModelId) {
|
||||
const newModel = modelList.value.find((m) => m.id === String(newModelId));
|
||||
@@ -338,7 +340,6 @@ const handleClose = () => {
|
||||
builtInModelToClone.value = null;
|
||||
};
|
||||
|
||||
// 鍔犺浇妯″瀷绫诲瀷鍒楄〃
|
||||
const loadModelTypes = async () => {
|
||||
try {
|
||||
const res: any = await getModelTypeList();
|
||||
@@ -346,7 +347,7 @@ const loadModelTypes = async () => {
|
||||
modelTypes.value = normalizeModelTypeOptions(res);
|
||||
}
|
||||
} catch {
|
||||
// 鎺ュ彛閿欒鐢?request 鍏ㄥ眬鎻愮ず鍚庣 message
|
||||
// 接口错误由 request 全局提示后端 message
|
||||
}
|
||||
};
|
||||
onMounted(() => {
|
||||
|
||||
Reference in New Issue
Block a user