- 支持配置类型注册表机制(basic、zhisuan) - 配置列表展示(生效中/未生效状态区分) - 新增/编辑配置表单,支持动态字段渲染 - 生效中配置不可编辑/删除限制 - 配置类型创建后不可修改 - 密钥掩码显示与显示/隐藏切换 - 操作二次确认弹窗(设为默认、删除)
94 lines
2.6 KiB
JavaScript
94 lines
2.6 KiB
JavaScript
/**
|
|
* 模型配置类型注册表
|
|
* 定义支持的配置类型及其字段元数据
|
|
*/
|
|
|
|
export const MODEL_CONFIG_TYPES = {
|
|
basic: {
|
|
key: 'basic',
|
|
label: 'OpenAI 兼容接口',
|
|
description: '支持标准的 OpenAI API 格式',
|
|
fields: [
|
|
{ key: 'apiUrl', label: 'API 地址', type: 'url', required: true },
|
|
{ key: 'apiKey', label: 'API 密钥', type: 'password', required: true },
|
|
{ key: 'modelName', label: '模型名称', type: 'text', required: true },
|
|
{ key: 'temperature', label: 'Temperature', type: 'number', min: 0, max: 2, step: 0.1, default: 0.7 },
|
|
{ key: 'maxTokens', label: 'Max Tokens', type: 'number', min: 1, max: 128000, step: 1, default: 4096 },
|
|
{ key: 'topP', label: 'Top P', type: 'number', min: 0, max: 1, step: 0.1, default: 0.9 },
|
|
]
|
|
},
|
|
zhisuan: {
|
|
key: 'zhisuan',
|
|
label: '智算管理平台',
|
|
description: '内部智算平台接入',
|
|
fields: [
|
|
{ key: 'apiUrl', label: 'API 地址', type: 'url', required: true },
|
|
{ key: 'appId', label: 'App ID', type: 'text', required: true },
|
|
{ key: 'appSecret', label: 'App Secret', type: 'password', required: true },
|
|
]
|
|
}
|
|
};
|
|
|
|
/**
|
|
* 获取所有配置类型列表
|
|
* @returns {Array} 配置类型列表
|
|
*/
|
|
export const getConfigTypeList = () => {
|
|
return Object.values(MODEL_CONFIG_TYPES).map(type => ({
|
|
key: type.key,
|
|
label: type.label,
|
|
description: type.description
|
|
}));
|
|
};
|
|
|
|
/**
|
|
* 根据 key 获取配置类型定义
|
|
* @param {string} key - 配置类型 key
|
|
* @returns {Object|undefined} 配置类型定义
|
|
*/
|
|
export const getConfigTypeByKey = (key) => {
|
|
return MODEL_CONFIG_TYPES[key];
|
|
};
|
|
|
|
/**
|
|
* 获取配置类型的字段定义
|
|
* @param {string} key - 配置类型 key
|
|
* @returns {Array} 字段定义数组
|
|
*/
|
|
export const getConfigFields = (key) => {
|
|
const configType = MODEL_CONFIG_TYPES[key];
|
|
return configType ? configType.fields : [];
|
|
};
|
|
|
|
/**
|
|
* 生成配置摘要信息
|
|
* @param {Object} config - 配置对象
|
|
* @returns {string} 摘要字符串
|
|
*/
|
|
export const getConfigSummary = (config) => {
|
|
if (!config) return '-';
|
|
|
|
const type = MODEL_CONFIG_TYPES[config.type];
|
|
if (!type) return '-';
|
|
|
|
if (config.type === 'basic') {
|
|
return config.basic?.modelName || '-';
|
|
}
|
|
|
|
if (config.type === 'zhisuan') {
|
|
return '智算平台接入';
|
|
}
|
|
|
|
return '-';
|
|
};
|
|
|
|
/**
|
|
* 掩码显示敏感信息
|
|
* @param {string} value - 原始值
|
|
* @returns {string} 掩码后的值
|
|
*/
|
|
export const maskSensitiveValue = (value) => {
|
|
if (!value || value.length < 8) return '****';
|
|
return value.substring(0, 4) + '****' + value.substring(value.length - 4);
|
|
};
|