/** * 主入口模块 * 页面初始化和导航控制 */ // 各功能模块的表格配置 window.tableConfigs = { 'fine-tune': { title: '模型调优', api: 'fine-tune', hasCreate: true, createText: '创建训练任务', columns: [ { title: '任务名称', key: 'name' }, { title: '任务状态', key: 'status', render: (val) => `${val}` }, { title: '训练方式', key: 'train_type', render: (val) => val === 'SFT' ? 'SFT 微调训练' : (val === 'DPO' ? 'DPO 偏好训练' : (val === 'CPT' ? 'CPT 继续预训练' : '-')) }, { title: '训练模板', key: 'template', render: (val) => val || '-' }, { title: '基座模型', key: 'base_model', render: (val, row) => `加载中...` } ], actions: ['stop', 'logs', 'delete'] }, 'my-models': { title: '我的模型', api: 'model-manage/trained-models', dataPath: 'models', hasCreate: false, columns: [ { title: '模型名称', key: 'name' }, { title: '训练方法', key: 'train_methods', render: (val) => val && val[0] ? val[0].name : '-' }, { title: '基座模型', key: 'base_model_path', render: (val) => `${val || '-'}` }, { title: '创建时间', key: 'create_time', render: (val) => val ? new Date(val).toLocaleString('zh-CN') : '-' } ], actions: ['view', 'delete'] }, 'model-eval': { title: '模型评测', isExternalPage: true, createConfig: { page: 'model-eval-create', hasCreate: true, createText: '新建评测' } }, 'model-compare': { title: '模型对比', api: 'model-compare', hasCreate: true, createText: '新建对比', columns: [ { title: '对比名称', key: 'model_name' }, { title: '描述', key: 'description', render: (val) => val || '-' }, { title: '相关模型', key: 'models', render: (val) => { if (!val) return '-'; try { // 如果是字符串,尝试解析 JSON let models = val; if (typeof val === 'string') { try { models = JSON.parse(val); } catch { models = val.split(',').map(id => ({ model_name: id.trim() })); } } // 如果是数组,提取模型名称 if (Array.isArray(models) && models.length > 0) { return models.map(function(m) { if (typeof m === 'object' && m !== null) { return m.model_name || m.name || '未知模型'; } return String(m); }).join(', '); } // 如果是单个对象 if (typeof models === 'object' && models !== null) { return models.model_name || models.name || '未知模型'; } return String(models); } catch (e) { return '解析错误'; } }}, { title: '创建时间', key: 'create_time', render: (val) => val ? new Date(val).toLocaleString('zh-CN') : '-' } ], actions: ['compare', 'delete'] }, 'dataset-manage': { title: '数据集管理', api: 'dataset-manage', hasCreate: true, createText: '上传数据集', columns: [ { title: '数据集名称', key: 'name' }, { title: '数据类型', key: 'type', render: (val) => { const textMap = { 'train': '训练数据', 'test': '测试数据', 'eval': '评测数据', 'val': '验证数据', 'other': '其他' }; const displayText = textMap[val?.toLowerCase()] || val || '-'; return '' + displayText + ''; }}, { title: '存储位置', key: 'storage_type', render: (val) => { const textMap = { 'local': '本地存储', 'minio': 'MinIO', 'cloud': '云存储' }; const displayText = textMap[val] || val || '-'; return '' + displayText + ''; }}, { title: '大小', key: 'size', render: (val) => (val && val !== '0 B' && val !== '0') ? val : '-' }, { title: '数据条数', key: 'count', render: (val) => val || 0 }, { title: '描述', key: 'description', render: (val) => val || '-' }, { title: '创建时间', key: 'create_time', render: (val) => val ? new Date(val).toLocaleString('zh-CN') : '-' } ], actions: ['preview', 'download', 'delete'] }, 'data-generate': { title: '其他工具', isTools: true, defaultTools: [ { id: 'data-generate', name: '数据生成', icon: 'fa-database', description: '基于LLM生成微调数据集' }, { id: 'json2jsonl', name: 'JSON转JSONL', icon: 'fa-code', description: '将JSON文件转换为JSONL格式' }, { id: 'md-convert', name: '转换Markdown', icon: 'fa-file-text', description: '将Markdown文件转换为训练数据' } ], customTools: [] }, 'model-manage': { title: '模型管理', api: 'model-manage', hasCreate: true, hasModelTabs: true, createText: '添加模型', columns: [ { title: '模型名称', key: 'name' }, { title: '模型类型', key: 'type', render: (val) => { const textMap = { 'LLM': '大语言模型', 'CV': '计算机视觉', 'NLP': '自然语言处理', 'Embedding': '向量模型', 'Other': '其他' }; const displayText = textMap[val] || val || '-'; return '' + displayText + ''; }}, { title: '用途', key: 'purpose', render: (val) => { const purposeMap = { 'training': { text: '训练', class: 'bg-blue-100 text-blue-700' }, 'inference': { text: '推理', class: 'bg-green-100 text-green-700' }, 'evaluation': { text: '评测', class: 'bg-purple-100 text-purple-700' } }; const display = purposeMap[val] || { text: val || '-', class: 'bg-gray-100 text-gray-700' }; return '' + display.text + ''; }}, { title: '模型来源', key: 'model_source', render: (val) => { const textMap = { 'local': '本地模型', 'api': '在线模型', 'online': '在线模型' }; const displayText = textMap[val] || val || '-'; return '' + displayText + ''; }}, { title: '描述', key: 'description', render: (val) => val || '-' }, { title: '创建时间', key: 'create_time', render: (val) => val ? new Date(val).toLocaleString('zh-CN') : '-' } ], actions: ['edit', 'delete'] }, 'config': { title: '平台性能', skipFetch: true, hasCreate: false, isHardwareMonitor: true }, 'logs': { title: '查看日志', skipFetch: true, hasCreate: false, isLogViewer: true }, 'model-compare-chat': { title: '模型对比', skipFetch: true, hasCreate: false, isExternalPage: true }, 'model-compare-result': { title: '对比结果', skipFetch: true, hasCreate: false, isExternalPage: true }, 'training-log': { title: '训练日志', skipFetch: true, hasCreate: false, isExternalPage: true } }; // 操作按钮映射 window.actionLabels = { 'stop': '停止', 'logs': '查看日志', 'delete': '删除', 'deploy': '部署', 'eval': '评测', 'report': '查看报告', 'scale': '扩容', 'preview': '预览', 'download': '下载', 'detail': '详情', 'edit': '编辑', 'compare': '开始对话', 'chat': '对话', 'view': '合并权重' }; // 加载模型列表缓存 async function loadModelListCache() { try { const response = await fetch(`${window.API_BASE}/model-manage`); const result = await response.json(); if (result.code === 0) { window.modelListCache = result.data || []; } } catch (e) { console.error('加载模型列表失败:', e); window.modelListCache = []; } } // 根据模型ID获取模型名称(同步版本) function getModelName(modelId) { if (!modelId) return '-'; const model = window.modelListCache.find(m => m.id == modelId || m.id === String(modelId) || m.id === Number(modelId) ); if (model) { return model.name; } return `模型${modelId}`; } // 异步获取模型名称并更新 DOM async function fetchAndUpdateModelName(modelId, cellElement) { if (!modelId) { cellElement.textContent = '-'; return; } let model = window.modelListCache.find(m => m.id == modelId || m.id === String(modelId) || m.id === Number(modelId) ); if (!model) { try { const response = await fetch(`${window.API_BASE}/model-manage`); const result = await response.json(); if (result.code === 0) { window.modelListCache = result.data || []; model = window.modelListCache.find(m => m.id == modelId || m.id === String(modelId) || m.id === Number(modelId) ); } } catch (e) { console.error('获取模型列表失败:', e); } } if (model) { cellElement.textContent = model.name; } else { cellElement.textContent = `模型${modelId}`; } } // 根据模型ID列表获取模型名称列表 function getModelNames(modelIds) { if (!modelIds || !Array.isArray(modelIds)) return '-'; return modelIds.map(id => getModelName(id)).join(', '); } // 显示创建表单页面 window.showCreateModal = function(apiType) { if (apiType === 'fine-tune') { window.location.href = 'fine-tune-create.html'; } else if (apiType === 'model-manage') { window.location.href = 'model-manage-create.html'; } else if (apiType === 'model-eval') { window.location.href = 'model-eval-create.html'; } else if (apiType === 'dataset-manage') { window.location.href = 'dataset-create.html'; } else if (apiType === 'model-compare') { window.location.href = 'model-compare-create.html'; } else { window.showMessage('提示', '该功能开发中...', 'info'); } }; // 返回列表页 window.goBack = function() { if (window.currentParentPage) { window.currentPage = window.currentParentPage; window.currentParentPage = null; loadPage(window.currentPage); } else { loadPage('fine-tune'); } }; // 跳转到页面 window.navigateToPage = function(pageName) { if (pageName.endsWith('-create')) { window.location.href = `${pageName}.html`; } else { window.location.href = `main.html?page=${pageName}`; } }; // 返回到列表页 window.goBackToList = function() { navigateToPage('fine-tune'); }; // 加载页面内容 async function loadPage(pageName) { // 切换页面时清除选中状态 TableComponent.clearSelection(); // 离开日志页面时停止自动刷新 SystemService.stopLogAutoRefresh(); // 离开模型调优页面时停止进度刷新 if (window.currentPage === 'fine-tune' && pageName !== 'fine-tune') { TrainingService.stopProgressRefresh(); } const container = document.getElementById('page-content'); const config = window.tableConfigs[pageName]; if (!config) return; // 更新当前页面 window.currentPage = pageName; // 显示加载中 container.innerHTML = `
加载中...