Compare commits
5 Commits
bff07b7a31
...
aea0d51b44
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aea0d51b44 | ||
|
|
3fabd0c0eb | ||
|
|
e212de1693 | ||
|
|
e580ec4791 | ||
|
|
735a8a71f5 |
@@ -8,6 +8,7 @@
|
|||||||
"build": "vue-tsc -b && vite build",
|
"build": "vue-tsc -b && vite build",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"type-check": "vue-tsc -b --noEmit",
|
"type-check": "vue-tsc -b --noEmit",
|
||||||
|
"test": "node scripts/run-regressions.mjs",
|
||||||
"test:default-dashboard": "node scripts/regression-default-dashboard.mjs",
|
"test:default-dashboard": "node scripts/regression-default-dashboard.mjs",
|
||||||
"test:dashboard": "node scripts/regression-dashboard.mjs",
|
"test:dashboard": "node scripts/regression-dashboard.mjs",
|
||||||
"test:data-process-list": "node scripts/regression-data-process-list.mjs",
|
"test:data-process-list": "node scripts/regression-data-process-list.mjs",
|
||||||
@@ -21,6 +22,7 @@
|
|||||||
"test:model-manage": "node scripts/regression-model-manage.mjs",
|
"test:model-manage": "node scripts/regression-model-manage.mjs",
|
||||||
"test:hardware": "node scripts/regression-hardware-dashboard.mjs",
|
"test:hardware": "node scripts/regression-hardware-dashboard.mjs",
|
||||||
"test:training-log-layout": "node scripts/regression-training-log-layout.mjs",
|
"test:training-log-layout": "node scripts/regression-training-log-layout.mjs",
|
||||||
|
"test:fine-tune-create": "node scripts/regression-fine-tune-create-ui.mjs",
|
||||||
"test:page-surface": "node scripts/regression-page-surface.mjs"
|
"test:page-surface": "node scripts/regression-page-surface.mjs"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -13,6 +13,13 @@ const confirmDialogPath = path.resolve(scriptDir, '../src/components/AppConfirmD
|
|||||||
const layoutPath = path.resolve(scriptDir, '../src/layouts/MainLayout.vue')
|
const layoutPath = path.resolve(scriptDir, '../src/layouts/MainLayout.vue')
|
||||||
const viewSource = await readFile(viewPath, 'utf8')
|
const viewSource = await readFile(viewPath, 'utf8')
|
||||||
const layoutSource = await readFile(layoutPath, 'utf8')
|
const layoutSource = await readFile(layoutPath, 'utf8')
|
||||||
|
const [draftSource, stateSource, generationSource, viewStyleSource] = await Promise.all([
|
||||||
|
readFile(path.join(createDir, 'useDataProcessDraft.ts'), 'utf8'),
|
||||||
|
readFile(path.join(createDir, 'dataProcessCreateState.ts'), 'utf8'),
|
||||||
|
readFile(path.join(createDir, 'useDataProcessGeneration.ts'), 'utf8'),
|
||||||
|
readFile(path.join(createDir, 'data-process-create.scss'), 'utf8'),
|
||||||
|
])
|
||||||
|
const implementationSource = [viewSource, draftSource, stateSource, generationSource].join('\n')
|
||||||
|
|
||||||
assert.ok(existsSync(confirmDialogPath), '缺少公共确认弹窗组件 AppConfirmDialog')
|
assert.ok(existsSync(confirmDialogPath), '缺少公共确认弹窗组件 AppConfirmDialog')
|
||||||
const confirmDialogSource = await readFile(confirmDialogPath, 'utf8')
|
const confirmDialogSource = await readFile(confirmDialogPath, 'utf8')
|
||||||
@@ -43,9 +50,10 @@ assert.match(
|
|||||||
'五步向导顺序必须为创建任务、上传文件、数据预览、开始生成、结果编辑与保存',
|
'五步向导顺序必须为创建任务、上传文件、数据预览、开始生成、结果编辑与保存',
|
||||||
)
|
)
|
||||||
assert.doesNotMatch(viewSource, /steps\s*=\s*computed|all\.filter/, '步骤仍根据处理类型动态增减')
|
assert.doesNotMatch(viewSource, /steps\s*=\s*computed|all\.filter/, '步骤仍根据处理类型动态增减')
|
||||||
assert.match(viewSource, /localStorage\.setItem\(DRAFT_STORAGE_KEY/, '草稿没有持久化')
|
assert.match(draftSource, /localStorage\.setItem\(DATA_PROCESS_DRAFT_STORAGE_KEY/, '草稿没有持久化')
|
||||||
assert.match(viewSource, /localStorage\.getItem\(DRAFT_STORAGE_KEY\)/, '草稿没有恢复读取')
|
assert.match(draftSource, /localStorage\.getItem\(DATA_PROCESS_DRAFT_STORAGE_KEY\)/, '草稿没有恢复读取')
|
||||||
assert.match(viewSource, /restoreDraft\(\)/, '页面没有恢复草稿')
|
assert.match(viewSource, /restoreDraft\(\)/, '页面没有恢复草稿')
|
||||||
|
assert.ok(viewSource.split('\n').length < 800, 'DataProcessCreateView 拆分后仍超过 800 行')
|
||||||
|
|
||||||
const expectedComponents = [
|
const expectedComponents = [
|
||||||
'TaskSetupStep.vue',
|
'TaskSetupStep.vue',
|
||||||
@@ -125,19 +133,49 @@ assert.match(previewSource, /\.preview-editor\s*\{[\s\S]*?flex:\s*1 1 auto[\s\S]
|
|||||||
assert.match(previewSource, /@media \(max-width: 900px\)/, '第三步缺少窄屏上下布局')
|
assert.match(previewSource, /@media \(max-width: 900px\)/, '第三步缺少窄屏上下布局')
|
||||||
|
|
||||||
const taskSetupPath = path.join(createDir, 'TaskSetupStep.vue')
|
const taskSetupPath = path.join(createDir, 'TaskSetupStep.vue')
|
||||||
const taskSetupSource = await readFile(taskSetupPath, 'utf8')
|
const structuredOptionsPath = path.join(createDir, 'StructuredOptionsPanel.vue')
|
||||||
|
const unstructuredOptionsPath = path.join(createDir, 'UnstructuredOptionsPanel.vue')
|
||||||
|
const datasetSplitEditorPath = path.join(createDir, 'DatasetSplitEditor.vue')
|
||||||
const generationOptionsPath = path.join(createDir, 'GenerationOptionsPanel.vue')
|
const generationOptionsPath = path.join(createDir, 'GenerationOptionsPanel.vue')
|
||||||
const generationControlSource = await readFile(generationOptionsPath, 'utf8')
|
|
||||||
const sourceUploadPath = path.join(createDir, 'SourceUploadStep.vue')
|
const sourceUploadPath = path.join(createDir, 'SourceUploadStep.vue')
|
||||||
const sourceUploadSource = await readFile(sourceUploadPath, 'utf8')
|
const [
|
||||||
|
taskSetupSource,
|
||||||
|
structuredOptionsSource,
|
||||||
|
unstructuredOptionsSource,
|
||||||
|
datasetSplitEditorSource,
|
||||||
|
generationControlSource,
|
||||||
|
sourceUploadSource,
|
||||||
|
] = await Promise.all([
|
||||||
|
readFile(taskSetupPath, 'utf8'),
|
||||||
|
readFile(structuredOptionsPath, 'utf8'),
|
||||||
|
readFile(unstructuredOptionsPath, 'utf8'),
|
||||||
|
readFile(datasetSplitEditorPath, 'utf8'),
|
||||||
|
readFile(generationOptionsPath, 'utf8'),
|
||||||
|
readFile(sourceUploadPath, 'utf8'),
|
||||||
|
])
|
||||||
|
const taskSetupFeatureSource = [
|
||||||
|
taskSetupSource,
|
||||||
|
structuredOptionsSource,
|
||||||
|
unstructuredOptionsSource,
|
||||||
|
datasetSplitEditorSource,
|
||||||
|
].join('\n')
|
||||||
|
|
||||||
|
for (const componentPath of [structuredOptionsPath, unstructuredOptionsPath, datasetSplitEditorPath]) {
|
||||||
|
assert.ok(existsSync(componentPath), `缺少任务配置拆分组件:${path.basename(componentPath)}`)
|
||||||
|
}
|
||||||
|
assert.ok(taskSetupSource.split('\n').length < 800, 'TaskSetupStep 拆分后仍超过 800 行')
|
||||||
|
assert.match(taskSetupSource, /<StructuredOptionsPanel/, '任务配置没有挂载结构化选项面板')
|
||||||
|
assert.match(taskSetupSource, /<UnstructuredOptionsPanel/, '任务配置没有挂载非结构化选项面板')
|
||||||
|
assert.match(structuredOptionsSource, /<DatasetSplitEditor/, '结构化选项没有复用数据集划分编辑器')
|
||||||
|
assert.match(unstructuredOptionsSource, /<DatasetSplitEditor/, '非结构化选项没有复用数据集划分编辑器')
|
||||||
|
|
||||||
for (const marker of ['<el-upload', '源数据上传', '数据源配置', 'uploadedFiles']) {
|
for (const marker of ['<el-upload', '源数据上传', '数据源配置', 'uploadedFiles']) {
|
||||||
assert.ok(!taskSetupSource.includes(marker), `第一步仍包含上传职责:${marker}`)
|
assert.ok(!taskSetupFeatureSource.includes(marker), `第一步仍包含上传职责:${marker}`)
|
||||||
}
|
}
|
||||||
assert.match(viewSource, /<SourceUploadStep\s+[\s\S]*?v-else-if="currentStepId === 'upload'"/, '第二步没有挂载独立上传组件')
|
assert.match(viewSource, /<SourceUploadStep\s+[\s\S]*?v-else-if="currentStepId === 'upload'"/, '第二步没有挂载独立上传组件')
|
||||||
assert.match(viewSource, /if \(currentStepId\.value === 'create'\) return '继续:上传文件'/, '第一步主按钮没有指向上传文件')
|
assert.match(viewSource, /if \(currentStepId\.value === 'create'\) return '继续:上传文件'/, '第一步主按钮没有指向上传文件')
|
||||||
assert.match(viewSource, /if \(currentStepId\.value === 'upload'\) return '继续:数据预览'/, '第二步主按钮没有指向数据预览')
|
assert.match(viewSource, /if \(currentStepId\.value === 'upload'\) return '继续:数据预览'/, '第二步主按钮没有指向数据预览')
|
||||||
assert.match(viewSource, /const DRAFT_SCHEMA_VERSION = 5/, '生成配置扩展后必须升级草稿版本')
|
assert.match(draftSource, /DATA_PROCESS_DRAFT_SCHEMA_VERSION = 6/, '安全草稿格式必须升级到 v6')
|
||||||
|
|
||||||
const nextFromCreateStart = viewSource.indexOf('async function nextFromCreate()')
|
const nextFromCreateStart = viewSource.indexOf('async function nextFromCreate()')
|
||||||
const nextFromUploadStart = viewSource.indexOf('function nextFromUpload()', nextFromCreateStart)
|
const nextFromUploadStart = viewSource.indexOf('function nextFromUpload()', nextFromCreateStart)
|
||||||
@@ -154,9 +192,15 @@ assert.match(nextFromUploadSource, /goToStep\('preview'\)/, '上传步骤完成
|
|||||||
assert.match(viewSource, /function goToStep\(stepId: StepId\)[\s\S]*?WIZARD_STEPS\.findIndex/, '向导跳转没有使用稳定步骤标识')
|
assert.match(viewSource, /function goToStep\(stepId: StepId\)[\s\S]*?WIZARD_STEPS\.findIndex/, '向导跳转没有使用稳定步骤标识')
|
||||||
assert.match(viewSource, /currentStepId\.value === 'preview'[\s\S]*?goToStep\('generate'\)/, '数据预览步骤没有进入开始生成')
|
assert.match(viewSource, /currentStepId\.value === 'preview'[\s\S]*?goToStep\('generate'\)/, '数据预览步骤没有进入开始生成')
|
||||||
assert.match(viewSource, /generation\.status === 'success'[\s\S]*?goToStep\('results'\)/, '生成成功后没有进入结果编辑与保存')
|
assert.match(viewSource, /generation\.status === 'success'[\s\S]*?goToStep\('results'\)/, '生成成功后没有进入结果编辑与保存')
|
||||||
assert.match(viewSource, /currentStepId:\s*currentStepId\.value/, '草稿没有保存稳定步骤标识')
|
assert.match(draftSource, /currentStepId:\s*bindings\.currentStepId\.value/, '草稿没有保存稳定步骤标识')
|
||||||
assert.match(viewSource, /const LEGACY_V3_STEP_IDS:[^=]*= \['create', 'preview', 'generate', 'results'\]/, 'v3 草稿缺少旧步骤索引映射')
|
const draftSnapshotSource = draftSource.slice(
|
||||||
assert.match(viewSource, /snapshotSchemaVersion === 3[\s\S]*?LEGACY_V3_STEP_IDS/, 'v3 草稿没有迁移到五步索引')
|
draftSource.indexOf('function draftSnapshot()'),
|
||||||
|
draftSource.indexOf('function writeDraft'),
|
||||||
|
)
|
||||||
|
for (const forbiddenField of ['uploadedFiles', 'previewItems', 'results', 'password', 'token']) {
|
||||||
|
assert.ok(!draftSnapshotSource.includes(forbiddenField), `安全草稿不应持久化:${forbiddenField}`)
|
||||||
|
}
|
||||||
|
assert.match(draftSource, /writeDraft\(false\)/, '恢复旧草稿后没有立即覆盖潜在敏感数据')
|
||||||
assert.match(viewSource, /<ResultEditorStep\s+[\s\S]*?v-else-if="currentStepId === 'results'"/, '结果编辑器必须只在结果步骤渲染')
|
assert.match(viewSource, /<ResultEditorStep\s+[\s\S]*?v-else-if="currentStepId === 'results'"/, '结果编辑器必须只在结果步骤渲染')
|
||||||
assert.match(viewSource, /watch\(processType,[\s\S]*?resetSourceDataForProcessTypeChange\(\)/, '切换处理类型后没有失效旧源数据')
|
assert.match(viewSource, /watch\(processType,[\s\S]*?resetSourceDataForProcessTypeChange\(\)/, '切换处理类型后没有失效旧源数据')
|
||||||
assert.match(viewSource, /function resetSourceDataForProcessTypeChange\(\)[\s\S]*?uploadedFiles\.value = \[\][\s\S]*?selectedPreviewFileId\.value = null/, '旧源数据失效没有同步清理文件与预览选择')
|
assert.match(viewSource, /function resetSourceDataForProcessTypeChange\(\)[\s\S]*?uploadedFiles\.value = \[\][\s\S]*?selectedPreviewFileId\.value = null/, '旧源数据失效没有同步清理文件与预览选择')
|
||||||
@@ -170,32 +214,32 @@ for (const option of [
|
|||||||
'异常数据过滤',
|
'异常数据过滤',
|
||||||
'敏感信息脱敏',
|
'敏感信息脱敏',
|
||||||
]) {
|
]) {
|
||||||
assert.ok(taskSetupSource.includes(option), `结构化预处理缺少选项:${option}`)
|
assert.ok(structuredOptionsSource.includes(option), `结构化预处理缺少选项:${option}`)
|
||||||
}
|
}
|
||||||
assert.ok(taskSetupSource.includes('生成选项'), '结构化配置缺少生成选项分类')
|
assert.ok(structuredOptionsSource.includes('生成选项'), '结构化配置缺少生成选项分类')
|
||||||
assert.ok(taskSetupSource.includes('语义丰富表达'), '生成选项缺少语义丰富表达开关')
|
assert.ok(structuredOptionsSource.includes('语义丰富表达'), '生成选项缺少语义丰富表达开关')
|
||||||
assert.ok(taskSetupSource.includes('使用大模型将问答表述得更自然、柔和'), '语义丰富表达缺少辅助说明')
|
assert.ok(structuredOptionsSource.includes('使用大模型将问答表述得更自然、柔和'), '语义丰富表达缺少辅助说明')
|
||||||
for (const splitName of ['训练集', '验证集', '测试集']) {
|
for (const splitName of ['训练集', '验证集', '测试集']) {
|
||||||
assert.ok(taskSetupSource.includes(splitName), `生成选项缺少数据集划分:${splitName}`)
|
assert.ok(datasetSplitEditorSource.includes(splitName), `生成选项缺少数据集划分:${splitName}`)
|
||||||
}
|
}
|
||||||
assert.match(taskSetupSource, /const splitTotal = computed/, '数据集划分缺少比例总和计算')
|
assert.match(datasetSplitEditorSource, /const splitTotal = computed/, '数据集划分缺少比例总和计算')
|
||||||
assert.match(taskSetupSource, /splitTotal\.value !== 100/, '数据集划分缺少总和 100% 校验')
|
assert.match(taskSetupSource, /splitTotal\.value !== 100/, '数据集划分缺少总和 100% 校验')
|
||||||
assert.ok(taskSetupSource.includes('训练集、验证集和测试集比例总和必须为 100%'), '数据集划分缺少就地错误提示')
|
assert.ok(datasetSplitEditorSource.includes('训练集、验证集和测试集比例总和必须为 100%'), '数据集划分缺少就地错误提示')
|
||||||
for (const splitField of ['train', 'validation', 'test']) {
|
for (const splitField of ['train', 'validation', 'test']) {
|
||||||
assert.match(
|
assert.match(
|
||||||
taskSetupSource,
|
datasetSplitEditorSource,
|
||||||
new RegExp(`structuredOptions\\.datasetSplit\\.${splitField}[\\s\\S]*?:min="0"[\\s\\S]*?:max="100"[\\s\\S]*?:step="1"[\\s\\S]*?:precision="0"`),
|
new RegExp(`modelValue\\.${splitField}[\\s\\S]*?:min="0"[\\s\\S]*?:max="100"[\\s\\S]*?:step="1"[\\s\\S]*?:precision="0"`),
|
||||||
`数据集划分字段 ${splitField} 缺少 0~100 的整数限制`,
|
`数据集划分字段 ${splitField} 缺少 0~100 的整数限制`,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
assert.match(taskSetupSource, /<el-switch[\s\S]*structuredOptions\.semanticEnrichment/, '语义丰富表达必须使用开关控件')
|
assert.match(structuredOptionsSource, /<el-switch[\s\S]*options\.semanticEnrichment/, '语义丰富表达必须使用开关控件')
|
||||||
assert.match(taskSetupSource, /<el-input-number[\s\S]*structuredOptions\.qaPairsPerRow[\s\S]*:min="1"[\s\S]*:max="5"/, '每行生成数量必须限制在 1 到 5')
|
assert.match(structuredOptionsSource, /<el-input-number[\s\S]*options\.qaPairsPerRow[\s\S]*:min="1"[\s\S]*:max="5"/, '每行生成数量必须限制在 1 到 5')
|
||||||
assert.match(viewSource, /const structuredOptions = ref<StructuredProcessOptions>/, '父页面缺少结构化配置状态')
|
assert.match(viewSource, /const structuredOptions = ref<StructuredProcessOptions>/, '父页面缺少结构化配置状态')
|
||||||
assert.match(viewSource, /datasetSplit:\s*\{ train: 80, validation: 10, test: 10 \}/, '数据集划分默认值必须为 80/10/10')
|
assert.match(stateSource, /datasetSplit:\s*\{ train: 80, validation: 10, test: 10 \}/, '数据集划分默认值必须为 80/10/10')
|
||||||
assert.match(viewSource, /structuredOptions:\s*\{[\s\S]*\.\.\.structuredOptions\.value/, '结构化配置没有写入草稿')
|
assert.match(draftSource, /structuredOptions:\s*\{[\s\S]*\.\.\.bindings\.structuredOptions\.value/, '结构化配置没有写入草稿')
|
||||||
assert.match(viewSource, /structuredOptions\.value = \{[\s\S]*\.\.\.snapshot\.structuredOptions/, '结构化配置没有从草稿恢复')
|
assert.match(draftSource, /bindings\.structuredOptions\.value = \{[\s\S]*\.\.\.snapshot\.structuredOptions/, '结构化配置没有从草稿恢复')
|
||||||
assert.match(viewSource, /v-model:structured-options="structuredOptions"/, '父页面没有双向绑定结构化配置')
|
assert.match(viewSource, /v-model:structured-options="structuredOptions"/, '父页面没有双向绑定结构化配置')
|
||||||
assert.match(viewSource, /createResults\([\s\S]*structuredOptions\.value/, '每行生成数量没有接入结果生成逻辑')
|
assert.match(generationSource, /createResults\([\s\S]*bindings\.structuredOptions\.value/, '每行生成数量没有接入结果生成逻辑')
|
||||||
|
|
||||||
for (const field of [
|
for (const field of [
|
||||||
'generationModelId',
|
'generationModelId',
|
||||||
@@ -206,23 +250,25 @@ for (const field of [
|
|||||||
'minOutputLength',
|
'minOutputLength',
|
||||||
]) {
|
]) {
|
||||||
assert.ok(typesSource.includes(field), `生成控制配置缺少字段:${field}`)
|
assert.ok(typesSource.includes(field), `生成控制配置缺少字段:${field}`)
|
||||||
assert.ok(viewSource.includes(field), `父页面默认值或草稿状态缺少字段:${field}`)
|
assert.ok(implementationSource.includes(field), `父页面默认值或草稿状态缺少字段:${field}`)
|
||||||
}
|
}
|
||||||
assert.match(taskSetupSource, /GenerationOptionsPanel/, '生成选项没有复用统一的大模型与质量筛选组件')
|
assert.match(structuredOptionsSource, /GenerationOptionsPanel/, '结构化生成选项没有复用统一的大模型与质量筛选组件')
|
||||||
assert.match(taskSetupSource, /:options="structuredOptions"/, '结构化生成选项未接入统一配置组件')
|
assert.match(unstructuredOptionsSource, /GenerationOptionsPanel/, '非结构化生成选项没有复用统一的大模型与质量筛选组件')
|
||||||
assert.match(taskSetupSource, /:options="unstructuredOptions"/, '非结构化生成选项未接入统一配置组件')
|
assert.match(structuredOptionsSource, /:options="options"/, '结构化生成选项未接入统一配置组件')
|
||||||
assert.match(taskSetupSource, /<h3>大模型<\/h3>/, '大模型必须作为与生成选项平级的独立分类')
|
assert.match(unstructuredOptionsSource, /:options="options"/, '非结构化生成选项未接入统一配置组件')
|
||||||
assert.match(taskSetupSource, /section="model"/, '独立大模型分类没有挂载模型配置')
|
assert.match(taskSetupFeatureSource, /<h3>大模型<\/h3>/, '大模型必须作为与生成选项平级的独立分类')
|
||||||
assert.match(taskSetupSource, /section="quality"/, '质量筛选没有保留在生成选项分类中')
|
assert.match(taskSetupFeatureSource, /section="model"/, '独立大模型分类没有挂载模型配置')
|
||||||
|
assert.match(taskSetupFeatureSource, /section="quality"/, '质量筛选没有保留在生成选项分类中')
|
||||||
assert.doesNotMatch(generationControlSource, /<h4>大模型<\/h4>/, '大模型不应继续作为生成选项内部子分类')
|
assert.doesNotMatch(generationControlSource, /<h4>大模型<\/h4>/, '大模型不应继续作为生成选项内部子分类')
|
||||||
for (const label of ['大模型', '数据生成模型', '默认提示语', '质量筛选', '过滤低质量内容', '过滤过短内容', '最少字数']) {
|
for (const label of ['大模型', '数据生成模型', '默认提示语', '质量筛选', '过滤低质量内容', '过滤过短内容', '最少字数']) {
|
||||||
assert.ok(generationControlSource.includes(label), `生成控制界面缺少:${label}`)
|
assert.ok(generationControlSource.includes(label), `生成控制界面缺少:${label}`)
|
||||||
}
|
}
|
||||||
assert.match(generationControlSource, /filterable/, '数据生成模型下拉必须支持搜索')
|
assert.match(generationControlSource, /filterable/, '数据生成模型下拉必须支持搜索')
|
||||||
assert.match(generationControlSource, /maxlength="500"/, '默认提示语缺少合理的长度限制')
|
assert.match(generationControlSource, /maxlength="500"/, '默认提示语缺少合理的长度限制')
|
||||||
assert.match(generationControlSource, /\.model-option-row\s*\{[\s\S]*?display:\s*flex[\s\S]*?border:\s*1px solid #e2e5ec/, '大模型配置没有与上方生成选项使用一致的配置行样式')
|
assert.match(generationControlSource, /\.model-field\s*\{[\s\S]*?display:\s*flex[\s\S]*?flex-direction:\s*column/, '大模型字段没有使用稳定的纵向表单布局')
|
||||||
assert.match(viewSource, /const DEFAULT_GENERATION_PROMPT\s*=\s*['"][^'"]{40,}['"]/, '大模型配置缺少可直接使用的默认提示语')
|
assert.match(generationControlSource, /\.generation-config-group\s*\{[\s\S]*?border:\s*1px solid #e2e5ec/, '大模型配置没有保留统一配置面板边框')
|
||||||
assert.equal((viewSource.match(/generationPrompt:\s*DEFAULT_GENERATION_PROMPT/g) || []).length, 2, '结构化与非结构化任务必须共用默认提示语')
|
assert.match(stateSource, /const DEFAULT_GENERATION_PROMPT\s*=\s*['"][^'"]{40,}['"]/, '大模型配置缺少可直接使用的默认提示语')
|
||||||
|
assert.equal((stateSource.match(/generationPrompt:\s*DEFAULT_GENERATION_PROMPT/g) || []).length, 2, '结构化与非结构化任务必须共用默认提示语')
|
||||||
assert.match(generationControlSource, /v-if="options\.qualityFilterEnabled"/, '质量规则没有随总开关渐进显示')
|
assert.match(generationControlSource, /v-if="options\.qualityFilterEnabled"/, '质量规则没有随总开关渐进显示')
|
||||||
assert.match(generationControlSource, /v-if="options\.filterShortContent"/, '最少字数没有随短内容规则显示')
|
assert.match(generationControlSource, /v-if="options\.filterShortContent"/, '最少字数没有随短内容规则显示')
|
||||||
assert.match(generationControlSource, /:min="1"[\s\S]*:max="1000"/, '最少字数缺少 1 到 1000 的边界限制')
|
assert.match(generationControlSource, /:min="1"[\s\S]*:max="1000"/, '最少字数缺少 1 到 1000 的边界限制')
|
||||||
@@ -253,60 +299,55 @@ for (const removedField of ['contextScope', 'generationTypes', 'skipUnanswerable
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert.match(taskSetupSource, /v-if="processType === 'unstructured'"/, '非结构化配置必须仅在非结构化数据类型下显示')
|
assert.match(taskSetupSource, /v-if="processType === 'unstructured'"/, '非结构化配置必须仅在非结构化数据类型下显示')
|
||||||
assert.ok(taskSetupSource.includes('智能预处理'), '简化后缺少智能预处理总开关')
|
assert.ok(unstructuredOptionsSource.includes('智能预处理'), '简化后缺少智能预处理总开关')
|
||||||
assert.ok(taskSetupSource.includes('敏感信息脱敏'), '简化后缺少脱敏开关')
|
assert.ok(unstructuredOptionsSource.includes('敏感信息脱敏'), '简化后缺少脱敏开关')
|
||||||
assert.match(taskSetupSource, /const smartPreprocessEnabled = computed/, '智能预处理没有映射到内部处理项')
|
assert.match(unstructuredOptionsSource, /const smartPreprocessEnabled = computed/, '智能预处理没有映射到内部处理项')
|
||||||
assert.match(taskSetupSource, /function updateSmartPreprocess/, '智能预处理开关缺少更新逻辑')
|
assert.match(unstructuredOptionsSource, /function updateSmartPreprocess/, '智能预处理开关缺少更新逻辑')
|
||||||
assert.match(taskSetupSource, /function updateDesensitize/, '脱敏开关缺少更新逻辑')
|
assert.match(unstructuredOptionsSource, /function updateDesensitize/, '脱敏开关缺少更新逻辑')
|
||||||
|
|
||||||
assert.ok(taskSetupSource.includes('切分选项'), '非结构化配置缺少切分选项分类')
|
assert.ok(unstructuredOptionsSource.includes('切分选项'), '非结构化配置缺少切分选项分类')
|
||||||
for (const method of ['自动语义切分', '按标题和段落', '按固定长度', '自定义分隔符']) {
|
for (const method of ['自动语义切分', '按标题和段落', '按固定长度', '自定义分隔符']) {
|
||||||
assert.ok(taskSetupSource.includes(method), `切分方式缺少选项:${method}`)
|
assert.ok(unstructuredOptionsSource.includes(method), `切分方式缺少选项:${method}`)
|
||||||
}
|
}
|
||||||
for (const label of ['切片长度', '重叠长度', '最小切片长度', '保护表格、代码和列表']) {
|
for (const label of ['切片长度', '重叠长度', '最小切片长度', '保护表格、代码和列表']) {
|
||||||
assert.ok(taskSetupSource.includes(label), `切分选项缺少配置:${label}`)
|
assert.ok(unstructuredOptionsSource.includes(label), `切分选项缺少配置:${label}`)
|
||||||
}
|
}
|
||||||
assert.ok(taskSetupSource.includes('高级设置'), '切分选项缺少渐进式高级设置入口')
|
assert.ok(unstructuredOptionsSource.includes('高级设置'), '切分选项缺少渐进式高级设置入口')
|
||||||
assert.match(taskSetupSource, /:aria-expanded="advancedChunkSettingsOpen"/, '高级设置入口缺少展开状态的可访问性标记')
|
assert.match(unstructuredOptionsSource, /:aria-expanded="advancedChunkSettingsOpen"/, '高级设置入口缺少展开状态的可访问性标记')
|
||||||
assert.match(taskSetupSource, /v-if="advancedChunkSettingsOpen"/, '高级设置内容没有默认收起')
|
assert.match(unstructuredOptionsSource, /v-if="advancedChunkSettingsOpen"/, '高级设置内容没有默认收起')
|
||||||
assert.match(taskSetupSource, /watch\(\(\) => props\.unstructuredOptions\.chunkMethod,[\s\S]*?method === 'custom'[\s\S]*?advancedChunkSettingsOpen\.value = true/, '选择自定义分隔符时没有自动展开高级设置')
|
assert.match(unstructuredOptionsSource, /watch\(\(\) => props\.options\.chunkMethod,[\s\S]*?method === 'custom'[\s\S]*?advancedChunkSettingsOpen\.value = true/, '选择自定义分隔符时没有自动展开高级设置')
|
||||||
assert.match(taskSetupSource, /if \(chunkValidationMessage\.value\) \{[\s\S]*?advancedChunkSettingsOpen\.value = true[\s\S]*?return false/, '高级切分配置校验失败时没有重新展开定位')
|
assert.match(unstructuredOptionsSource, /function revealValidation\(\)[\s\S]*?advancedChunkSettingsOpen\.value = true/, '非结构化面板没有暴露高级校验定位能力')
|
||||||
assert.match(taskSetupSource, /const preserveSpecialContentEnabled = computed/, '特殊内容保护没有合并为单一开关')
|
assert.match(taskSetupSource, /if \(chunkValidationMessage\.value\) \{[\s\S]*?revealValidation\(\)[\s\S]*?return false/, '高级切分配置校验失败时没有重新展开定位')
|
||||||
assert.match(taskSetupSource, /function updateSpecialContentProtection/, '特殊内容保护开关缺少更新逻辑')
|
assert.match(unstructuredOptionsSource, /const preserveSpecialContentEnabled = computed/, '特殊内容保护没有合并为单一开关')
|
||||||
assert.match(taskSetupSource, /unstructuredOptions\.chunkSize[\s\S]*?:min="200"[\s\S]*?:max="2000"/, '切片长度必须限制在 200 到 2000 Token')
|
assert.match(unstructuredOptionsSource, /function updateSpecialContentProtection/, '特殊内容保护开关缺少更新逻辑')
|
||||||
assert.match(taskSetupSource, /unstructuredOptions\.chunkOverlap[\s\S]*?:min="0"[\s\S]*?:max="500"/, '重叠长度必须限制在 0 到 500 Token')
|
assert.match(unstructuredOptionsSource, /options\.chunkSize[\s\S]*?:min="200"[\s\S]*?:max="2000"/, '切片长度必须限制在 200 到 2000 Token')
|
||||||
assert.match(taskSetupSource, /unstructuredOptions\.minChunkSize[\s\S]*?:min="20"[\s\S]*?:max="500"/, '最小切片长度必须限制在 20 到 500 Token')
|
assert.match(unstructuredOptionsSource, /options\.chunkOverlap[\s\S]*?:min="0"[\s\S]*?:max="500"/, '重叠长度必须限制在 0 到 500 Token')
|
||||||
|
assert.match(unstructuredOptionsSource, /options\.minChunkSize[\s\S]*?:min="20"[\s\S]*?:max="500"/, '最小切片长度必须限制在 20 到 500 Token')
|
||||||
|
|
||||||
for (const label of ['语义丰富表达', '每个切片生成数量', '数据集划分']) {
|
for (const label of ['语义丰富表达', '每个切片生成数量', '数据集划分']) {
|
||||||
assert.ok(taskSetupSource.includes(label), `非结构化生成选项缺少:${label}`)
|
assert.ok(taskSetupFeatureSource.includes(label), `非结构化生成选项缺少:${label}`)
|
||||||
}
|
}
|
||||||
for (const removedLabel of ['上下文范围', '问题类型', '跳过无法回答的内容']) {
|
for (const removedLabel of ['上下文范围', '问题类型', '跳过无法回答的内容']) {
|
||||||
assert.ok(!taskSetupSource.includes(removedLabel), `简化后仍显示低频选项:${removedLabel}`)
|
assert.ok(!taskSetupFeatureSource.includes(removedLabel), `简化后仍显示低频选项:${removedLabel}`)
|
||||||
}
|
}
|
||||||
assert.match(taskSetupSource, /unstructuredOptions\.qaPairsPerChunk[\s\S]*?:min="1"[\s\S]*?:max="3"/, '每个切片生成数量必须限制在 1 到 3')
|
assert.match(unstructuredOptionsSource, /options\.qaPairsPerChunk[\s\S]*?:min="1"[\s\S]*?:max="3"/, '每个切片生成数量必须限制在 1 到 3')
|
||||||
assert.match(taskSetupSource, /unstructuredSplitTotal\.value !== 100/, '非结构化数据集划分缺少总和 100% 校验')
|
assert.match(taskSetupSource, /unstructuredSplitTotal\.value !== 100/, '非结构化数据集划分缺少总和 100% 校验')
|
||||||
assert.match(taskSetupSource, /chunkOverlap \+ props\.unstructuredOptions\.minChunkSize[\s\S]*?> props\.unstructuredOptions\.chunkSize/, '切分配置未校验重叠长度与最小切片长度的组合边界')
|
assert.match(taskSetupSource, /chunkOverlap \+ props\.unstructuredOptions\.minChunkSize[\s\S]*?> props\.unstructuredOptions\.chunkSize/, '切分配置未校验重叠长度与最小切片长度的组合边界')
|
||||||
assert.ok(taskSetupSource.includes('Token 数为轻量估算值'), '切片长度缺少 Token 估算说明')
|
assert.ok(unstructuredOptionsSource.includes('Token 数为轻量估算值'), '切片长度缺少 Token 估算说明')
|
||||||
assert.match(taskSetupSource, /\.chunk-settings-grid\s*\{[\s\S]*?grid-template-columns:\s*repeat\(3,\s*minmax\(0,\s*1fr\)\)/, '核心切分参数没有收紧为三列布局')
|
assert.match(unstructuredOptionsSource, /\.chunk-settings-grid\s*\{[\s\S]*?grid-template-columns:\s*repeat\(3,\s*minmax\(0,\s*1fr\)\)/, '核心切分参数没有收紧为三列布局')
|
||||||
|
|
||||||
assert.match(viewSource, /const unstructuredOptions = ref<UnstructuredProcessOptions>/, '父页面缺少非结构化配置状态')
|
assert.match(viewSource, /const unstructuredOptions = ref<UnstructuredProcessOptions>/, '父页面缺少非结构化配置状态')
|
||||||
assert.match(viewSource, /chunkMethod:\s*'semantic'/, '非结构化默认切分方式必须为自动语义切分')
|
assert.match(stateSource, /chunkMethod:\s*'semantic'/, '非结构化默认切分方式必须为自动语义切分')
|
||||||
assert.match(viewSource, /chunkSize:\s*800/, '默认切片长度必须为 800 Token')
|
assert.match(stateSource, /chunkSize:\s*800/, '默认切片长度必须为 800 Token')
|
||||||
assert.match(viewSource, /chunkOverlap:\s*100/, '默认重叠长度必须为 100 Token')
|
assert.match(stateSource, /chunkOverlap:\s*100/, '默认重叠长度必须为 100 Token')
|
||||||
assert.match(viewSource, /minChunkSize:\s*100/, '默认最小切片长度必须为 100 Token')
|
assert.match(stateSource, /minChunkSize:\s*100/, '默认最小切片长度必须为 100 Token')
|
||||||
assert.match(viewSource, /qaPairsPerChunk:\s*1/, '默认每个切片必须生成 1 个问答对')
|
assert.match(stateSource, /qaPairsPerChunk:\s*1/, '默认每个切片必须生成 1 个问答对')
|
||||||
assert.match(viewSource, /unstructuredOptions:\s*\{[\s\S]*\.\.\.unstructuredOptions\.value/, '非结构化配置没有写入草稿')
|
assert.match(draftSource, /unstructuredOptions:\s*\{[\s\S]*\.\.\.bindings\.unstructuredOptions\.value/, '非结构化配置没有写入草稿')
|
||||||
assert.match(viewSource, /unstructuredOptions\.value = \{[\s\S]*restoredUnstructuredOptions\.chunkSize/, '非结构化配置没有从草稿恢复')
|
assert.match(draftSource, /bindings\.unstructuredOptions\.value = \{[\s\S]*\.\.\.snapshot\.unstructuredOptions/, '非结构化配置没有从草稿恢复')
|
||||||
assert.match(viewSource, /v-model:unstructured-options="unstructuredOptions"/, '父页面没有双向绑定非结构化配置')
|
assert.match(viewSource, /v-model:unstructured-options="unstructuredOptions"/, '父页面没有双向绑定非结构化配置')
|
||||||
assert.match(viewSource, /const DRAFT_SCHEMA_VERSION = \d+/, '草稿缺少版本标识')
|
assert.match(draftSource, /DATA_PROCESS_DRAFT_SCHEMA_VERSION = \d+/, '草稿缺少版本标识')
|
||||||
assert.match(viewSource, /schemaVersion:\s*DRAFT_SCHEMA_VERSION/, '草稿快照没有写入版本标识')
|
assert.match(draftSource, /schemaVersion:\s*DATA_PROCESS_DRAFT_SCHEMA_VERSION/, '草稿快照没有写入版本标识')
|
||||||
assert.match(viewSource, /requiresPreviewMigration/, '旧草稿没有失效旧切片预览')
|
assert.match(draftSource, /bindings\.goToStep\('create'\)/, '恢复配置后应回到安全的创建步骤')
|
||||||
assert.doesNotMatch(
|
|
||||||
viewSource,
|
|
||||||
/snapshot\.unstructuredOptions\s*&&\s*!requiresPreviewMigration/,
|
|
||||||
'草稿版本迁移不应丢失仍受支持的非结构化配置',
|
|
||||||
)
|
|
||||||
assert.match(viewSource, /const restoredUnstructuredOptions = snapshot\.unstructuredOptions/, '旧草稿没有通过白名单恢复仍受支持的配置')
|
|
||||||
assert.match(viewSource, /JSON\.stringify\(previewAffectingOptions\(\)\)/, '影响切分的非结构化配置没有纳入预览失效判断')
|
assert.match(viewSource, /JSON\.stringify\(previewAffectingOptions\(\)\)/, '影响切分的非结构化配置没有纳入预览失效判断')
|
||||||
|
|
||||||
const previewOptionsStart = viewSource.indexOf('function previewAffectingOptions()')
|
const previewOptionsStart = viewSource.indexOf('function previewAffectingOptions()')
|
||||||
@@ -810,10 +851,10 @@ assert.match(sourceUploadSource, /@click="emit\('remove-file', file\.uid\)"/, '
|
|||||||
const { descriptor } = parseSfc(viewSource, { filename: viewPath })
|
const { descriptor } = parseSfc(viewSource, { filename: viewPath })
|
||||||
const template = descriptor.template?.content || ''
|
const template = descriptor.template?.content || ''
|
||||||
assert.equal((template.match(/class="wizard-primary-action"/g) || []).length, 1, '页面必须只有一个主操作入口')
|
assert.equal((template.match(/class="wizard-primary-action"/g) || []).length, 1, '页面必须只有一个主操作入口')
|
||||||
assert.match(viewSource, /onBeforeUnmount\(stopGenerationTimer\)/, '生成计时器没有在卸载时清理')
|
assert.match(viewSource, /onBeforeUnmount\(\(\) => \{[\s\S]*?stopGenerationTimer\(\)[\s\S]*?clearTimeout\(connectionTimer\)[\s\S]*?clearTimeout\(pullTimer\)/, '生成与外部数据源计时器没有在卸载时清理')
|
||||||
assert.match(viewSource, /function scrollToStepTop/, '步骤切换后没有恢复页面顶部上下文')
|
assert.match(viewSource, /function scrollToStepTop/, '步骤切换后没有恢复页面顶部上下文')
|
||||||
assert.match(viewSource, /nextTick\(scrollToStepTop\)/, '步骤切换没有触发页面滚动复位')
|
assert.match(viewSource, /nextTick\(scrollToStepTop\)/, '步骤切换没有触发页面滚动复位')
|
||||||
assert.match(viewSource, /\.wizard-content\s*\{[\s\S]*min-height:\s*400px/, '第一步内容区必须保留足够高度以显示底部操作栏')
|
assert.match(viewStyleSource, /\.wizard-content\s*\{[\s\S]*min-height:\s*400px/, '第一步内容区必须保留足够高度以显示底部操作栏')
|
||||||
assert.match(
|
assert.match(
|
||||||
layoutSource,
|
layoutSource,
|
||||||
/&:has\(\.create-wizard-layout\)\s*\{[\s\S]*?overflow-y:\s*hidden[\s\S]*?\.page-canvas\s*\{[\s\S]*?flex:\s*1 1 auto[\s\S]*?min-height:\s*0/,
|
/&:has\(\.create-wizard-layout\)\s*\{[\s\S]*?overflow-y:\s*hidden[\s\S]*?\.page-canvas\s*\{[\s\S]*?flex:\s*1 1 auto[\s\S]*?min-height:\s*0/,
|
||||||
|
|||||||
@@ -4,12 +4,24 @@ import ts from 'typescript'
|
|||||||
|
|
||||||
const root = process.cwd()
|
const root = process.cwd()
|
||||||
const previewPath = path.join(root, 'src/views/dataset/DatasetPreviewView.vue')
|
const previewPath = path.join(root, 'src/views/dataset/DatasetPreviewView.vue')
|
||||||
|
const previewComponentsDir = path.join(root, 'src/views/dataset/preview')
|
||||||
|
const previewComponentPaths = [
|
||||||
|
'DatasetVersionBar.vue',
|
||||||
|
'DatasetRecordTable.vue',
|
||||||
|
'DatasetRecordEditorDialog.vue',
|
||||||
|
'DatasetRawPreview.vue',
|
||||||
|
].map((name) => path.join(previewComponentsDir, name))
|
||||||
const apiPath = path.join(root, 'src/api/modules/dataset.ts')
|
const apiPath = path.join(root, 'src/api/modules/dataset.ts')
|
||||||
const adapterPath = path.join(root, 'src/mock/adapter.ts')
|
const adapterPath = path.join(root, 'src/mock/adapter.ts')
|
||||||
const mockPath = path.join(root, 'src/mock/data.ts')
|
const mockPath = path.join(root, 'src/mock/data.ts')
|
||||||
const recordsPath = path.join(root, 'src/views/dataset/datasetRecords.ts')
|
const recordsPath = path.join(root, 'src/views/dataset/datasetRecords.ts')
|
||||||
const versionsPath = path.join(root, 'src/mock/datasetVersions.ts')
|
const versionsPath = path.join(root, 'src/mock/datasetVersions.ts')
|
||||||
const source = fs.readFileSync(previewPath, 'utf8')
|
const source = fs.readFileSync(previewPath, 'utf8')
|
||||||
|
const previewComponentSources = previewComponentPaths.map((componentPath) => {
|
||||||
|
expect(fs.existsSync(componentPath), `缺少数据集预览叶子组件:${path.basename(componentPath)}`)
|
||||||
|
return fs.readFileSync(componentPath, 'utf8')
|
||||||
|
})
|
||||||
|
const previewSurfaceSource = [source, ...previewComponentSources].join('\n')
|
||||||
const apiSource = fs.readFileSync(apiPath, 'utf8')
|
const apiSource = fs.readFileSync(apiPath, 'utf8')
|
||||||
const adapterSource = fs.readFileSync(adapterPath, 'utf8')
|
const adapterSource = fs.readFileSync(adapterPath, 'utf8')
|
||||||
const mockSource = fs.readFileSync(mockPath, 'utf8')
|
const mockSource = fs.readFileSync(mockPath, 'utf8')
|
||||||
@@ -35,33 +47,55 @@ function expect(condition, message) {
|
|||||||
if (!condition) throw new Error(message)
|
if (!condition) throw new Error(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expect(source.split('\n').length < 800, 'DatasetPreviewView.vue 应拆分到 800 行以内')
|
||||||
|
for (const componentName of ['DatasetVersionBar', 'DatasetRecordTable', 'DatasetRecordEditorDialog', 'DatasetRawPreview']) {
|
||||||
|
expect(source.includes(`import ${componentName}`), `主页面未导入叶子组件:${componentName}`)
|
||||||
|
expect(source.includes(`<${componentName}`), `主页面未挂载叶子组件:${componentName}`)
|
||||||
|
}
|
||||||
expect(source.includes('class="preview-workspace"'), '详情页应提供数据文件工作区')
|
expect(source.includes('class="preview-workspace"'), '详情页应提供数据文件工作区')
|
||||||
expect(!source.includes('class="file-pane"'), '单文件数据集详情不应展示文件选择侧栏')
|
expect(!source.includes('class="file-pane"'), '单文件数据集详情不应展示文件选择侧栏')
|
||||||
expect(source.includes('class="code-line"'), '内容查看器应提供逐行展示')
|
expect(previewSurfaceSource.includes('class="code-line"'), '内容查看器应提供逐行展示')
|
||||||
expect(source.includes('class="line-number"'), '内容查看器应显示行号')
|
expect(previewSurfaceSource.includes('class="line-number"'), '内容查看器应显示行号')
|
||||||
expect(source.includes('previewLoading'), '切换文件时应提供独立加载状态')
|
expect(source.includes('previewLoading'), '切换文件时应提供独立加载状态')
|
||||||
expect(source.includes('previewError'), '内容加载失败时应提供错误状态')
|
expect(source.includes('previewError'), '内容加载失败时应提供错误状态')
|
||||||
expect(source.includes('class="records-viewer"'), '详情页应将结构化文件展示为样本列表')
|
expect(previewSurfaceSource.includes('class="records-viewer"'), '详情页应将结构化文件展示为样本列表')
|
||||||
expect(source.includes('class="record-table"'), '样本数据应使用企业级表格展示')
|
expect(previewSurfaceSource.includes('class="record-table"'), '样本数据应使用企业级表格展示')
|
||||||
expect(source.includes('fixed="right"'), '逐条编辑操作列应固定在表格右侧')
|
expect(previewSurfaceSource.includes('fixed="right"'), '逐条编辑操作列应固定在表格右侧')
|
||||||
expect(source.includes('v-for="fieldKey in tableFieldKeys"'), '企业表格应根据数据结构动态生成字段列')
|
expect(previewSurfaceSource.includes('v-for="fieldKey in tableFieldKeys"'), '企业表格应根据数据结构动态生成字段列')
|
||||||
expect(source.includes('openRecordEditor(asDatasetRecord(row))'), '每条样本应提供独立编辑入口')
|
expect(previewSurfaceSource.includes("emit('edit', asDatasetRecord(row))"), '每条样本应向主页面发送编辑事件')
|
||||||
expect(source.includes('暂存修改'), '单条编辑应先暂存到当前页面')
|
expect(previewSurfaceSource.includes('暂存修改'), '单条编辑应先暂存到当前页面')
|
||||||
expect(source.includes('hasPendingVersionChanges && isViewingActiveVersion'), '存在暂存修改时才应显示保存版本按钮')
|
expect(source.includes('hasPendingVersionChanges && isViewingActiveVersion'), '存在暂存修改时才应显示保存版本按钮')
|
||||||
expect(source.includes('保存版本'), '文件工具栏应提供保存版本按钮')
|
expect(source.includes('保存版本'), '文件工具栏应提供保存版本按钮')
|
||||||
expect(source.includes('baseVersionContent'), '页面应区分已保存版本与待保存工作副本')
|
expect(source.includes('baseVersionContent'), '页面应区分已保存版本与待保存工作副本')
|
||||||
expect(source.includes('class="version-control-bar"'), '详情页应提供独立版本控制区')
|
expect(previewSurfaceSource.includes('class="version-control-bar"'), '详情页应提供独立版本控制区')
|
||||||
expect(source.includes('设为当前版本'), '历史版本应支持显式切换为当前版本')
|
expect(previewSurfaceSource.includes('设为当前版本'), '历史版本应支持显式切换为当前版本')
|
||||||
expect(source.includes('历史版本(只读)'), '历史版本应明确展示只读状态')
|
expect(previewSurfaceSource.includes('历史版本(只读)'), '历史版本应明确展示只读状态')
|
||||||
expect(source.includes('loadedVersionId.value'), '下载和展示应绑定正在查看的具体版本')
|
expect(source.includes('loadedVersionId.value'), '下载和展示应绑定正在查看的具体版本')
|
||||||
expect(source.includes('versionRequestId'), '快速切换历史版本时应防止旧响应覆盖新内容')
|
expect(source.includes('versionRequestId'), '快速切换历史版本时应防止旧响应覆盖新内容')
|
||||||
expect(source.includes('v-model:current-page="currentPage"'), '样本列表应支持分页浏览')
|
expect(previewSurfaceSource.includes('v-model:current-page="currentPage"'), '样本列表应支持分页浏览')
|
||||||
expect(!source.includes('class="content-editor"'), '详情页不应继续提供整文件编辑器')
|
expect(!source.includes('class="content-editor"'), '详情页不应继续提供整文件编辑器')
|
||||||
expect(source.includes('saveRecord'), '逐条编辑器应提供单条保存动作')
|
expect(source.includes('saveRecord'), '逐条编辑器应提供单条保存动作')
|
||||||
expect(source.includes('hasUnsavedChanges'), '在线编辑器应跟踪未保存修改')
|
expect(source.includes('hasUnsavedChanges'), '在线编辑器应跟踪未保存修改')
|
||||||
expect(source.includes('onBeforeRouteLeave'), '离开页面时应保护未保存修改')
|
expect(source.includes('onBeforeRouteLeave'), '离开页面时应保护未保存修改')
|
||||||
expect(source.includes("event.key.toLowerCase() === 's'"), '在线编辑器应支持快捷键保存')
|
expect(previewSurfaceSource.includes("event.key.toLowerCase() === 's'"), '在线编辑器应支持快捷键保存')
|
||||||
expect(source.includes('loadVersions(selectedFile)'), '版本内容加载失败后应支持重新加载')
|
expect(source.includes('loadVersions(selectedFile)'), '版本内容加载失败后应支持重新加载')
|
||||||
|
expect(source.includes('function resetRecordEditor()'), '主页面应提供统一的编辑器状态清理函数')
|
||||||
|
const resetEditorStart = source.indexOf('function resetRecordEditor()')
|
||||||
|
const updateFieldStart = source.indexOf('function updateEditField', resetEditorStart)
|
||||||
|
const resetEditorSource = source.slice(resetEditorStart, updateFieldStart)
|
||||||
|
for (const marker of [
|
||||||
|
'editorVisible.value = false',
|
||||||
|
'editingRecord.value = null',
|
||||||
|
'editFields.value = []',
|
||||||
|
"rawDraft.value = ''",
|
||||||
|
"originalDraft.value = ''",
|
||||||
|
]) {
|
||||||
|
expect(resetEditorSource.includes(marker), `编辑器状态清理不完整:${marker}`)
|
||||||
|
}
|
||||||
|
const versionChangeStart = source.indexOf('async function handleViewedVersionChange')
|
||||||
|
const activateVersionStart = source.indexOf('async function activateViewedVersion', versionChangeStart)
|
||||||
|
const versionChangeSource = source.slice(versionChangeStart, activateVersionStart)
|
||||||
|
expect(versionChangeSource.includes('resetRecordEditor()'), '成功切换版本后必须关闭并清空旧编辑器状态')
|
||||||
expect(!source.includes('handleDownloadAll'), '页面不应保留整包下载逻辑')
|
expect(!source.includes('handleDownloadAll'), '页面不应保留整包下载逻辑')
|
||||||
expect(!source.includes('handleDelete'), '页面不应保留删除逻辑')
|
expect(!source.includes('handleDelete'), '页面不应保留删除逻辑')
|
||||||
expect(!source.includes('router.back()'), '页面不应保留页头返回逻辑')
|
expect(!source.includes('router.back()'), '页面不应保留页头返回逻辑')
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import { readFileSync } from 'node:fs'
|
import { readFileSync } from 'node:fs'
|
||||||
import { resolve } from 'node:path'
|
import { resolve } from 'node:path'
|
||||||
import { fileURLToPath } from 'node:url'
|
import { fileURLToPath } from 'node:url'
|
||||||
|
import ts from 'typescript'
|
||||||
|
|
||||||
const root = resolve(fileURLToPath(new URL('..', import.meta.url)))
|
const root = resolve(fileURLToPath(new URL('..', import.meta.url)))
|
||||||
const source = readFileSync(resolve(root, 'src/views/fine-tune/FineTuneCreateView.vue'), 'utf8')
|
const source = readFileSync(resolve(root, 'src/views/fine-tune/FineTuneCreateView.vue'), 'utf8')
|
||||||
const modelDialogSource = readFileSync(resolve(root, 'src/components/ModelSelectDialog.vue'), 'utf8')
|
const modelDialogSource = readFileSync(resolve(root, 'src/components/ModelSelectDialog.vue'), 'utf8')
|
||||||
|
const formModelSource = readFileSync(resolve(root, 'src/views/fine-tune/fineTuneFormModel.ts'), 'utf8')
|
||||||
|
|
||||||
function assert(condition, message) {
|
function assert(condition, message) {
|
||||||
if (!condition) {
|
if (!condition) {
|
||||||
@@ -24,11 +26,32 @@ assert(modelDialogSource.includes('width="860px"'), 'Model dialog should use a c
|
|||||||
assert(modelDialogSource.includes('model-series-list'), 'Model dialog should include a model series list column')
|
assert(modelDialogSource.includes('model-series-list'), 'Model dialog should include a model series list column')
|
||||||
assert(modelDialogSource.includes('model-version-list'), 'Model dialog should include a snapshot/version list column')
|
assert(modelDialogSource.includes('model-version-list'), 'Model dialog should include a snapshot/version list column')
|
||||||
assert(modelDialogSource.includes('handleConfirm'), 'Model dialog should confirm the selected model before updating the form')
|
assert(modelDialogSource.includes('handleConfirm'), 'Model dialog should confirm the selected model before updating the form')
|
||||||
assert(source.includes("auto_merge: false"), 'Auto merge should default to disabled')
|
assert(formModelSource.includes('auto_merge: false'), 'Auto merge should default to disabled')
|
||||||
assert(source.includes('v-if="form.train_type === \'SFT\'"'), 'Merge model settings should only be visible for SFT')
|
assert(source.includes('v-if="form.train_type === \'SFT\'"'), 'Merge model settings should only be visible for SFT')
|
||||||
assert(source.includes('content-position="left">合并模型'), 'SFT form should include a merge model section below data configuration')
|
assert(source.includes('content-position="left">合并模型'), 'SFT form should include a merge model section below data configuration')
|
||||||
assert(source.includes('v-model="form.auto_merge"'), 'Merge model section should provide an auto merge selector')
|
assert(source.includes('v-model="form.auto_merge"'), 'Merge model section should provide an auto merge selector')
|
||||||
assert(source.includes('label="自动合并权重并保存"'), 'Auto merge selector should use a clear visible label')
|
assert(source.includes('label="自动合并权重并保存"'), 'Auto merge selector should use a clear visible label')
|
||||||
assert((source.match(/auto_merge: form\.train_type === 'SFT' && form\.auto_merge/g) || []).length === 2, 'Auto merge should be sent for SFT when creating and starting the task')
|
assert(formModelSource.includes("auto_merge: form.train_type === 'SFT' && form.auto_merge"), 'Auto merge should be normalized by the shared payload builder')
|
||||||
|
assert(source.includes('const payload = buildFineTunePayload(form, selectedGpus.value)'), 'Create and start should share one normalized payload')
|
||||||
|
assert(source.includes('startFineTune({ ...payload, task_id: taskId })'), 'Start request should reuse the normalized payload')
|
||||||
|
assert(source.includes('Object.assign(form, DEFAULT_TRAINING_PARAMS)'), 'Reset should reuse the canonical defaults')
|
||||||
|
assert(!source.includes('const taskData = {'), 'The duplicated create payload should be removed')
|
||||||
|
assert(!source.includes('const createRes: any'), 'Create response should use the API return type')
|
||||||
|
assert(!source.includes('(check as any).exists'), 'Name-check response should use its API return type')
|
||||||
|
assert(source.includes('任务名校验失败'), 'Name-check failures should be visible and block submission')
|
||||||
|
|
||||||
|
const runnableSource = ts.transpileModule(
|
||||||
|
formModelSource.replace("import type { FineTuneStartPayload, FineTuneTask } from '@/types'", ''),
|
||||||
|
{ compilerOptions: { module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2022 } },
|
||||||
|
).outputText
|
||||||
|
const model = await import(`data:text/javascript;base64,${Buffer.from(runnableSource).toString('base64')}`)
|
||||||
|
const defaults = model.createDefaultFineTuneForm()
|
||||||
|
const customized = { ...defaults, train_type: 'DPO', train_method: 'full', auto_merge: true, quantization_bit: 4 }
|
||||||
|
const payload = model.buildFineTunePayload(customized, [0, 2])
|
||||||
|
assert(payload.auto_merge === false, 'Non-SFT tasks must never enable auto merge')
|
||||||
|
assert(payload.quantization_bit === 0, 'Full fine-tuning must never send QLoRA quantization')
|
||||||
|
assert(payload.gpus.join(',') === '0,2', 'Selected GPUs should be preserved in the shared payload')
|
||||||
|
const resetDefaults = { ...model.DEFAULT_TRAINING_PARAMS }
|
||||||
|
assert(resetDefaults.lora_alpha === defaults.lora_alpha, 'Reset and initial defaults must share LoRA values')
|
||||||
|
|
||||||
console.log('fine-tune create UI regression checks passed')
|
console.log('fine-tune create UI regression checks passed')
|
||||||
|
|||||||
@@ -6,11 +6,12 @@ import { parse as parseTemplate } from '@vue/compiler-dom'
|
|||||||
import { parse as parseSfc } from '@vue/compiler-sfc'
|
import { parse as parseSfc } from '@vue/compiler-sfc'
|
||||||
|
|
||||||
const scriptDir = path.dirname(fileURLToPath(import.meta.url))
|
const scriptDir = path.dirname(fileURLToPath(import.meta.url))
|
||||||
const [globalStyles, routerSource, mainLayoutSource, trainingLogSource, fineTuneCreateSource] = await Promise.all([
|
const [globalStyles, routerSource, mainLayoutSource, trainingLogSource, trainingOverviewSource, fineTuneCreateSource] = await Promise.all([
|
||||||
readFile(path.resolve(scriptDir, '../src/styles/index.scss'), 'utf8'),
|
readFile(path.resolve(scriptDir, '../src/styles/index.scss'), 'utf8'),
|
||||||
readFile(path.resolve(scriptDir, '../src/router/index.ts'), 'utf8'),
|
readFile(path.resolve(scriptDir, '../src/router/index.ts'), 'utf8'),
|
||||||
readFile(path.resolve(scriptDir, '../src/layouts/MainLayout.vue'), 'utf8'),
|
readFile(path.resolve(scriptDir, '../src/layouts/MainLayout.vue'), 'utf8'),
|
||||||
readFile(path.resolve(scriptDir, '../src/views/system/TrainingLogView.vue'), 'utf8'),
|
readFile(path.resolve(scriptDir, '../src/views/system/TrainingLogView.vue'), 'utf8'),
|
||||||
|
readFile(path.resolve(scriptDir, '../src/views/system/training-log/TrainingTaskOverview.vue'), 'utf8'),
|
||||||
readFile(path.resolve(scriptDir, '../src/views/fine-tune/FineTuneCreateView.vue'), 'utf8'),
|
readFile(path.resolve(scriptDir, '../src/views/fine-tune/FineTuneCreateView.vue'), 'utf8'),
|
||||||
])
|
])
|
||||||
|
|
||||||
@@ -70,8 +71,10 @@ const selfSurfaceRoutes = [
|
|||||||
'fine-tune',
|
'fine-tune',
|
||||||
'model-eval',
|
'model-eval',
|
||||||
'model-inference',
|
'model-inference',
|
||||||
|
'model-inference/chat/:id',
|
||||||
'model-manage',
|
'model-manage',
|
||||||
'data-process',
|
'data-process',
|
||||||
|
'data-process/create',
|
||||||
'dataset',
|
'dataset',
|
||||||
]
|
]
|
||||||
for (const routePath of selfSurfaceRoutes) {
|
for (const routePath of selfSurfaceRoutes) {
|
||||||
@@ -138,8 +141,8 @@ assert.doesNotMatch(
|
|||||||
const layoutContentBlock = extractCssBlock(mainLayoutStyle, '.layout-content')
|
const layoutContentBlock = extractCssBlock(mainLayoutStyle, '.layout-content')
|
||||||
assert.match(layoutContentBlock, /background-color:\s*var\(--app-shell-bg\);/, '主内容区未使用灰色外层背景')
|
assert.match(layoutContentBlock, /background-color:\s*var\(--app-shell-bg\);/, '主内容区未使用灰色外层背景')
|
||||||
|
|
||||||
const pageCanvasBlock = extractCssBlock(mainLayoutStyle, '.page-canvas')
|
const pageCanvasBlock = extractCssBlock(mainLayoutStyle, '\n.page-canvas {')
|
||||||
assert.match(pageCanvasBlock, /min-height:\s*100%;/, '白色页面画布没有铺满可用高度')
|
assert.match(pageCanvasBlock, /flex:\s*1 0 auto;/, '白色页面画布没有铺满可用高度')
|
||||||
assert.match(pageCanvasBlock, /padding:\s*24px;/, '白色页面画布缺少统一内容内边距')
|
assert.match(pageCanvasBlock, /padding:\s*24px;/, '白色页面画布缺少统一内容内边距')
|
||||||
assert.match(pageCanvasBlock, /border-radius:\s*16px;/, '白色页面画布圆角与参考不一致')
|
assert.match(pageCanvasBlock, /border-radius:\s*16px;/, '白色页面画布圆角与参考不一致')
|
||||||
assert.match(pageCanvasBlock, /background-color:\s*var\(--app-page-bg\);/, '全局页面画布未使用白色背景')
|
assert.match(pageCanvasBlock, /background-color:\s*var\(--app-page-bg\);/, '全局页面画布未使用白色背景')
|
||||||
@@ -174,7 +177,9 @@ assert.match(rootPageCardBlock, /background-color:\s*transparent;/, '页面根
|
|||||||
assert.match(rootPageCardBlock, /border-radius:\s*0\s*!important;/, '页面根卡片仍形成第二层圆角边界')
|
assert.match(rootPageCardBlock, /border-radius:\s*0\s*!important;/, '页面根卡片仍形成第二层圆角边界')
|
||||||
assert.match(rootPageCardBlock, /box-shadow:\s*none\s*!important;/, '页面根卡片仍形成重复卡片层级')
|
assert.match(rootPageCardBlock, /box-shadow:\s*none\s*!important;/, '页面根卡片仍形成重复卡片层级')
|
||||||
|
|
||||||
const trainingLogStyle = parseSfc(trainingLogSource).descriptor.styles.map((item) => item.content).join('\n')
|
const trainingLogStyle = [trainingLogSource, trainingOverviewSource]
|
||||||
|
.flatMap((source) => parseSfc(source).descriptor.styles.map((item) => item.content))
|
||||||
|
.join('\n')
|
||||||
const businessSurfaceBlock = extractCssBlock(trainingLogStyle, '.profile-section,\n.runtime-panel')
|
const businessSurfaceBlock = extractCssBlock(trainingLogStyle, '.profile-section,\n.runtime-panel')
|
||||||
assert.match(
|
assert.match(
|
||||||
businessSurfaceBlock,
|
businessSurfaceBlock,
|
||||||
|
|||||||
@@ -2,17 +2,35 @@ import assert from 'node:assert/strict'
|
|||||||
import { readFile } from 'node:fs/promises'
|
import { readFile } from 'node:fs/promises'
|
||||||
import { fileURLToPath } from 'node:url'
|
import { fileURLToPath } from 'node:url'
|
||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
|
import ts from 'typescript'
|
||||||
import { parse as parseTemplate } from '@vue/compiler-dom'
|
import { parse as parseTemplate } from '@vue/compiler-dom'
|
||||||
import { parse as parseSfc } from '@vue/compiler-sfc'
|
import { parse as parseSfc } from '@vue/compiler-sfc'
|
||||||
|
|
||||||
const scriptDir = path.dirname(fileURLToPath(import.meta.url))
|
const scriptDir = path.dirname(fileURLToPath(import.meta.url))
|
||||||
const viewPath = path.resolve(scriptDir, '../src/views/system/TrainingLogView.vue')
|
const viewPath = path.resolve(scriptDir, '../src/views/system/TrainingLogView.vue')
|
||||||
const source = await readFile(viewPath, 'utf8')
|
const overviewPath = path.resolve(scriptDir, '../src/views/system/training-log/TrainingTaskOverview.vue')
|
||||||
|
const modelPath = path.resolve(scriptDir, '../src/views/system/training-log/trainingLogModel.ts')
|
||||||
|
const [source, overviewSource, modelSource] = await Promise.all([
|
||||||
|
readFile(viewPath, 'utf8'),
|
||||||
|
readFile(overviewPath, 'utf8'),
|
||||||
|
readFile(modelPath, 'utf8'),
|
||||||
|
])
|
||||||
const { descriptor } = parseSfc(source, { filename: viewPath })
|
const { descriptor } = parseSfc(source, { filename: viewPath })
|
||||||
const template = descriptor.template?.content || ''
|
const { descriptor: overviewDescriptor } = parseSfc(overviewSource, { filename: overviewPath })
|
||||||
const style = descriptor.styles.map((item) => item.content).join('\n')
|
const template = [descriptor.template?.content, overviewDescriptor.template?.content].filter(Boolean).join('\n')
|
||||||
|
const viewStyle = descriptor.styles.map((item) => item.content).join('\n')
|
||||||
|
const overviewStyle = overviewDescriptor.styles.map((item) => item.content).join('\n')
|
||||||
|
const style = `${viewStyle}\n${overviewStyle}`
|
||||||
const templateAst = parseTemplate(template)
|
const templateAst = parseTemplate(template)
|
||||||
|
|
||||||
|
const modelModuleCode = ts.transpileModule(modelSource, {
|
||||||
|
compilerOptions: { module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2022 },
|
||||||
|
}).outputText
|
||||||
|
const {
|
||||||
|
parseTrainingLog,
|
||||||
|
resolveTrainingLogFile,
|
||||||
|
} = await import(`data:text/javascript;base64,${Buffer.from(modelModuleCode).toString('base64')}`)
|
||||||
|
|
||||||
function findElements(node, predicate, result = []) {
|
function findElements(node, predicate, result = []) {
|
||||||
if (node?.type === 1 && predicate(node)) result.push(node)
|
if (node?.type === 1 && predicate(node)) result.push(node)
|
||||||
for (const child of node?.children || []) findElements(child, predicate, result)
|
for (const child of node?.children || []) findElements(child, predicate, result)
|
||||||
@@ -50,41 +68,71 @@ function extractCssBlock(css, marker) {
|
|||||||
assert.fail(`样式规则缺少右花括号:${marker}`)
|
assert.fail(`样式规则缺少右花括号:${marker}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
function relativeLuminance(hex) {
|
const logFiles = [
|
||||||
const channels = hex
|
{ file: 'first_pid111.log', name: 'first-task', size: '1 KB', pid: 111 },
|
||||||
.replace('#', '')
|
{ file: 'target_pid222.log', name: 'target-task', size: '1 KB', pid: 222 },
|
||||||
.match(/.{2}/g)
|
]
|
||||||
.map((channel) => Number.parseInt(channel, 16) / 255)
|
assert.equal(
|
||||||
.map((value) => (value <= 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4))
|
resolveTrainingLogFile(logFiles, { process_id: 222, name: 'target-task' })?.file,
|
||||||
return 0.2126 * channels[0] + 0.7152 * channels[1] + 0.0722 * channels[2]
|
'target_pid222.log',
|
||||||
}
|
'训练日志必须按 task.process_id 精确匹配文件 pid,不能只判断两者是否存在',
|
||||||
|
)
|
||||||
|
assert.equal(
|
||||||
|
resolveTrainingLogFile(logFiles, { process_id: 999, name: 'target-task' })?.file,
|
||||||
|
'target_pid222.log',
|
||||||
|
'PID 无匹配时应按任务名回退选择日志',
|
||||||
|
)
|
||||||
|
assert.equal(
|
||||||
|
resolveTrainingLogFile(logFiles, { process_id: 999, name: 'missing-task' }),
|
||||||
|
undefined,
|
||||||
|
'任务无匹配日志时不得静默退回第一份日志',
|
||||||
|
)
|
||||||
|
|
||||||
function contrastRatio(foreground, background) {
|
const parsed = parseTrainingLog([
|
||||||
const lighter = Math.max(relativeLuminance(foreground), relativeLuminance(background))
|
"INFO {'epoch': .5, 'learning_rate': 1.2E-5, 'grad_norm': -2.5e+0, 'loss': +3.25}",
|
||||||
const darker = Math.min(relativeLuminance(foreground), relativeLuminance(background))
|
'***** train metrics *****',
|
||||||
return (lighter + 0.05) / (darker + 0.05)
|
'train_runtime = 1.7852e3',
|
||||||
}
|
"'train_loss': -3.42e-1",
|
||||||
|
'epoch: 1.0',
|
||||||
|
'***** train metrics end *****',
|
||||||
|
].join('\n'))
|
||||||
|
assert.deepEqual(parsed.metrics.loss, [3.25], '指标解析应允许字段乱序和带符号数值')
|
||||||
|
assert.deepEqual(parsed.metrics.gradNorm, [-2.5], '梯度范数应支持科学计数法')
|
||||||
|
assert.deepEqual(parsed.metrics.lr, [1.2e-5], '学习率应支持大小写科学计数法')
|
||||||
|
assert.deepEqual(
|
||||||
|
parsed.summary,
|
||||||
|
{ epoch: '1.0', trainLoss: '-3.42e-1', runtime: '1.7852e3' },
|
||||||
|
'训练汇总应同时支持等号、冒号、可选引号和科学计数法',
|
||||||
|
)
|
||||||
|
assert.deepEqual(
|
||||||
|
parseTrainingLog('普通日志,无训练指标').summary,
|
||||||
|
{ epoch: '', trainLoss: '', runtime: '' },
|
||||||
|
'每次解析必须返回全新的空汇总,避免保留上一份日志的旧值',
|
||||||
|
)
|
||||||
|
assert.match(
|
||||||
|
source,
|
||||||
|
/const currentTask = await loadTask\(\)[\s\S]*?loadLog\(currentTask\)/,
|
||||||
|
'刷新流程必须先加载 task,再使用该 task 选择日志',
|
||||||
|
)
|
||||||
|
assert.match(source, /import \{ getSystemInfo \} from '@\/api\/modules\/system'/, '训练概览必须复用系统 GPU 监控数据源')
|
||||||
|
assert.match(source, /Promise\.all\(\[datasetPromise, loadLog\(currentTask\), loadGpuStatus\(\)\]\)/, 'GPU 状态必须和训练日志一起刷新')
|
||||||
|
assert.match(source, /if \(refreshInFlight\) return/, '轮询刷新必须阻止并发重叠')
|
||||||
|
assert.match(source, /onUnmounted\([\s\S]*?clearInterval\(timer\)/, '组件卸载时必须清理轮询定时器')
|
||||||
|
|
||||||
const overview = findElements(
|
const overview = findElements(
|
||||||
templateAst,
|
templateAst,
|
||||||
(node) => staticAttribute(node, 'class')?.split(/\s+/).includes('overview-layout'),
|
(node) => staticAttribute(node, 'class')?.split(/\s+/).includes('overview-layout'),
|
||||||
)
|
)
|
||||||
assert.equal(overview.length, 1, '双栏任务档案容器必须且只能存在一个')
|
assert.equal(overview.length, 1, '标准任务概况容器必须且只能存在一个')
|
||||||
|
assert.doesNotMatch(overviewSource, /<aside\b/, '任务概况仍保留左右侧栏结构')
|
||||||
for (const expectedClass of ['task-profile', 'dataset-profile', 'runtime-panel', 'parameter-groups']) {
|
assert.doesNotMatch(overviewSource, /<i class="fa\b/, '任务概况仍包含过多装饰性图标')
|
||||||
const matched = findElements(
|
|
||||||
templateAst,
|
|
||||||
(node) => staticAttribute(node, 'class')?.split(/\s+/).includes(expectedClass),
|
|
||||||
)
|
|
||||||
assert.equal(matched.length, 1, `缺少或重复布局结构:${expectedClass}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
const toggleButtons = findElements(
|
const toggleButtons = findElements(
|
||||||
templateAst,
|
templateAst,
|
||||||
(node) => node.tag === 'button'
|
(node) => node.tag === 'el-button'
|
||||||
&& staticAttribute(node, 'class')?.split(/\s+/).includes('params-toggle-button'),
|
&& staticAttribute(node, 'class')?.split(/\s+/).includes('params-toggle-button'),
|
||||||
)
|
)
|
||||||
assert.equal(toggleButtons.length, 1, '参数折叠必须使用唯一的原生 button')
|
assert.equal(toggleButtons.length, 1, '参数折叠必须使用唯一的标准按钮')
|
||||||
|
|
||||||
const toggleButton = toggleButtons[0]
|
const toggleButton = toggleButtons[0]
|
||||||
assert.equal(boundExpression(toggleButton, 'aria-expanded'), 'paramsExpanded', '折叠按钮未绑定 aria-expanded')
|
assert.equal(boundExpression(toggleButton, 'aria-expanded'), 'paramsExpanded', '折叠按钮未绑定 aria-expanded')
|
||||||
@@ -96,33 +144,80 @@ const controlledRegions = findElements(
|
|||||||
)
|
)
|
||||||
assert.equal(controlledRegions.length, 1, 'aria-controls 指向的参数内容区域不存在或重复')
|
assert.equal(controlledRegions.length, 1, 'aria-controls 指向的参数内容区域不存在或重复')
|
||||||
|
|
||||||
|
const pageTitleIndex = source.indexOf('id="task-page-title"')
|
||||||
|
const summaryCardIndex = source.indexOf('id="training-overview-title"')
|
||||||
|
const taskOverviewIndex = source.indexOf('<TrainingTaskOverview')
|
||||||
|
assert.notEqual(pageTitleIndex, -1, '页面缺少独立的训练任务标题')
|
||||||
|
assert.ok(pageTitleIndex < summaryCardIndex, '训练任务标题必须出现在训练概览之前')
|
||||||
|
assert.ok(summaryCardIndex < taskOverviewIndex, '训练概览必须出现在任务信息之前')
|
||||||
|
assert.equal((source.match(/<h1\b/g) || []).length, 1, '训练详情页必须且只能有一个一级标题')
|
||||||
|
assert.doesNotMatch(overviewSource, /<h1\b/, '任务信息卡片不得重复渲染页面一级标题')
|
||||||
|
assert.ok(overviewSource.includes('title="任务信息"'), '任务详情卡片缺少明确的“任务信息”标题')
|
||||||
|
|
||||||
const firstChartIndex = template.indexOf('<!-- 训练曲线 -->')
|
const firstChartIndex = template.indexOf('<!-- 训练曲线 -->')
|
||||||
assert.notEqual(firstChartIndex, -1, '未找到训练曲线边界,无法限定首屏检查范围')
|
assert.notEqual(firstChartIndex, -1, '未找到训练曲线边界,无法限定首屏检查范围')
|
||||||
assert.equal(
|
assert.ok(template.includes('training-progress-panel'), '训练概览缺少独立的主进度区域')
|
||||||
template.slice(0, firstChartIndex).includes('<el-descriptions'),
|
assert.ok(template.includes('training-metric-grid'), '训练概览缺少次级训练指标摘要')
|
||||||
false,
|
assert.ok(template.includes('gpu-device-list'), '训练概览缺少紧凑的 GPU 设备列表')
|
||||||
'任务概览、数据集和训练参数仍使用带表格感的 el-descriptions',
|
assert.ok(template.includes('gpu-list-header'), 'GPU 设备列表缺少企业表格式列标题')
|
||||||
|
assert.ok(template.includes('gpu-device-row'), 'GPU 设备列表缺少统一行结构')
|
||||||
|
assert.doesNotMatch(template, /training-summary-strip|gpu-device-card/, '训练概览仍保留同级宫格或 GPU 嵌套卡片结构')
|
||||||
|
assert.ok(template.includes('id="training-overview-title"'), '训练概览缺少可访问的卡片标题')
|
||||||
|
assert.ok(
|
||||||
|
template.indexOf('id="training-overview-title"') < template.indexOf('<TrainingTaskOverview'),
|
||||||
|
'训练概览必须位于任务档案之前,成为页面第一块内容',
|
||||||
)
|
)
|
||||||
|
assert.ok(
|
||||||
|
template.indexOf('training-progress-panel') < template.indexOf('training-metric-grid')
|
||||||
|
&& template.indexOf('training-metric-grid') < template.indexOf('gpu-device-list'),
|
||||||
|
'训练概览必须按主进度、次级指标、GPU 设备列表的顺序展示',
|
||||||
|
)
|
||||||
|
assert.ok(template.includes('id="gpu-monitor-title"'), '训练概览缺少 GPU 运行状态区域')
|
||||||
|
assert.ok(template.includes('计算利用率'), 'GPU 运行状态缺少计算利用率')
|
||||||
|
assert.ok(template.includes('显存占用'), 'GPU 运行状态缺少显存占用')
|
||||||
|
assert.ok(template.includes('每 5 秒刷新'), 'GPU 运行状态缺少刷新频率说明')
|
||||||
|
assert.ok(template.includes(':aria-label="`GPU ${item.index} 计算利用率'), 'GPU 强度条缺少可访问说明')
|
||||||
|
assert.match(source, /const GPU_PREVIEW_LIMIT = 4/, '多 GPU 默认预览数量必须限制为 4 张')
|
||||||
|
assert.match(source, /const visibleGpuItems = computed/, '多 GPU 缺少渐进披露列表计算')
|
||||||
|
assert.match(source, /gpuRuntimePriority/, '折叠状态必须优先展示异常和运行中的 GPU')
|
||||||
|
assert.ok(template.includes('v-for="item in visibleGpuItems"'), 'GPU 列表没有使用受控预览数据')
|
||||||
|
assert.ok(template.includes('taskGpuItems.length > GPU_PREVIEW_LIMIT'), 'GPU 数量超过预览上限时没有展开入口')
|
||||||
|
|
||||||
|
const gpuToggleButtons = findElements(
|
||||||
|
templateAst,
|
||||||
|
(node) => node.tag === 'el-button'
|
||||||
|
&& staticAttribute(node, 'class')?.split(/\s+/).includes('gpu-toggle-button'),
|
||||||
|
)
|
||||||
|
assert.equal(gpuToggleButtons.length, 1, '多 GPU 展开控制必须且只能存在一个')
|
||||||
|
assert.equal(boundExpression(gpuToggleButtons[0], 'aria-expanded'), 'gpuExpanded', 'GPU 展开按钮未绑定 aria-expanded')
|
||||||
|
assert.equal(staticAttribute(gpuToggleButtons[0], 'aria-controls'), 'gpu-device-list', 'GPU 展开按钮缺少正确的 aria-controls')
|
||||||
|
assert.ok(template.includes('title="训练曲线"'), '训练曲线没有使用标准 PageCard 标题')
|
||||||
|
assert.ok(template.includes('title="训练日志"'), '训练日志没有使用标准 PageCard 标题')
|
||||||
|
assert.ok(template.includes('每 5 秒刷新'), '训练监控区缺少自动刷新状态说明')
|
||||||
|
assert.ok((template.match(/<el-descriptions\b/g) || []).length >= 3, '任务概况和训练参数没有使用标准详情表格')
|
||||||
|
assert.equal((template.match(/class="chart-section"/g) || []).length, 3, '三组训练曲线没有按上下结构完整展示')
|
||||||
|
assert.doesNotMatch(template, /<el-row\b|<el-col\b/, '训练曲线仍保留左右分栏布局')
|
||||||
|
assert.doesNotMatch(template, /class="chart-card"/, '训练曲线仍存在卡片嵌套')
|
||||||
|
assert.doesNotMatch(template, /summary-metric is-primary/, '训练概览仍保留大块装饰性主色背景')
|
||||||
|
|
||||||
|
for (const selector of ['.summary-card', '.parameters-card', '.metrics-panel', '.log-card']) {
|
||||||
|
const cardBlock = extractCssBlock(style, selector)
|
||||||
|
assert.match(cardBlock, /border-radius:\s*8px/, `${selector} 未统一为 8px 企业卡片圆角`)
|
||||||
|
assert.match(cardBlock, /box-shadow:\s*none/, `${selector} 仍保留不统一的浮层阴影`)
|
||||||
|
}
|
||||||
|
|
||||||
assert.ok(template.includes("task?.output_model_name || '暂未生成'"), '输出模型缺失值文案不正确')
|
assert.ok(template.includes("task?.output_model_name || '暂未生成'"), '输出模型缺失值文案不正确')
|
||||||
assert.ok(template.includes("task?.batch_size ?? '未配置'"), '训练参数缺失值文案不正确')
|
assert.ok(template.includes("task?.batch_size ?? '未配置'"), '训练参数缺失值文案不正确')
|
||||||
|
|
||||||
const media1100 = extractCssBlock(style, '@media (max-width: 1100px)')
|
const overviewLayoutBlock = extractCssBlock(overviewStyle, '.overview-layout')
|
||||||
const overviewAt1100 = extractCssBlock(media1100, '.overview-layout')
|
assert.match(overviewLayoutBlock, /width:\s*100%/, '任务概况没有使用全宽单列布局')
|
||||||
assert.match(overviewAt1100, /grid-template-columns:\s*minmax\(0,\s*1fr\)/, '1100px 断点未将双栏改为单栏')
|
assert.doesNotMatch(overviewLayoutBlock, /grid-template-columns/, '任务档案仍保留左右分栏规则')
|
||||||
|
|
||||||
const media700 = extractCssBlock(style, '@media (max-width: 700px)')
|
const overviewMedia700 = extractCssBlock(overviewStyle, '@media (max-width: 700px)')
|
||||||
for (const selector of ['.dataset-metrics', '.runtime-list', '.parameter-grid']) {
|
assert.ok(overviewMedia700.includes('.task-descriptions'), '700px 断点缺少任务详情表单列规则')
|
||||||
assert.ok(media700.includes(selector), `700px 断点缺少单列规则:${selector}`)
|
assert.match(overviewMedia700, /display:\s*block/, '移动端任务详情表没有转换为单列')
|
||||||
}
|
const viewMedia600 = extractCssBlock(viewStyle, '@media (max-width: 600px)')
|
||||||
assert.match(media700, /grid-template-columns:\s*minmax\(0,\s*1fr\)/, '700px 断点未设置单列网格')
|
assert.ok(viewMedia600.includes('.parameter-descriptions'), '600px 断点缺少训练参数表单列规则')
|
||||||
|
assert.match(viewMedia600, /display:\s*block/, '移动端训练参数表没有转换为单列')
|
||||||
const mutedBlock = extractCssBlock(style, '.is-muted')
|
|
||||||
const mutedColor = mutedBlock.match(/color:\s*(#[0-9a-f]{6})/i)?.[1]
|
|
||||||
assert.ok(mutedColor, '未配置文本缺少明确颜色')
|
|
||||||
assert.ok(
|
|
||||||
contrastRatio(mutedColor, '#ffffff') >= 4.5,
|
|
||||||
`未配置文本颜色 ${mutedColor} 与白色背景对比度不足 4.5:1`,
|
|
||||||
)
|
|
||||||
|
|
||||||
console.log('训练日志详情布局回归检查通过')
|
console.log('训练日志详情布局回归检查通过')
|
||||||
|
|||||||
77
frontend/scripts/regression-training-log-mock.mjs
Normal file
77
frontend/scripts/regression-training-log-mock.mjs
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import { readFile } from 'node:fs/promises'
|
||||||
|
import { fileURLToPath } from 'node:url'
|
||||||
|
import path from 'node:path'
|
||||||
|
|
||||||
|
const scriptDir = path.dirname(fileURLToPath(import.meta.url))
|
||||||
|
const mockDataPath = path.resolve(scriptDir, '../src/mock/data.ts')
|
||||||
|
const mockAdapterPath = path.resolve(scriptDir, '../src/mock/adapter.ts')
|
||||||
|
const modelPath = path.resolve(scriptDir, '../src/views/system/training-log/trainingLogModel.ts')
|
||||||
|
const [mockData, mockAdapter, modelSource] = await Promise.all([
|
||||||
|
readFile(mockDataPath, 'utf8'),
|
||||||
|
readFile(mockAdapterPath, 'utf8'),
|
||||||
|
readFile(modelPath, 'utf8'),
|
||||||
|
])
|
||||||
|
|
||||||
|
function objectFromMarker(source, marker) {
|
||||||
|
const markerIndex = source.indexOf(marker)
|
||||||
|
assert.notEqual(markerIndex, -1, `未找到 Mock 数据标记:${marker}`)
|
||||||
|
const openBrace = source.lastIndexOf('{', markerIndex)
|
||||||
|
assert.notEqual(openBrace, -1, `Mock 数据缺少对象起点:${marker}`)
|
||||||
|
|
||||||
|
let depth = 0
|
||||||
|
for (let index = openBrace; index < source.length; index += 1) {
|
||||||
|
if (source[index] === '{') depth += 1
|
||||||
|
if (source[index] === '}') depth -= 1
|
||||||
|
if (depth === 0) return source.slice(openBrace, index + 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.fail(`Mock 数据缺少对象终点:${marker}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const taskNames = [
|
||||||
|
'finance-sft-001',
|
||||||
|
'legal-sft-002',
|
||||||
|
'medical-cpt-001',
|
||||||
|
'service-dpo-001',
|
||||||
|
'finance-sft-002',
|
||||||
|
'general-sft-001',
|
||||||
|
]
|
||||||
|
const commonTrainingFields = [
|
||||||
|
'output_model_name',
|
||||||
|
'batch_size',
|
||||||
|
'learning_rate',
|
||||||
|
'n_epochs',
|
||||||
|
'save_steps',
|
||||||
|
'lr_scheduler_type',
|
||||||
|
'max_length',
|
||||||
|
'warmup_ratio',
|
||||||
|
'weight_decay',
|
||||||
|
]
|
||||||
|
|
||||||
|
for (const taskName of taskNames) {
|
||||||
|
const task = objectFromMarker(mockData, `name: '${taskName}'`)
|
||||||
|
for (const field of commonTrainingFields) {
|
||||||
|
assert.match(task, new RegExp(`\\b${field}\\s*:`), `${taskName} 缺少训练参数:${field}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (/train_method:\s*'lora'/.test(task)) {
|
||||||
|
for (const field of ['lora_rank', 'lora_alpha', 'lora_dropout']) {
|
||||||
|
assert.match(task, new RegExp(`\\b${field}\\s*:`), `${taskName} 缺少 LoRA 参数:${field}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const medicalTask = objectFromMarker(mockData, "name: 'medical-cpt-001'")
|
||||||
|
assert.match(medicalTask, /\bprocess_id\s*:/, '运行中的医疗训练任务缺少进程 ID')
|
||||||
|
assert.match(mockData, /medical-cpt-001_pid28741\.log/, '医疗训练任务缺少 PID 对应的日志文件')
|
||||||
|
assert.match(mockData, /export const mockTrainingLogContents/, '训练日志没有按文件提供独立 Mock 内容')
|
||||||
|
assert.match(mockData, /Num examples\s*=\s*9,800/, '医疗训练日志缺少样本规模信息')
|
||||||
|
assert.match(mockData, /Total optimization steps\s*=\s*921/, '医疗训练日志缺少真实训练步数信息')
|
||||||
|
assert.match(mockData, /\\'epoch\\':\s*1\.92/, '医疗训练日志的 Epoch 未与 64% 进度对齐')
|
||||||
|
assert.match(mockData, /\\'loss\\':\s*1\.146/, '医疗训练日志缺少当前 Loss 指标')
|
||||||
|
assert.match(mockAdapter, /const file = String\(params\.file/, '训练日志接口没有读取请求中的日志文件名')
|
||||||
|
assert.match(mockAdapter, /mockTrainingLogContents\[file\]/, '训练日志接口没有按请求文件返回对应内容')
|
||||||
|
assert.match(modelSource, /epoch:\s*number\[\]/, '训练指标模型没有保留逐步 Epoch')
|
||||||
|
|
||||||
|
console.log('训练日志 Mock 数据回归检查通过')
|
||||||
15
frontend/scripts/run-regressions.mjs
Normal file
15
frontend/scripts/run-regressions.mjs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { readdir } from 'node:fs/promises'
|
||||||
|
import { pathToFileURL } from 'node:url'
|
||||||
|
import path from 'node:path'
|
||||||
|
|
||||||
|
const scriptsDir = path.resolve(process.cwd(), 'scripts')
|
||||||
|
const regressionScripts = (await readdir(scriptsDir))
|
||||||
|
.filter((file) => file.startsWith('regression-') && file.endsWith('.mjs'))
|
||||||
|
.sort()
|
||||||
|
|
||||||
|
for (const script of regressionScripts) {
|
||||||
|
console.log(`\n▶ ${script}`)
|
||||||
|
await import(pathToFileURL(path.join(scriptsDir, script)).href)
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`\n✅ ${regressionScripts.length} 个前端回归脚本全部通过`)
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { get, post, put, del } from '../request'
|
import { get, post, put, del } from '../request'
|
||||||
import type { FineTuneTask, TrainingProgress } from '@/types'
|
import type { FineTuneStartPayload, FineTuneTask, TrainingProgress } from '@/types'
|
||||||
|
|
||||||
/** 训练任务列表 */
|
/** 训练任务列表 */
|
||||||
export const getFineTuneList = () => get<FineTuneTask[]>('/fine-tune')
|
export const getFineTuneList = () => get<FineTuneTask[]>('/fine-tune')
|
||||||
@@ -16,7 +16,7 @@ export const createFineTune = (data: Partial<FineTuneTask>) =>
|
|||||||
post<{ id: string | number }>('/fine-tune', data)
|
post<{ id: string | number }>('/fine-tune', data)
|
||||||
|
|
||||||
/** 启动训练(第二步) */
|
/** 启动训练(第二步) */
|
||||||
export const startFineTune = (data: any) => post('/fine-tune/start', data)
|
export const startFineTune = (data: FineTuneStartPayload) => post('/fine-tune/start', data)
|
||||||
|
|
||||||
/** 更新训练任务 */
|
/** 更新训练任务 */
|
||||||
export const updateFineTune = (id: string | number, data: Partial<FineTuneTask>) =>
|
export const updateFineTune = (id: string | number, data: Partial<FineTuneTask>) =>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* 拦截所有 API 请求并返回 mock 数据
|
* 拦截所有 API 请求并返回 mock 数据
|
||||||
* 通过 URL + method 路由到对应的 mock 响应
|
* 通过 URL + method 路由到对应的 mock 响应
|
||||||
*/
|
*/
|
||||||
import type { AxiosInstance, AxiosRequestConfig } from 'axios'
|
import type { AxiosAdapter, AxiosInstance, AxiosRequestConfig } from 'axios'
|
||||||
import {
|
import {
|
||||||
mockLoginOk,
|
mockLoginOk,
|
||||||
mockHealth,
|
mockHealth,
|
||||||
@@ -21,6 +21,7 @@ import {
|
|||||||
mockLogFiles,
|
mockLogFiles,
|
||||||
mockTrainingLogFiles,
|
mockTrainingLogFiles,
|
||||||
mockLogContent,
|
mockLogContent,
|
||||||
|
mockTrainingLogContents,
|
||||||
} from './data'
|
} from './data'
|
||||||
import {
|
import {
|
||||||
activateDatasetVersion,
|
activateDatasetVersion,
|
||||||
@@ -164,7 +165,8 @@ async function handleMock(config: AxiosRequestConfig) {
|
|||||||
}
|
}
|
||||||
m = url.match(/^\/dataset-manage\/([^/]+)$/)
|
m = url.match(/^\/dataset-manage\/([^/]+)$/)
|
||||||
if (m && method === 'get') {
|
if (m && method === 'get') {
|
||||||
const found = mockDatasets.find((x) => String(x.id) === m[1])
|
const datasetId = m[1]
|
||||||
|
const found = mockDatasets.find((x) => String(x.id) === datasetId)
|
||||||
return found ? ok(found) : fail('数据集不存在', 404)
|
return found ? ok(found) : fail('数据集不存在', 404)
|
||||||
}
|
}
|
||||||
if (m && (method === 'put' || method === 'delete')) {
|
if (m && (method === 'put' || method === 'delete')) {
|
||||||
@@ -261,7 +263,8 @@ async function handleMock(config: AxiosRequestConfig) {
|
|||||||
}
|
}
|
||||||
m = url.match(/^\/fine-tune\/progress\/([^/]+)$/)
|
m = url.match(/^\/fine-tune\/progress\/([^/]+)$/)
|
||||||
if (m && method === 'get') {
|
if (m && method === 'get') {
|
||||||
const task = mockFineTuneList.find((t) => String(t.id) === m[1])
|
const taskId = m[1]
|
||||||
|
const task = mockFineTuneList.find((t) => String(t.id) === taskId)
|
||||||
if (!task) return fail('任务不存在', 404)
|
if (!task) return fail('任务不存在', 404)
|
||||||
if (task.status === 'running') {
|
if (task.status === 'running') {
|
||||||
return ok({
|
return ok({
|
||||||
@@ -276,7 +279,8 @@ async function handleMock(config: AxiosRequestConfig) {
|
|||||||
}
|
}
|
||||||
m = url.match(/^\/fine-tune\/([^/]+)$/)
|
m = url.match(/^\/fine-tune\/([^/]+)$/)
|
||||||
if (m && method === 'get') {
|
if (m && method === 'get') {
|
||||||
const found = mockFineTuneList.find((x) => String(x.id) === m[1])
|
const taskId = m[1]
|
||||||
|
const found = mockFineTuneList.find((x) => String(x.id) === taskId)
|
||||||
return found ? ok(found) : fail('任务不存在', 404)
|
return found ? ok(found) : fail('任务不存在', 404)
|
||||||
}
|
}
|
||||||
m = url.match(/^\/fine-tune\/stop\/([^/]+)$/)
|
m = url.match(/^\/fine-tune\/stop\/([^/]+)$/)
|
||||||
@@ -296,7 +300,8 @@ async function handleMock(config: AxiosRequestConfig) {
|
|||||||
}
|
}
|
||||||
m = url.match(/^\/model-compare\/([^/]+)$/)
|
m = url.match(/^\/model-compare\/([^/]+)$/)
|
||||||
if (m && method === 'get') {
|
if (m && method === 'get') {
|
||||||
const found = mockCompareList.find((x) => String(x.id) === m[1])
|
const compareId = m[1]
|
||||||
|
const found = mockCompareList.find((x) => String(x.id) === compareId)
|
||||||
return found ? ok(found) : fail('任务不存在', 404)
|
return found ? ok(found) : fail('任务不存在', 404)
|
||||||
}
|
}
|
||||||
if (m && method === 'delete') return ok({ deleted: m[1] })
|
if (m && method === 'delete') return ok({ deleted: m[1] })
|
||||||
@@ -363,7 +368,14 @@ async function handleMock(config: AxiosRequestConfig) {
|
|||||||
if (url === '/log-files' && method === 'get') return ok(mockLogFiles)
|
if (url === '/log-files' && method === 'get') return ok(mockLogFiles)
|
||||||
if (url === '/log-content' && method === 'get') return ok(mockLogContent)
|
if (url === '/log-content' && method === 'get') return ok(mockLogContent)
|
||||||
if (url === '/training-log-files' && method === 'get') return ok(mockTrainingLogFiles)
|
if (url === '/training-log-files' && method === 'get') return ok(mockTrainingLogFiles)
|
||||||
if (url === '/training-log-content' && method === 'get') return ok(mockLogContent)
|
if (url === '/training-log-content' && method === 'get') {
|
||||||
|
const file = String(params.file || '')
|
||||||
|
return ok(mockTrainingLogContents[file] || {
|
||||||
|
file,
|
||||||
|
size: '0 KB',
|
||||||
|
content: `[Mock] 未找到训练日志内容:${file}`,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 未匹配的请求 → 兜底返回空成功(避免阻断 UI)
|
// 未匹配的请求 → 兜底返回空成功(避免阻断 UI)
|
||||||
console.warn('[Mock] 未匹配路由:', method.toUpperCase(), url, params)
|
console.warn('[Mock] 未匹配路由:', method.toUpperCase(), url, params)
|
||||||
@@ -380,12 +392,13 @@ function safeJSON(str: string) {
|
|||||||
|
|
||||||
/** 给 axios instance 安装 mock adapter */
|
/** 给 axios instance 安装 mock adapter */
|
||||||
export function installMockAdapter(instance: AxiosInstance) {
|
export function installMockAdapter(instance: AxiosInstance) {
|
||||||
instance.defaults.adapter = async (config: AxiosRequestConfig) => {
|
const adapter = async (config: AxiosRequestConfig) => {
|
||||||
try {
|
try {
|
||||||
const response = await handleMock(config)
|
const response = await handleMock(config)
|
||||||
return response
|
return response
|
||||||
} catch (e: any) {
|
} catch (error: unknown) {
|
||||||
return fail(e.message || 'Mock 错误', 500, config)
|
return fail(error instanceof Error ? error.message : 'Mock 错误', 500, config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
instance.defaults.adapter = adapter as AxiosAdapter
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,37 +58,40 @@ export const mockSystemInfo: SystemInfo = {
|
|||||||
id: 0,
|
id: 0,
|
||||||
uuid: 'GPU-MOCK-A800-00',
|
uuid: 'GPU-MOCK-A800-00',
|
||||||
name: 'NVIDIA A800',
|
name: 'NVIDIA A800',
|
||||||
status: 'idle',
|
status: 'busy',
|
||||||
gpu_percent: 0,
|
gpu_percent: 74,
|
||||||
memory_used_gb: 0,
|
memory_used_gb: 41.8,
|
||||||
memory_total_gb: 80,
|
memory_total_gb: 80,
|
||||||
memory_percent: 0,
|
memory_percent: 52.3,
|
||||||
temperature: 32,
|
temperature: 63,
|
||||||
power_w: 38,
|
power_w: 286,
|
||||||
power_limit_w: 400,
|
power_limit_w: 400,
|
||||||
fan_speed: 0,
|
fan_speed: 51,
|
||||||
clock_mhz: 1410,
|
clock_mhz: 1410,
|
||||||
driver_version: '535.86.10',
|
driver_version: '535.86.10',
|
||||||
processes: [],
|
processes: [
|
||||||
|
{ pid: 28741, name: 'python', task_name: 'medical-cpt-001 / rank 0', user: 'trainer', memory_used_gb: 39.6 },
|
||||||
|
{ pid: 28768, name: 'python', task_name: '训练指标采集', user: 'trainer', memory_used_gb: 2.2 },
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
uuid: 'GPU-MOCK-A800-01',
|
uuid: 'GPU-MOCK-A800-01',
|
||||||
name: 'NVIDIA A800',
|
name: 'NVIDIA A800',
|
||||||
status: 'busy',
|
status: 'busy',
|
||||||
gpu_percent: 28,
|
gpu_percent: 71,
|
||||||
memory_used_gb: 22.5,
|
memory_used_gb: 42.1,
|
||||||
memory_total_gb: 80,
|
memory_total_gb: 80,
|
||||||
memory_percent: 28.1,
|
memory_percent: 52.6,
|
||||||
temperature: 52,
|
temperature: 62,
|
||||||
power_w: 165,
|
power_w: 279,
|
||||||
power_limit_w: 400,
|
power_limit_w: 400,
|
||||||
fan_speed: 32,
|
fan_speed: 49,
|
||||||
clock_mhz: 1410,
|
clock_mhz: 1410,
|
||||||
driver_version: '535.86.10',
|
driver_version: '535.86.10',
|
||||||
processes: [
|
processes: [
|
||||||
{ pid: 18421, name: 'python', task_name: '指令微调任务', user: 'trainer', memory_used_gb: 18.6 },
|
{ pid: 28742, name: 'python', task_name: 'medical-cpt-001 / rank 1', user: 'trainer', memory_used_gb: 39.9 },
|
||||||
{ pid: 18503, name: 'python', task_name: '训练指标采集', user: 'trainer', memory_used_gb: 3.9 },
|
{ pid: 28769, name: 'python', task_name: '训练指标采集', user: 'trainer', memory_used_gb: 2.2 },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -249,7 +252,7 @@ export const mockLocalModels = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ============ 数据集 ============
|
// ============ 数据集 ============
|
||||||
export const mockDatasets: DatasetItem[] = [
|
export const mockDatasets: DatasetItem[] = ([
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
name: '金融问答-训练集',
|
name: '金融问答-训练集',
|
||||||
@@ -273,7 +276,7 @@ export const mockDatasets: DatasetItem[] = [
|
|||||||
{ id: 8, name: '通用指令构造集', type: 'train', storage_type: 'local', source: 'task', task_id: 492015, size: '148 MB', count: 12600, description: '由指令微调数据构造任务生成', create_time: '2026-07-09T01:42:00Z' },
|
{ id: 8, name: '通用指令构造集', type: 'train', storage_type: 'local', source: 'task', task_id: 492015, size: '148 MB', count: 12600, description: '由指令微调数据构造任务生成', create_time: '2026-07-09T01:42:00Z' },
|
||||||
{ id: 9, name: '用户反馈脱敏集', type: 'test', storage_type: 'minio', source: 'task', task_id: 731948, size: '72 MB', count: 9340, description: '由敏感信息脱敏任务生成', create_time: '2026-07-09T09:18:00Z' },
|
{ id: 9, name: '用户反馈脱敏集', type: 'test', storage_type: 'minio', source: 'task', task_id: 731948, size: '72 MB', count: 9340, description: '由敏感信息脱敏任务生成', create_time: '2026-07-09T09:18:00Z' },
|
||||||
{ id: 10, name: '多轮对话增强集', type: 'eval', storage_type: 'local', source: 'task', task_id: 582012, size: '41 MB', count: 2780, description: '由多轮对话拼接任务生成', create_time: '2026-07-10T02:06:00Z' },
|
{ id: 10, name: '多轮对话增强集', type: 'eval', storage_type: 'local', source: 'task', task_id: 582012, size: '41 MB', count: 2780, description: '由多轮对话拼接任务生成', create_time: '2026-07-10T02:06:00Z' },
|
||||||
].map((dataset) => ({
|
] satisfies DatasetItem[]).map((dataset) => ({
|
||||||
...dataset,
|
...dataset,
|
||||||
files: dataset.files?.length
|
files: dataset.files?.length
|
||||||
? dataset.files
|
? dataset.files
|
||||||
@@ -339,12 +342,181 @@ export const mockDatasetPreviews: Record<string, string> = {
|
|||||||
|
|
||||||
// ============ 训练任务 ============
|
// ============ 训练任务 ============
|
||||||
export const mockFineTuneList: FineTuneTask[] = [
|
export const mockFineTuneList: FineTuneTask[] = [
|
||||||
{ id: 103942, name: 'finance-sft-001', description: '金融领域 SFT 训练', status: 'completed', train_type: 'SFT', train_method: 'lora', template: 'qwen', base_model: 1, train_dataset_id: 1, gpus: [0], progress: 100, train_duration: '2小时18分钟', create_time: '2026-01-15T08:00:00Z' },
|
{
|
||||||
{ id: 349102, name: 'legal-sft-002', description: '法律文书 SFT', status: 'completed', train_type: 'SFT', train_method: 'lora', template: 'qwen', base_model: 1, train_dataset_id: 2, gpus: [1], progress: 100, train_duration: '1小时46分钟', create_time: '2026-01-18T10:00:00Z' },
|
id: 103942,
|
||||||
{ id: 849301, name: 'medical-cpt-001', description: '医疗领域继续预训练', status: 'running', train_type: 'CPT', train_method: 'lora', template: 'qwen2_5', base_model: 2, train_dataset_id: 6, gpus: [0, 1], progress: 64, train_duration: '36分钟', create_time: '2026-02-05T09:00:00Z' },
|
name: 'finance-sft-001',
|
||||||
{ id: 593021, name: 'service-dpo-001', description: '客服对话偏好训练', status: 'pending', train_type: 'DPO', train_method: 'lora', template: 'qwen', base_model: 1, train_dataset_id: 3, gpus: [2], progress: 0, train_duration: '-', create_time: '2026-02-08T14:00:00Z' },
|
description: '金融领域 SFT 训练',
|
||||||
{ id: 201948, name: 'finance-sft-002', description: '金融领域二轮微调', status: 'failed', train_type: 'SFT', train_method: 'lora', template: 'qwen', base_model: 1, train_dataset_id: 1, gpus: [3], progress: 32, train_duration: '18分钟', create_time: '2026-02-10T11:00:00Z' },
|
status: 'completed',
|
||||||
{ id: 940212, name: 'general-sft-001', description: '通用能力微调', status: 'completed', train_type: 'SFT', train_method: 'full', template: 'llama3', base_model: 3, train_dataset_id: 3, gpus: [0, 2], progress: 100, train_duration: '3小时05分钟', create_time: '2026-02-12T13:00:00Z' },
|
train_type: 'SFT',
|
||||||
|
train_method: 'lora',
|
||||||
|
template: 'qwen',
|
||||||
|
base_model: 1,
|
||||||
|
train_dataset_id: 1,
|
||||||
|
output_model_name: 'qwen2.5-7b-finance-sft-v1',
|
||||||
|
auto_merge: true,
|
||||||
|
gpus: [0],
|
||||||
|
batch_size: 8,
|
||||||
|
learning_rate: 0.00002,
|
||||||
|
n_epochs: 3,
|
||||||
|
save_steps: 100,
|
||||||
|
lr_scheduler_type: 'cosine',
|
||||||
|
max_length: 2048,
|
||||||
|
warmup_ratio: 0.05,
|
||||||
|
weight_decay: 0.01,
|
||||||
|
lora_rank: 16,
|
||||||
|
lora_alpha: 32,
|
||||||
|
lora_dropout: 0.05,
|
||||||
|
quantization_bit: 0,
|
||||||
|
process_id: 12345,
|
||||||
|
progress: 100,
|
||||||
|
train_duration: '2小时18分钟',
|
||||||
|
create_time: '2026-01-15T08:00:00Z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 349102,
|
||||||
|
name: 'legal-sft-002',
|
||||||
|
description: '法律文书 SFT',
|
||||||
|
status: 'completed',
|
||||||
|
train_type: 'SFT',
|
||||||
|
train_method: 'lora',
|
||||||
|
template: 'qwen',
|
||||||
|
base_model: 1,
|
||||||
|
train_dataset_id: 2,
|
||||||
|
output_model_name: 'qwen2.5-7b-legal-sft-v2',
|
||||||
|
auto_merge: true,
|
||||||
|
gpus: [1],
|
||||||
|
batch_size: 4,
|
||||||
|
learning_rate: 0.000015,
|
||||||
|
n_epochs: 4,
|
||||||
|
save_steps: 120,
|
||||||
|
lr_scheduler_type: 'linear',
|
||||||
|
max_length: 4096,
|
||||||
|
warmup_ratio: 0.03,
|
||||||
|
weight_decay: 0.01,
|
||||||
|
lora_rank: 32,
|
||||||
|
lora_alpha: 64,
|
||||||
|
lora_dropout: 0.05,
|
||||||
|
quantization_bit: 0,
|
||||||
|
process_id: 12350,
|
||||||
|
progress: 100,
|
||||||
|
train_duration: '1小时46分钟',
|
||||||
|
create_time: '2026-01-18T10:00:00Z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 849301,
|
||||||
|
name: 'medical-cpt-001',
|
||||||
|
description: '医疗领域继续预训练',
|
||||||
|
status: 'running',
|
||||||
|
train_type: 'CPT',
|
||||||
|
train_method: 'lora',
|
||||||
|
template: 'qwen2_5',
|
||||||
|
base_model: 2,
|
||||||
|
train_dataset_id: 6,
|
||||||
|
output_model_name: 'qwen2.5-14b-medical-cpt-v1',
|
||||||
|
auto_merge: true,
|
||||||
|
gpus: [0, 1],
|
||||||
|
batch_size: 2,
|
||||||
|
learning_rate: 0.0001,
|
||||||
|
n_epochs: 3,
|
||||||
|
save_steps: 200,
|
||||||
|
lr_scheduler_type: 'cosine',
|
||||||
|
max_length: 4096,
|
||||||
|
warmup_ratio: 0.03,
|
||||||
|
weight_decay: 0.01,
|
||||||
|
lora_rank: 16,
|
||||||
|
lora_alpha: 32,
|
||||||
|
lora_dropout: 0.05,
|
||||||
|
quantization_bit: 0,
|
||||||
|
process_id: 28741,
|
||||||
|
progress: 64,
|
||||||
|
train_duration: '36分钟',
|
||||||
|
create_time: '2026-07-13T06:40:00Z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 593021,
|
||||||
|
name: 'service-dpo-001',
|
||||||
|
description: '客服对话偏好训练',
|
||||||
|
status: 'pending',
|
||||||
|
train_type: 'DPO',
|
||||||
|
train_method: 'lora',
|
||||||
|
template: 'qwen',
|
||||||
|
base_model: 1,
|
||||||
|
train_dataset_id: 3,
|
||||||
|
output_model_name: 'qwen2.5-7b-service-dpo-v1',
|
||||||
|
auto_merge: true,
|
||||||
|
gpus: [2],
|
||||||
|
batch_size: 4,
|
||||||
|
learning_rate: 0.000005,
|
||||||
|
n_epochs: 2,
|
||||||
|
save_steps: 100,
|
||||||
|
lr_scheduler_type: 'cosine',
|
||||||
|
max_length: 2048,
|
||||||
|
warmup_ratio: 0.1,
|
||||||
|
weight_decay: 0,
|
||||||
|
lora_rank: 16,
|
||||||
|
lora_alpha: 32,
|
||||||
|
lora_dropout: 0.1,
|
||||||
|
quantization_bit: 0,
|
||||||
|
progress: 0,
|
||||||
|
train_duration: '等待调度',
|
||||||
|
create_time: '2026-02-08T14:00:00Z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 201948,
|
||||||
|
name: 'finance-sft-002',
|
||||||
|
description: '金融领域二轮微调',
|
||||||
|
status: 'failed',
|
||||||
|
train_type: 'SFT',
|
||||||
|
train_method: 'lora',
|
||||||
|
template: 'qwen',
|
||||||
|
base_model: 1,
|
||||||
|
train_dataset_id: 1,
|
||||||
|
output_model_name: 'qwen2.5-7b-finance-sft-v2',
|
||||||
|
auto_merge: false,
|
||||||
|
gpus: [3],
|
||||||
|
batch_size: 8,
|
||||||
|
learning_rate: 0.00002,
|
||||||
|
n_epochs: 3,
|
||||||
|
save_steps: 100,
|
||||||
|
lr_scheduler_type: 'cosine',
|
||||||
|
max_length: 2048,
|
||||||
|
warmup_ratio: 0.05,
|
||||||
|
weight_decay: 0.01,
|
||||||
|
lora_rank: 16,
|
||||||
|
lora_alpha: 32,
|
||||||
|
lora_dropout: 0.05,
|
||||||
|
quantization_bit: 0,
|
||||||
|
process_id: 27654,
|
||||||
|
progress: 32,
|
||||||
|
train_duration: '18分钟',
|
||||||
|
create_time: '2026-02-10T11:00:00Z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 940212,
|
||||||
|
name: 'general-sft-001',
|
||||||
|
description: '通用能力全参数微调',
|
||||||
|
status: 'completed',
|
||||||
|
train_type: 'SFT',
|
||||||
|
train_method: 'full',
|
||||||
|
template: 'llama3',
|
||||||
|
base_model: 3,
|
||||||
|
train_dataset_id: 3,
|
||||||
|
output_model_name: 'llama3-8b-general-sft-v1',
|
||||||
|
auto_merge: false,
|
||||||
|
gpus: [0, 2],
|
||||||
|
batch_size: 2,
|
||||||
|
learning_rate: 0.00001,
|
||||||
|
n_epochs: 2,
|
||||||
|
save_steps: 250,
|
||||||
|
lr_scheduler_type: 'cosine',
|
||||||
|
max_length: 4096,
|
||||||
|
warmup_ratio: 0.03,
|
||||||
|
weight_decay: 0.1,
|
||||||
|
process_id: 26318,
|
||||||
|
progress: 100,
|
||||||
|
train_duration: '3小时05分钟',
|
||||||
|
create_time: '2026-02-12T13:00:00Z',
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
// ============ 模型推理/对比 ============
|
// ============ 模型推理/对比 ============
|
||||||
@@ -549,11 +721,48 @@ export const mockLogFiles: LogFile[] = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
export const mockTrainingLogFiles: TrainingLogFile[] = [
|
export const mockTrainingLogFiles: TrainingLogFile[] = [
|
||||||
|
{ file: 'medical-cpt-001_pid28741.log', name: 'medical-cpt-001', size: '6.8 MB', pid: 28741, date: '2026-07-13' },
|
||||||
{ file: 'qwen-ft-finance-001_pid12345.log', name: 'finance-sft-001', size: '4.5 MB', pid: 12345, date: '2026-02-15' },
|
{ file: 'qwen-ft-finance-001_pid12345.log', name: 'finance-sft-001', size: '4.5 MB', pid: 12345, date: '2026-02-15' },
|
||||||
{ file: 'llama3-ft-customer-service_pid12346.log', name: 'service-dpo-001', size: '2.1 MB', pid: 12346, date: '2026-02-18' },
|
{ file: 'llama3-ft-customer-service_pid12346.log', name: 'service-dpo-001', size: '2.1 MB', pid: 12346, date: '2026-02-18' },
|
||||||
{ file: 'qwen-ft-legal-002_pid12350.log', name: 'legal-sft-002', size: '5.8 MB', pid: 12350, date: '2026-02-20' },
|
{ file: 'qwen-ft-legal-002_pid12350.log', name: 'legal-sft-002', size: '5.8 MB', pid: 12350, date: '2026-02-20' },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
const medicalTrainingLogLines = [
|
||||||
|
'[2026-07-13 14:40:01] INFO: Launching distributed training with torchrun --nproc_per_node=2',
|
||||||
|
'[2026-07-13 14:40:02] INFO: Process rank: 0, world size: 2, device: cuda:0, distributed training: True',
|
||||||
|
'[2026-07-13 14:40:04] INFO: Loading tokenizer from /data/models/qwen2.5-14b-instruct',
|
||||||
|
'[2026-07-13 14:40:16] INFO: Loading checkpoint shards: 100% | 8/8 | 00:12',
|
||||||
|
'[2026-07-13 14:40:18] INFO: Loading dataset 医疗问答-训练集 (9,800 samples)',
|
||||||
|
'[2026-07-13 14:40:27] INFO: Tokenizing dataset: 100% | 9,800/9,800 | 00:09',
|
||||||
|
'[2026-07-13 14:40:28] INFO: LoRA config: rank=16, alpha=32, dropout=0.05, target_modules=q_proj,k_proj,v_proj,o_proj',
|
||||||
|
'[2026-07-13 14:40:29] INFO: Trainable params: 83,886,080 / 14,787,584,000 (0.5673%)',
|
||||||
|
'[2026-07-13 14:40:30] INFO: ***** Running training *****',
|
||||||
|
'[2026-07-13 14:40:30] INFO: Num examples = 9,800',
|
||||||
|
'[2026-07-13 14:40:30] INFO: Num Epochs = 3',
|
||||||
|
'[2026-07-13 14:40:30] INFO: Instantaneous batch size per device = 2',
|
||||||
|
'[2026-07-13 14:40:30] INFO: Total train batch size = 32',
|
||||||
|
'[2026-07-13 14:40:30] INFO: Gradient Accumulation steps = 8',
|
||||||
|
'[2026-07-13 14:40:30] INFO: Total optimization steps = 921',
|
||||||
|
'[2026-07-13 14:42:18] INFO: step=40 {\'loss\': 2.684, \'grad_norm\': 1.184, \'learning_rate\': 9.82e-05, \'epoch\': 0.13}',
|
||||||
|
'[2026-07-13 14:44:26] INFO: step=80 {\'loss\': 2.312, \'grad_norm\': 1.092, \'learning_rate\': 9.68e-05, \'epoch\': 0.26}',
|
||||||
|
'[2026-07-13 14:46:34] INFO: step=120 {\'loss\': 2.084, \'grad_norm\': 1.037, \'learning_rate\': 9.43e-05, \'epoch\': 0.39}',
|
||||||
|
'[2026-07-13 14:48:42] INFO: step=160 {\'loss\': 1.932, \'grad_norm\': 0.986, \'learning_rate\': 9.08e-05, \'epoch\': 0.52}',
|
||||||
|
'[2026-07-13 14:50:49] INFO: step=200 {\'loss\': 1.801, \'grad_norm\': 0.944, \'learning_rate\': 8.64e-05, \'epoch\': 0.65}',
|
||||||
|
'[2026-07-13 14:50:54] INFO: Saving checkpoint to /data/checkpoints/medical-cpt-001/checkpoint-200',
|
||||||
|
'[2026-07-13 14:52:58] INFO: step=240 {\'loss\': 1.696, \'grad_norm\': 0.913, \'learning_rate\': 8.15e-05, \'epoch\': 0.78}',
|
||||||
|
'[2026-07-13 14:55:06] INFO: step=280 {\'loss\': 1.611, \'grad_norm\': 0.887, \'learning_rate\': 7.61e-05, \'epoch\': 0.91}',
|
||||||
|
'[2026-07-13 14:57:13] INFO: step=320 {\'loss\': 1.532, \'grad_norm\': 0.852, \'learning_rate\': 7.06e-05, \'epoch\': 1.04}',
|
||||||
|
'[2026-07-13 14:59:21] INFO: step=360 {\'loss\': 1.461, \'grad_norm\': 0.829, \'learning_rate\': 6.49e-05, \'epoch\': 1.17}',
|
||||||
|
'[2026-07-13 15:01:29] INFO: step=400 {\'loss\': 1.396, \'grad_norm\': 0.811, \'learning_rate\': 5.91e-05, \'epoch\': 1.30}',
|
||||||
|
'[2026-07-13 15:01:34] INFO: Saving checkpoint to /data/checkpoints/medical-cpt-001/checkpoint-400',
|
||||||
|
'[2026-07-13 15:03:37] INFO: step=440 {\'loss\': 1.337, \'grad_norm\': 0.795, \'learning_rate\': 5.35e-05, \'epoch\': 1.43}',
|
||||||
|
'[2026-07-13 15:05:45] INFO: step=480 {\'loss\': 1.286, \'grad_norm\': 0.776, \'learning_rate\': 4.80e-05, \'epoch\': 1.56}',
|
||||||
|
'[2026-07-13 15:07:53] INFO: step=520 {\'loss\': 1.232, \'grad_norm\': 0.758, \'learning_rate\': 4.28e-05, \'epoch\': 1.69}',
|
||||||
|
'[2026-07-13 15:11:59] INFO: step=560 {\'loss\': 1.184, \'grad_norm\': 0.741, \'learning_rate\': 3.79e-05, \'epoch\': 1.82}',
|
||||||
|
'[2026-07-13 15:16:05] INFO: step=590 {\'loss\': 1.146, \'grad_norm\': 0.728, \'learning_rate\': 3.44e-05, \'epoch\': 1.92}',
|
||||||
|
'[2026-07-13 15:16:06] INFO: Training is running normally, estimated remaining time: 00:20:15',
|
||||||
|
]
|
||||||
|
|
||||||
const fakeLogLines = [
|
const fakeLogLines = [
|
||||||
"[2026-02-15 08:30:12] INFO: Loading model from /data/models/qwen2.5-7b",
|
"[2026-02-15 08:30:12] INFO: Loading model from /data/models/qwen2.5-7b",
|
||||||
"[2026-02-15 08:30:13] INFO: Loading dataset finance-train-001 (8560 samples)",
|
"[2026-02-15 08:30:13] INFO: Loading dataset finance-train-001 (8560 samples)",
|
||||||
@@ -591,3 +800,16 @@ export const mockLogContent: LogContent = {
|
|||||||
size: '2.3 MB',
|
size: '2.3 MB',
|
||||||
content: fakeLogLines.join('\n'),
|
content: fakeLogLines.join('\n'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const mockTrainingLogContents: Record<string, LogContent> = {
|
||||||
|
'medical-cpt-001_pid28741.log': {
|
||||||
|
file: 'medical-cpt-001_pid28741.log',
|
||||||
|
size: '6.8 MB',
|
||||||
|
content: medicalTrainingLogLines.join('\n'),
|
||||||
|
},
|
||||||
|
'qwen-ft-finance-001_pid12345.log': {
|
||||||
|
file: 'qwen-ft-finance-001_pid12345.log',
|
||||||
|
size: '4.5 MB',
|
||||||
|
content: fakeLogLines.join('\n'),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|||||||
@@ -139,6 +139,37 @@ export interface FineTuneTask {
|
|||||||
create_time?: string
|
create_time?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type FineTuneStartPayload = Omit<
|
||||||
|
FineTuneTask,
|
||||||
|
'id' | 'status' | 'progress' | 'process_id' | 'train_duration' | 'create_time'
|
||||||
|
> & {
|
||||||
|
task_id: string | number
|
||||||
|
description: string
|
||||||
|
template: string
|
||||||
|
train_method: TrainMethodType
|
||||||
|
train_dataset_id: string | number
|
||||||
|
auto_merge: boolean
|
||||||
|
output_model_name: string
|
||||||
|
gpus: number[]
|
||||||
|
batch_size: number
|
||||||
|
learning_rate: number
|
||||||
|
n_epochs: number
|
||||||
|
save_steps: number
|
||||||
|
lr_scheduler_type: string
|
||||||
|
max_length: number
|
||||||
|
warmup_ratio: number
|
||||||
|
weight_decay: number
|
||||||
|
lora_alpha: number
|
||||||
|
lora_dropout: number
|
||||||
|
lora_rank: number
|
||||||
|
quantization_bit: number
|
||||||
|
export_quantized: boolean
|
||||||
|
quant_method: string
|
||||||
|
quant_bits: number
|
||||||
|
quant_group_size: number
|
||||||
|
export_format: string
|
||||||
|
}
|
||||||
|
|
||||||
export interface TrainingProgress {
|
export interface TrainingProgress {
|
||||||
status?: string
|
status?: string
|
||||||
progress?: number
|
progress?: number
|
||||||
|
|||||||
@@ -9,17 +9,25 @@ import SourceUploadStep from './create/SourceUploadStep.vue'
|
|||||||
import PreviewCompareStep from './create/PreviewCompareStep.vue'
|
import PreviewCompareStep from './create/PreviewCompareStep.vue'
|
||||||
import GenerationStep from './create/GenerationStep.vue'
|
import GenerationStep from './create/GenerationStep.vue'
|
||||||
import ResultEditorStep from './create/ResultEditorStep.vue'
|
import ResultEditorStep from './create/ResultEditorStep.vue'
|
||||||
import { buildPreviewItems, createResults, DEFAULT_SOURCE_TEXT } from './create/previewModel'
|
import { buildPreviewItems, DEFAULT_SOURCE_TEXT } from './create/previewModel'
|
||||||
|
import {
|
||||||
|
createDefaultStructuredOptions,
|
||||||
|
createDefaultUnstructuredOptions,
|
||||||
|
} from './create/dataProcessCreateState'
|
||||||
|
import {
|
||||||
|
DATA_PROCESS_DRAFT_STORAGE_KEY,
|
||||||
|
useDataProcessDraft,
|
||||||
|
} from './create/useDataProcessDraft'
|
||||||
|
import { useDataProcessGeneration } from './create/useDataProcessGeneration'
|
||||||
import { useModelsStore } from '@/stores/models'
|
import { useModelsStore } from '@/stores/models'
|
||||||
import type {
|
import type {
|
||||||
ExternalDataSource,
|
ExternalDataSource,
|
||||||
GenerationState,
|
|
||||||
PreviewItem,
|
PreviewItem,
|
||||||
ProcessType,
|
ProcessType,
|
||||||
ResultItem,
|
|
||||||
StepId,
|
StepId,
|
||||||
StructuredProcessOptions,
|
StructuredProcessOptions,
|
||||||
UnstructuredProcessOptions,
|
UnstructuredProcessOptions,
|
||||||
|
UploadedDataFile,
|
||||||
} from './create/types'
|
} from './create/types'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -28,10 +36,7 @@ const { list: modelList } = storeToRefs(modelsStore)
|
|||||||
const generationModels = computed(() => modelList.value.filter((model) => model.type === 'LLM'))
|
const generationModels = computed(() => modelList.value.filter((model) => model.type === 'LLM'))
|
||||||
const taskSetupRef = ref<InstanceType<typeof TaskSetupStep>>()
|
const taskSetupRef = ref<InstanceType<typeof TaskSetupStep>>()
|
||||||
const confirmDialogRef = ref<InstanceType<typeof AppConfirmDialog>>()
|
const confirmDialogRef = ref<InstanceType<typeof AppConfirmDialog>>()
|
||||||
const DRAFT_STORAGE_KEY = 'yg-data-process-create-draft'
|
|
||||||
const DRAFT_SCHEMA_VERSION = 5
|
|
||||||
const PREVIEW_MODEL_VERSION = 'document-chunk-v2'
|
const PREVIEW_MODEL_VERSION = 'document-chunk-v2'
|
||||||
const DEFAULT_GENERATION_PROMPT = '你是一名专业的数据生成助手。请根据输入内容生成准确、完整、可直接用于模型训练的问答数据。仅输出符合目标格式的内容,答案应事实清晰、语言自然,不要添加分析过程、说明或无关内容。'
|
|
||||||
|
|
||||||
const WIZARD_STEPS = [
|
const WIZARD_STEPS = [
|
||||||
{ id: 'create', title: '创建任务', desc: '填写任务信息与处理配置' },
|
{ id: 'create', title: '创建任务', desc: '填写任务信息与处理配置' },
|
||||||
@@ -40,65 +45,12 @@ const WIZARD_STEPS = [
|
|||||||
{ id: 'generate', title: '开始生成', desc: '确认摘要并启动处理' },
|
{ id: 'generate', title: '开始生成', desc: '确认摘要并启动处理' },
|
||||||
{ id: 'results', title: '结果编辑与保存', desc: '检查、修改并保存结果' },
|
{ id: 'results', title: '结果编辑与保存', desc: '检查、修改并保存结果' },
|
||||||
] as const satisfies ReadonlyArray<{ id: StepId; title: string; desc: string }>
|
] as const satisfies ReadonlyArray<{ id: StepId; title: string; desc: string }>
|
||||||
const LEGACY_V3_STEP_IDS: ReadonlyArray<StepId> = ['create', 'preview', 'generate', 'results']
|
|
||||||
|
|
||||||
const currentStep = ref(0)
|
const currentStep = ref(0)
|
||||||
const currentStepId = computed<StepId>(() => WIZARD_STEPS[currentStep.value]?.id ?? 'create')
|
const currentStepId = computed<StepId>(() => WIZARD_STEPS[currentStep.value]?.id ?? 'create')
|
||||||
const task = reactive({ name: '', description: '' })
|
const task = reactive({ name: '', description: '' })
|
||||||
const processType = ref<ProcessType>('unstructured')
|
const processType = ref<ProcessType>('unstructured')
|
||||||
const structuredOptions = ref<StructuredProcessOptions>({
|
const structuredOptions = ref<StructuredProcessOptions>(createDefaultStructuredOptions())
|
||||||
preprocessOptions: ['clean_invalid', 'detect_structure', 'deduplicate', 'normalize_format'],
|
const unstructuredOptions = ref<UnstructuredProcessOptions>(createDefaultUnstructuredOptions())
|
||||||
semanticEnrichment: false,
|
|
||||||
qaPairsPerRow: 1,
|
|
||||||
datasetSplit: { train: 80, validation: 10, test: 10 },
|
|
||||||
generationModelId: '',
|
|
||||||
generationPrompt: DEFAULT_GENERATION_PROMPT,
|
|
||||||
temperature: 0.7,
|
|
||||||
maxTokens: 1024,
|
|
||||||
jsonMode: false,
|
|
||||||
qualityFilterEnabled: false,
|
|
||||||
filterLowQuality: true,
|
|
||||||
filterShortContent: true,
|
|
||||||
minOutputLength: 20,
|
|
||||||
})
|
|
||||||
const unstructuredOptions = ref<UnstructuredProcessOptions>({
|
|
||||||
preprocessOptions: [
|
|
||||||
'clean_invalid_content',
|
|
||||||
'detect_document_structure',
|
|
||||||
'merge_short_content',
|
|
||||||
'filter_low_quality',
|
|
||||||
'deduplicate_content',
|
|
||||||
'preserve_context',
|
|
||||||
],
|
|
||||||
chunkMethod: 'semantic',
|
|
||||||
chunkSize: 800,
|
|
||||||
chunkOverlap: 100,
|
|
||||||
minChunkSize: 100,
|
|
||||||
customDelimiter: '',
|
|
||||||
preserveTables: true,
|
|
||||||
preserveCodeBlocks: true,
|
|
||||||
preserveLists: true,
|
|
||||||
semanticEnrichment: false,
|
|
||||||
qaPairsPerChunk: 1,
|
|
||||||
datasetSplit: { train: 80, validation: 10, test: 10 },
|
|
||||||
generationModelId: '',
|
|
||||||
generationPrompt: DEFAULT_GENERATION_PROMPT,
|
|
||||||
temperature: 0.7,
|
|
||||||
maxTokens: 1024,
|
|
||||||
jsonMode: false,
|
|
||||||
qualityFilterEnabled: false,
|
|
||||||
filterLowQuality: true,
|
|
||||||
filterShortContent: true,
|
|
||||||
minOutputLength: 20,
|
|
||||||
})
|
|
||||||
interface UploadedDataFile {
|
|
||||||
uid: number | string
|
|
||||||
name: string
|
|
||||||
size: number
|
|
||||||
count: number
|
|
||||||
content: string
|
|
||||||
}
|
|
||||||
|
|
||||||
const uploadedFiles = ref<UploadedDataFile[]>([])
|
const uploadedFiles = ref<UploadedDataFile[]>([])
|
||||||
|
|
||||||
const externalSource = reactive<ExternalDataSource>({
|
const externalSource = reactive<ExternalDataSource>({
|
||||||
@@ -112,35 +64,53 @@ const externalSource = reactive<ExternalDataSource>({
|
|||||||
})
|
})
|
||||||
const externalPulling = ref(false)
|
const externalPulling = ref(false)
|
||||||
const externalConnected = ref(false)
|
const externalConnected = ref(false)
|
||||||
|
let connectionTimer: ReturnType<typeof setTimeout> | null = null
|
||||||
|
let pullTimer: ReturnType<typeof setTimeout> | null = null
|
||||||
|
|
||||||
const fileName = computed(() => uploadedFiles.value.map(f => f.name).join(', '))
|
const fileName = computed(() => uploadedFiles.value.map(f => f.name).join(', '))
|
||||||
const fileSize = computed(() => uploadedFiles.value.reduce((sum, f) => sum + f.size, 0))
|
|
||||||
const fileCount = computed(() => uploadedFiles.value.reduce((sum, f) => sum + f.count, 0))
|
|
||||||
const previewSignature = ref('')
|
const previewSignature = ref('')
|
||||||
const previewItems = ref<PreviewItem[]>([])
|
const previewItems = ref<PreviewItem[]>([])
|
||||||
const selectedPreviewFileId = ref<string | null>(null)
|
const selectedPreviewFileId = ref<string | null>(null)
|
||||||
const selectedPreviewId = ref<string | null>(null)
|
const selectedPreviewId = ref<string | null>(null)
|
||||||
const selectedPreviewIdsByFile = ref<Record<string, string>>({})
|
const selectedPreviewIdsByFile = ref<Record<string, string>>({})
|
||||||
const results = ref<ResultItem[]>([])
|
|
||||||
const selectedResultId = ref<string | null>(null)
|
|
||||||
const dirty = ref(false)
|
const dirty = ref(false)
|
||||||
const restoringDraft = ref(false)
|
const restoringDraft = ref(false)
|
||||||
let allowLeave = false
|
let allowLeave = false
|
||||||
|
|
||||||
const generation = reactive<GenerationState>({
|
const {
|
||||||
status: 'idle',
|
generation,
|
||||||
progress: 0,
|
results,
|
||||||
message: '确认摘要后即可开始生成,过程中可查看实时进度。',
|
selectedResultId,
|
||||||
|
resetDownstream,
|
||||||
|
restoreResult,
|
||||||
|
startGeneration,
|
||||||
|
stopGeneration,
|
||||||
|
stopGenerationTimer,
|
||||||
|
updateResultField,
|
||||||
|
validateResults,
|
||||||
|
} = useDataProcessGeneration({
|
||||||
|
previewItems,
|
||||||
|
processType,
|
||||||
|
structuredOptions,
|
||||||
|
unstructuredOptions,
|
||||||
|
dirty,
|
||||||
})
|
})
|
||||||
|
|
||||||
let generationTimer: ReturnType<typeof setInterval> | null = null
|
|
||||||
|
|
||||||
const modifiedPreviewCount = computed(() => previewItems.value.filter((item) => item.status !== 'original').length)
|
const modifiedPreviewCount = computed(() => previewItems.value.filter((item) => item.status !== 'original').length)
|
||||||
|
const previewItemsByFile = computed(() => {
|
||||||
|
const grouped = new Map<string, PreviewItem[]>()
|
||||||
|
for (const item of previewItems.value) {
|
||||||
|
const items = grouped.get(item.sourceFileId) || []
|
||||||
|
items.push(item)
|
||||||
|
grouped.set(item.sourceFileId, items)
|
||||||
|
}
|
||||||
|
return grouped
|
||||||
|
})
|
||||||
const activePreviewFile = computed(() => uploadedFiles.value.find((file) => String(file.uid) === selectedPreviewFileId.value))
|
const activePreviewFile = computed(() => uploadedFiles.value.find((file) => String(file.uid) === selectedPreviewFileId.value))
|
||||||
const activePreviewItems = computed(() => previewItems.value.filter((item) => item.sourceFileId === selectedPreviewFileId.value))
|
const activePreviewItems = computed(() => previewItemsByFile.value.get(selectedPreviewFileId.value || '') || [])
|
||||||
const activeSourceText = computed(() => activePreviewFile.value?.content ?? '')
|
const activeSourceText = computed(() => activePreviewFile.value?.content ?? '')
|
||||||
const previewFiles = computed(() => uploadedFiles.value.map((file) => {
|
const previewFiles = computed(() => uploadedFiles.value.map((file) => {
|
||||||
const items = previewItems.value.filter((item) => item.sourceFileId === String(file.uid))
|
const items = previewItemsByFile.value.get(String(file.uid)) || []
|
||||||
return {
|
return {
|
||||||
id: String(file.uid),
|
id: String(file.uid),
|
||||||
name: file.name,
|
name: file.name,
|
||||||
@@ -169,44 +139,22 @@ const previousStepLabel = computed(() => currentStep.value > 0
|
|||||||
? WIZARD_STEPS[currentStep.value - 1].title
|
? WIZARD_STEPS[currentStep.value - 1].title
|
||||||
: '')
|
: '')
|
||||||
|
|
||||||
function isStepId(value: unknown): value is StepId {
|
|
||||||
return typeof value === 'string' && WIZARD_STEPS.some((step) => step.id === value)
|
|
||||||
}
|
|
||||||
|
|
||||||
function goToStep(stepId: StepId) {
|
function goToStep(stepId: StepId) {
|
||||||
const nextStepIndex = WIZARD_STEPS.findIndex((step) => step.id === stepId)
|
const nextStepIndex = WIZARD_STEPS.findIndex((step) => step.id === stepId)
|
||||||
if (nextStepIndex >= 0) currentStep.value = nextStepIndex
|
if (nextStepIndex >= 0) currentStep.value = nextStepIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
function draftSnapshot() {
|
const { persistDraft, restoreDraft } = useDataProcessDraft({
|
||||||
return {
|
currentStepId,
|
||||||
schemaVersion: DRAFT_SCHEMA_VERSION,
|
task,
|
||||||
currentStep: currentStep.value,
|
processType,
|
||||||
currentStepId: currentStepId.value,
|
structuredOptions,
|
||||||
task: { ...task },
|
unstructuredOptions,
|
||||||
processType: processType.value,
|
externalSource,
|
||||||
structuredOptions: {
|
restoringDraft,
|
||||||
...structuredOptions.value,
|
dirty,
|
||||||
preprocessOptions: [...structuredOptions.value.preprocessOptions],
|
goToStep,
|
||||||
datasetSplit: { ...structuredOptions.value.datasetSplit },
|
})
|
||||||
},
|
|
||||||
unstructuredOptions: {
|
|
||||||
...unstructuredOptions.value,
|
|
||||||
preprocessOptions: [...unstructuredOptions.value.preprocessOptions],
|
|
||||||
datasetSplit: { ...unstructuredOptions.value.datasetSplit },
|
|
||||||
},
|
|
||||||
uploadedFiles: uploadedFiles.value,
|
|
||||||
externalSource: { ...externalSource },
|
|
||||||
previewSignature: previewSignature.value,
|
|
||||||
previewItems: previewItems.value,
|
|
||||||
selectedPreviewFileId: selectedPreviewFileId.value,
|
|
||||||
selectedPreviewId: selectedPreviewId.value,
|
|
||||||
selectedPreviewIdsByFile: selectedPreviewIdsByFile.value,
|
|
||||||
results: results.value,
|
|
||||||
selectedResultId: selectedResultId.value,
|
|
||||||
generation: { ...generation },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function previewAffectingOptions() {
|
function previewAffectingOptions() {
|
||||||
if (processType.value === 'structured') {
|
if (processType.value === 'structured') {
|
||||||
@@ -291,191 +239,11 @@ const generationOptionsSignature = computed(() => JSON.stringify(generationAffec
|
|||||||
|
|
||||||
function buildPreviewSignature() {
|
function buildPreviewSignature() {
|
||||||
const filesSignature = uploadedFiles.value
|
const filesSignature = uploadedFiles.value
|
||||||
.map((file) => `${file.uid}:${file.content}`)
|
.map((file) => `${file.uid}:${file.name}:${file.size}:${file.count}`)
|
||||||
.join('|')
|
.join('|')
|
||||||
return `${PREVIEW_MODEL_VERSION}:${processType.value}:${JSON.stringify(previewAffectingOptions())}:${filesSignature}`
|
return `${PREVIEW_MODEL_VERSION}:${processType.value}:${JSON.stringify(previewAffectingOptions())}:${filesSignature}`
|
||||||
}
|
}
|
||||||
|
|
||||||
function persistDraft() {
|
|
||||||
if (restoringDraft.value) return
|
|
||||||
try {
|
|
||||||
localStorage.setItem(DRAFT_STORAGE_KEY, JSON.stringify(draftSnapshot()))
|
|
||||||
} catch {
|
|
||||||
ElMessage.warning('草稿保存失败,请检查浏览器存储空间')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type DraftSnapshot = Partial<ReturnType<typeof draftSnapshot>> & {
|
|
||||||
fileName?: string
|
|
||||||
fileSize?: number
|
|
||||||
fileCount?: number
|
|
||||||
sourceText?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
function restoreDraft() {
|
|
||||||
try {
|
|
||||||
const raw = localStorage.getItem(DRAFT_STORAGE_KEY)
|
|
||||||
if (!raw) return
|
|
||||||
const snapshot = JSON.parse(raw) as DraftSnapshot
|
|
||||||
if (!snapshot?.uploadedFiles && (!snapshot?.fileName || !snapshot?.sourceText)) return
|
|
||||||
const snapshotSchemaVersion = Number(snapshot.schemaVersion) || 0
|
|
||||||
const requiresPreviewMigration = snapshotSchemaVersion < 3
|
|
||||||
const legacyStepId = snapshotSchemaVersion === 3
|
|
||||||
? LEGACY_V3_STEP_IDS[Math.min(Math.max(Number(snapshot.currentStep) || 0, 0), LEGACY_V3_STEP_IDS.length - 1)]
|
|
||||||
: undefined
|
|
||||||
const indexedStepId = WIZARD_STEPS[Math.min(
|
|
||||||
Math.max(Number(snapshot.currentStep) || 0, 0),
|
|
||||||
WIZARD_STEPS.length - 1,
|
|
||||||
)]?.id
|
|
||||||
const restoredStepId = isStepId(snapshot.currentStepId)
|
|
||||||
? snapshot.currentStepId
|
|
||||||
: legacyStepId || indexedStepId || 'create'
|
|
||||||
|
|
||||||
restoringDraft.value = true
|
|
||||||
goToStep(requiresPreviewMigration ? 'create' : restoredStepId)
|
|
||||||
task.name = snapshot.task?.name || ''
|
|
||||||
task.description = snapshot.task?.description || ''
|
|
||||||
processType.value = snapshot.processType === 'structured' || snapshot.processType === 'external'
|
|
||||||
? snapshot.processType
|
|
||||||
: 'unstructured'
|
|
||||||
if (snapshot.structuredOptions) {
|
|
||||||
structuredOptions.value = {
|
|
||||||
...structuredOptions.value,
|
|
||||||
...snapshot.structuredOptions,
|
|
||||||
preprocessOptions: Array.isArray(snapshot.structuredOptions.preprocessOptions)
|
|
||||||
? snapshot.structuredOptions.preprocessOptions
|
|
||||||
: structuredOptions.value.preprocessOptions,
|
|
||||||
datasetSplit: {
|
|
||||||
...structuredOptions.value.datasetSplit,
|
|
||||||
...snapshot.structuredOptions.datasetSplit,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (snapshot.unstructuredOptions) {
|
|
||||||
const restoredUnstructuredOptions = snapshot.unstructuredOptions
|
|
||||||
const restoredDatasetSplit = restoredUnstructuredOptions.datasetSplit
|
|
||||||
unstructuredOptions.value = {
|
|
||||||
...unstructuredOptions.value,
|
|
||||||
preprocessOptions: Array.isArray(restoredUnstructuredOptions.preprocessOptions)
|
|
||||||
? restoredUnstructuredOptions.preprocessOptions
|
|
||||||
: unstructuredOptions.value.preprocessOptions,
|
|
||||||
chunkMethod: restoredUnstructuredOptions.chunkMethod || unstructuredOptions.value.chunkMethod,
|
|
||||||
chunkSize: Number.isFinite(restoredUnstructuredOptions.chunkSize)
|
|
||||||
? restoredUnstructuredOptions.chunkSize
|
|
||||||
: unstructuredOptions.value.chunkSize,
|
|
||||||
chunkOverlap: Number.isFinite(restoredUnstructuredOptions.chunkOverlap)
|
|
||||||
? restoredUnstructuredOptions.chunkOverlap
|
|
||||||
: unstructuredOptions.value.chunkOverlap,
|
|
||||||
minChunkSize: Number.isFinite(restoredUnstructuredOptions.minChunkSize)
|
|
||||||
? restoredUnstructuredOptions.minChunkSize
|
|
||||||
: unstructuredOptions.value.minChunkSize,
|
|
||||||
customDelimiter: typeof restoredUnstructuredOptions.customDelimiter === 'string'
|
|
||||||
? restoredUnstructuredOptions.customDelimiter
|
|
||||||
: unstructuredOptions.value.customDelimiter,
|
|
||||||
preserveTables: typeof restoredUnstructuredOptions.preserveTables === 'boolean'
|
|
||||||
? restoredUnstructuredOptions.preserveTables
|
|
||||||
: unstructuredOptions.value.preserveTables,
|
|
||||||
preserveCodeBlocks: typeof restoredUnstructuredOptions.preserveCodeBlocks === 'boolean'
|
|
||||||
? restoredUnstructuredOptions.preserveCodeBlocks
|
|
||||||
: unstructuredOptions.value.preserveCodeBlocks,
|
|
||||||
preserveLists: typeof restoredUnstructuredOptions.preserveLists === 'boolean'
|
|
||||||
? restoredUnstructuredOptions.preserveLists
|
|
||||||
: unstructuredOptions.value.preserveLists,
|
|
||||||
semanticEnrichment: typeof restoredUnstructuredOptions.semanticEnrichment === 'boolean'
|
|
||||||
? restoredUnstructuredOptions.semanticEnrichment
|
|
||||||
: unstructuredOptions.value.semanticEnrichment,
|
|
||||||
qaPairsPerChunk: Number.isFinite(restoredUnstructuredOptions.qaPairsPerChunk)
|
|
||||||
? restoredUnstructuredOptions.qaPairsPerChunk
|
|
||||||
: unstructuredOptions.value.qaPairsPerChunk,
|
|
||||||
generationModelId: restoredUnstructuredOptions.generationModelId ?? unstructuredOptions.value.generationModelId,
|
|
||||||
generationPrompt: typeof restoredUnstructuredOptions.generationPrompt === 'string'
|
|
||||||
? restoredUnstructuredOptions.generationPrompt
|
|
||||||
: unstructuredOptions.value.generationPrompt,
|
|
||||||
temperature: Number.isFinite(restoredUnstructuredOptions.temperature)
|
|
||||||
? restoredUnstructuredOptions.temperature
|
|
||||||
: unstructuredOptions.value.temperature,
|
|
||||||
maxTokens: Number.isFinite(restoredUnstructuredOptions.maxTokens)
|
|
||||||
? restoredUnstructuredOptions.maxTokens
|
|
||||||
: unstructuredOptions.value.maxTokens,
|
|
||||||
jsonMode: typeof restoredUnstructuredOptions.jsonMode === 'boolean'
|
|
||||||
? restoredUnstructuredOptions.jsonMode
|
|
||||||
: unstructuredOptions.value.jsonMode,
|
|
||||||
qualityFilterEnabled: typeof restoredUnstructuredOptions.qualityFilterEnabled === 'boolean'
|
|
||||||
? restoredUnstructuredOptions.qualityFilterEnabled
|
|
||||||
: unstructuredOptions.value.qualityFilterEnabled,
|
|
||||||
filterLowQuality: typeof restoredUnstructuredOptions.filterLowQuality === 'boolean'
|
|
||||||
? restoredUnstructuredOptions.filterLowQuality
|
|
||||||
: unstructuredOptions.value.filterLowQuality,
|
|
||||||
filterShortContent: typeof restoredUnstructuredOptions.filterShortContent === 'boolean'
|
|
||||||
? restoredUnstructuredOptions.filterShortContent
|
|
||||||
: unstructuredOptions.value.filterShortContent,
|
|
||||||
minOutputLength: Number.isFinite(restoredUnstructuredOptions.minOutputLength)
|
|
||||||
? restoredUnstructuredOptions.minOutputLength
|
|
||||||
: unstructuredOptions.value.minOutputLength,
|
|
||||||
datasetSplit: {
|
|
||||||
train: Number.isFinite(restoredDatasetSplit?.train)
|
|
||||||
? restoredDatasetSplit.train
|
|
||||||
: unstructuredOptions.value.datasetSplit.train,
|
|
||||||
validation: Number.isFinite(restoredDatasetSplit?.validation)
|
|
||||||
? restoredDatasetSplit.validation
|
|
||||||
: unstructuredOptions.value.datasetSplit.validation,
|
|
||||||
test: Number.isFinite(restoredDatasetSplit?.test)
|
|
||||||
? restoredDatasetSplit.test
|
|
||||||
: unstructuredOptions.value.datasetSplit.test,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (snapshot.uploadedFiles) {
|
|
||||||
uploadedFiles.value = Array.isArray(snapshot.uploadedFiles) ? snapshot.uploadedFiles : []
|
|
||||||
} else if (snapshot.fileName && snapshot.sourceText) {
|
|
||||||
// Migrate old draft
|
|
||||||
uploadedFiles.value = [{
|
|
||||||
uid: 'migrated-draft',
|
|
||||||
name: snapshot.fileName,
|
|
||||||
size: Number(snapshot.fileSize) || 0,
|
|
||||||
count: Number(snapshot.fileCount) || 0,
|
|
||||||
content: snapshot.sourceText
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
|
|
||||||
previewSignature.value = requiresPreviewMigration ? '' : snapshot.previewSignature || ''
|
|
||||||
if (snapshot.externalSource) {
|
|
||||||
Object.assign(externalSource, snapshot.externalSource)
|
|
||||||
}
|
|
||||||
const defaultSourceFileId = String(uploadedFiles.value[0]?.uid ?? '')
|
|
||||||
previewItems.value = !requiresPreviewMigration && Array.isArray(snapshot.previewItems)
|
|
||||||
? snapshot.previewItems.map((item) => ({ ...item, sourceFileId: item.sourceFileId ?? defaultSourceFileId }))
|
|
||||||
: []
|
|
||||||
selectedPreviewFileId.value = snapshot.selectedPreviewFileId || defaultSourceFileId || null
|
|
||||||
selectedPreviewIdsByFile.value = requiresPreviewMigration ? {} : snapshot.selectedPreviewIdsByFile || {}
|
|
||||||
selectedPreviewId.value = requiresPreviewMigration
|
|
||||||
? null
|
|
||||||
: snapshot.selectedPreviewId
|
|
||||||
|| selectedPreviewIdsByFile.value[selectedPreviewFileId.value ?? '']
|
|
||||||
|| activePreviewItems.value[0]?.id
|
|
||||||
|| null
|
|
||||||
results.value = !requiresPreviewMigration && Array.isArray(snapshot.results) ? snapshot.results : []
|
|
||||||
selectedResultId.value = requiresPreviewMigration ? null : snapshot.selectedResultId || results.value[0]?.id || null
|
|
||||||
if (!requiresPreviewMigration) {
|
|
||||||
const restoredGeneration = snapshot.generation || {}
|
|
||||||
Object.assign(generation, restoredGeneration)
|
|
||||||
if (generation.status === 'running') {
|
|
||||||
generation.status = 'idle'
|
|
||||||
generation.progress = 0
|
|
||||||
generation.message = '草稿已恢复,请重新开始生成。'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dirty.value = false
|
|
||||||
nextTick(() => { restoringDraft.value = false })
|
|
||||||
ElMessage.info(requiresPreviewMigration
|
|
||||||
? '已恢复任务信息,切分规则已更新,请重新生成预览'
|
|
||||||
: '已恢复上次保存的草稿')
|
|
||||||
} catch {
|
|
||||||
localStorage.removeItem(DRAFT_STORAGE_KEY)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
[() => task.name, () => task.description, processType, structuredOptions, unstructuredOptions, externalSource],
|
[() => task.name, () => task.description, processType, structuredOptions, unstructuredOptions, externalSource],
|
||||||
() => {
|
() => {
|
||||||
@@ -496,9 +264,7 @@ watch(generationOptionsSignature, (currentSignature, previousSignature) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
[currentStep, task, processType, structuredOptions, unstructuredOptions, uploadedFiles, externalSource, previewSignature,
|
[task, processType, structuredOptions, unstructuredOptions, externalSource],
|
||||||
previewItems, selectedPreviewFileId, selectedPreviewId, selectedPreviewIdsByFile,
|
|
||||||
results, selectedResultId, generation],
|
|
||||||
persistDraft,
|
persistDraft,
|
||||||
{ deep: true },
|
{ deep: true },
|
||||||
)
|
)
|
||||||
@@ -566,8 +332,10 @@ function handleTestConnection() {
|
|||||||
ElMessage.warning('请先填写数据源地址')
|
ElMessage.warning('请先填写数据源地址')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (connectionTimer) clearTimeout(connectionTimer)
|
||||||
externalPulling.value = true
|
externalPulling.value = true
|
||||||
setTimeout(() => {
|
connectionTimer = setTimeout(() => {
|
||||||
|
connectionTimer = null
|
||||||
externalPulling.value = false
|
externalPulling.value = false
|
||||||
externalConnected.value = true
|
externalConnected.value = true
|
||||||
ElMessage.success('数据源连接测试成功')
|
ElMessage.success('数据源连接测试成功')
|
||||||
@@ -579,8 +347,10 @@ function handlePullData() {
|
|||||||
ElMessage.warning('请先填写数据源地址')
|
ElMessage.warning('请先填写数据源地址')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (pullTimer) clearTimeout(pullTimer)
|
||||||
externalPulling.value = true
|
externalPulling.value = true
|
||||||
setTimeout(() => {
|
pullTimer = setTimeout(() => {
|
||||||
|
pullTimer = null
|
||||||
externalPulling.value = false
|
externalPulling.value = false
|
||||||
externalConnected.value = true
|
externalConnected.value = true
|
||||||
const typeName = externalSource.type.toUpperCase()
|
const typeName = externalSource.type.toUpperCase()
|
||||||
@@ -620,15 +390,6 @@ function resetSourceDataForProcessTypeChange() {
|
|||||||
resetDownstream()
|
resetDownstream()
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetDownstream() {
|
|
||||||
stopGenerationTimer()
|
|
||||||
generation.status = 'idle'
|
|
||||||
generation.progress = 0
|
|
||||||
generation.message = '确认摘要后即可开始生成,过程中可查看实时进度。'
|
|
||||||
results.value = []
|
|
||||||
selectedResultId.value = null
|
|
||||||
}
|
|
||||||
|
|
||||||
async function nextFromCreate() {
|
async function nextFromCreate() {
|
||||||
const valid = await taskSetupRef.value?.validate()
|
const valid = await taskSetupRef.value?.validate()
|
||||||
if (!valid) return
|
if (!valid) return
|
||||||
@@ -738,81 +499,6 @@ async function removePreviewItem(id: string) {
|
|||||||
dirty.value = true
|
dirty.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopGenerationTimer() {
|
|
||||||
if (generationTimer) clearInterval(generationTimer)
|
|
||||||
generationTimer = null
|
|
||||||
}
|
|
||||||
|
|
||||||
function startGeneration() {
|
|
||||||
stopGenerationTimer()
|
|
||||||
generation.status = 'running'
|
|
||||||
generation.progress = 0
|
|
||||||
generation.message = '正在应用预览修改并生成标准化结果,请稍候。'
|
|
||||||
|
|
||||||
generationTimer = setInterval(() => {
|
|
||||||
generation.progress = Math.min(100, generation.progress + 8)
|
|
||||||
if (generation.progress < 100) return
|
|
||||||
|
|
||||||
stopGenerationTimer()
|
|
||||||
generation.status = 'success'
|
|
||||||
results.value = createResults(
|
|
||||||
previewItems.value,
|
|
||||||
processType.value === 'structured'
|
|
||||||
? structuredOptions.value
|
|
||||||
: processType.value === 'unstructured'
|
|
||||||
? unstructuredOptions.value
|
|
||||||
: undefined,
|
|
||||||
)
|
|
||||||
generation.message = `已完成 ${results.value.length.toLocaleString()} 条数据处理,可进入结果页检查。`
|
|
||||||
selectedResultId.value = results.value[0]?.id ?? null
|
|
||||||
dirty.value = true
|
|
||||||
ElMessage.success('数据处理完成')
|
|
||||||
}, 180)
|
|
||||||
}
|
|
||||||
|
|
||||||
function stopGeneration() {
|
|
||||||
stopGenerationTimer()
|
|
||||||
generation.status = 'failed'
|
|
||||||
generation.message = '任务已停止,预览修改仍然保留,可以重新生成。'
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateResultField(id: string, field: 'instruction' | 'input' | 'output', value: string) {
|
|
||||||
const item = results.value.find((entry) => entry.id === id)
|
|
||||||
if (!item) return
|
|
||||||
item[field] = value
|
|
||||||
const valid = item.instruction.trim() && item.output.trim()
|
|
||||||
item.error = valid ? undefined : 'Instruction 和 Output 不能为空'
|
|
||||||
const changed = item.instruction !== item.originalInstruction
|
|
||||||
|| item.input !== item.originalInput
|
|
||||||
|| item.output !== item.originalOutput
|
|
||||||
item.status = item.error ? 'invalid' : changed ? 'modified' : 'valid'
|
|
||||||
dirty.value = true
|
|
||||||
}
|
|
||||||
|
|
||||||
function restoreResult(id: string) {
|
|
||||||
const item = results.value.find((entry) => entry.id === id)
|
|
||||||
if (!item) return
|
|
||||||
item.instruction = item.originalInstruction
|
|
||||||
item.input = item.originalInput
|
|
||||||
item.output = item.originalOutput
|
|
||||||
item.error = undefined
|
|
||||||
item.status = 'valid'
|
|
||||||
dirty.value = true
|
|
||||||
}
|
|
||||||
|
|
||||||
function validateResults() {
|
|
||||||
let firstInvalidId: string | null = null
|
|
||||||
for (const item of results.value) {
|
|
||||||
if (!item.instruction.trim() || !item.output.trim()) {
|
|
||||||
item.error = 'Instruction 和 Output 不能为空'
|
|
||||||
item.status = 'invalid'
|
|
||||||
firstInvalidId ??= item.id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (firstInvalidId) selectedResultId.value = firstInvalidId
|
|
||||||
return firstInvalidId == null
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handlePrimaryAction() {
|
async function handlePrimaryAction() {
|
||||||
if (currentStepId.value === 'create') {
|
if (currentStepId.value === 'create') {
|
||||||
await nextFromCreate()
|
await nextFromCreate()
|
||||||
@@ -856,7 +542,7 @@ async function saveTask() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
dirty.value = false
|
dirty.value = false
|
||||||
localStorage.removeItem(DRAFT_STORAGE_KEY)
|
localStorage.removeItem(DATA_PROCESS_DRAFT_STORAGE_KEY)
|
||||||
allowLeave = true
|
allowLeave = true
|
||||||
ElMessage.success('数据处理任务已保存')
|
ElMessage.success('数据处理任务已保存')
|
||||||
await router.push('/data-process')
|
await router.push('/data-process')
|
||||||
@@ -893,7 +579,11 @@ onBeforeRouteLeave(async () => {
|
|||||||
return Boolean(confirmed)
|
return Boolean(confirmed)
|
||||||
})
|
})
|
||||||
|
|
||||||
onBeforeUnmount(stopGenerationTimer)
|
onBeforeUnmount(() => {
|
||||||
|
stopGenerationTimer()
|
||||||
|
if (connectionTimer) clearTimeout(connectionTimer)
|
||||||
|
if (pullTimer) clearTimeout(pullTimer)
|
||||||
|
})
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
restoreDraft()
|
restoreDraft()
|
||||||
modelsStore.load()
|
modelsStore.load()
|
||||||
@@ -1023,198 +713,4 @@ onMounted(() => {
|
|||||||
<AppConfirmDialog ref="confirmDialogRef" />
|
<AppConfirmDialog ref="confirmDialogRef" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss" src="./create/data-process-create.scss"></style>
|
||||||
.create-wizard-layout {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
height: 100%;
|
|
||||||
border: 1px solid #eef0f5;
|
|
||||||
border-radius: 8px;
|
|
||||||
background: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wizard-main {
|
|
||||||
flex: 1;
|
|
||||||
overflow-y: auto;
|
|
||||||
padding: 32px;
|
|
||||||
|
|
||||||
/* 自定义滚动条 */
|
|
||||||
&::-webkit-scrollbar {
|
|
||||||
width: 6px;
|
|
||||||
}
|
|
||||||
&::-webkit-scrollbar-thumb {
|
|
||||||
background: #cbd5e1;
|
|
||||||
border-radius: 3px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.wizard-main-inner {
|
|
||||||
min-height: 100%;
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wizard-steps-container {
|
|
||||||
margin-bottom: 32px;
|
|
||||||
padding-bottom: 24px;
|
|
||||||
border-bottom: 1px dashed #e2e8f0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.custom-wizard-steps {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
max-width: 860px;
|
|
||||||
margin: 0 auto;
|
|
||||||
padding: 0 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.step-item {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
flex: 1;
|
|
||||||
|
|
||||||
&:first-child {
|
|
||||||
flex: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.step-connector {
|
|
||||||
flex: 1;
|
|
||||||
height: 2px;
|
|
||||||
background-color: #e2e8f0;
|
|
||||||
margin: 0 16px;
|
|
||||||
transition: background-color 0.3s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.step-item.is-completed .step-connector,
|
|
||||||
.step-item.is-active .step-connector {
|
|
||||||
background-color: #5146e5;
|
|
||||||
}
|
|
||||||
|
|
||||||
.step-node {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.step-icon {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
width: 28px;
|
|
||||||
height: 28px;
|
|
||||||
border-radius: 50%;
|
|
||||||
border: 2px solid #cbd5e1;
|
|
||||||
background-color: #fff;
|
|
||||||
color: #64748b;
|
|
||||||
font-size: 13px;
|
|
||||||
font-weight: 650;
|
|
||||||
transition: all 0.3s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.step-title {
|
|
||||||
font-size: 14px;
|
|
||||||
font-weight: 600;
|
|
||||||
color: #64748b;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* State: Active */
|
|
||||||
.step-item.is-active {
|
|
||||||
.step-icon {
|
|
||||||
border-color: #5146e5;
|
|
||||||
background-color: #eef2ff;
|
|
||||||
color: #5146e5;
|
|
||||||
}
|
|
||||||
.step-title {
|
|
||||||
color: #1e293b;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* State: Completed */
|
|
||||||
.step-item.is-completed {
|
|
||||||
.step-icon {
|
|
||||||
background-color: #5146e5;
|
|
||||||
border-color: #5146e5;
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
.step-title {
|
|
||||||
color: #1e293b;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.wizard-content {
|
|
||||||
min-height: 400px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wizard-footer {
|
|
||||||
flex-shrink: 0;
|
|
||||||
height: 64px;
|
|
||||||
background: #ffffff;
|
|
||||||
border-top: 1px solid #e2e8f0;
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 1fr auto 1fr;
|
|
||||||
align-items: center;
|
|
||||||
padding: 0 32px;
|
|
||||||
box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.02);
|
|
||||||
|
|
||||||
.footer-left {
|
|
||||||
justify-self: start;
|
|
||||||
}
|
|
||||||
|
|
||||||
.footer-center {
|
|
||||||
justify-self: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.footer-right {
|
|
||||||
justify-self: end;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.wizard-primary-action {
|
|
||||||
min-width: 160px;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 760px) {
|
|
||||||
.wizard-main {
|
|
||||||
padding: 24px 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.custom-wizard-steps {
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.step-connector {
|
|
||||||
margin: 0 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.step-node {
|
|
||||||
gap: 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.step-title {
|
|
||||||
max-width: 72px;
|
|
||||||
font-size: 12px;
|
|
||||||
line-height: 1.35;
|
|
||||||
white-space: normal;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wizard-footer {
|
|
||||||
padding: 0 20px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 600px) {
|
|
||||||
.step-title {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.step-connector {
|
|
||||||
margin: 0 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wizard-primary-action {
|
|
||||||
min-width: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|||||||
185
frontend/src/views/data-process/create/DatasetSplitEditor.vue
Normal file
185
frontend/src/views/data-process/create/DatasetSplitEditor.vue
Normal file
@@ -0,0 +1,185 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed } from 'vue'
|
||||||
|
import type { DatasetSplitOptions } from './types'
|
||||||
|
|
||||||
|
const props = withDefaults(defineProps<{
|
||||||
|
modelValue: DatasetSplitOptions
|
||||||
|
ariaLabelPrefix?: string
|
||||||
|
}>(), {
|
||||||
|
ariaLabelPrefix: '',
|
||||||
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:modelValue': [value: DatasetSplitOptions]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const splitTotal = computed(() => {
|
||||||
|
const { train, validation, test } = props.modelValue
|
||||||
|
return train + validation + test
|
||||||
|
})
|
||||||
|
|
||||||
|
function updateField(field: keyof DatasetSplitOptions, value: number | undefined) {
|
||||||
|
emit('update:modelValue', {
|
||||||
|
...props.modelValue,
|
||||||
|
[field]: Math.min(100, Math.max(0, Number(value) || 0)),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function ariaLabel(label: string) {
|
||||||
|
return `${props.ariaLabelPrefix}${label}比例`
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="generation-option-row dataset-split-row">
|
||||||
|
<div class="generation-option-copy">
|
||||||
|
<strong>数据集划分</strong>
|
||||||
|
<small>按比例将生成后的问答对随机划分为训练集、验证集和测试集</small>
|
||||||
|
</div>
|
||||||
|
<div class="dataset-split-config">
|
||||||
|
<div class="dataset-split-grid">
|
||||||
|
<label class="dataset-split-field">
|
||||||
|
<span>训练集</span>
|
||||||
|
<span class="dataset-split-input">
|
||||||
|
<el-input-number
|
||||||
|
:model-value="modelValue.train"
|
||||||
|
:min="0"
|
||||||
|
:max="100"
|
||||||
|
:step="1"
|
||||||
|
:precision="0"
|
||||||
|
controls-position="right"
|
||||||
|
:aria-label="ariaLabel('训练集')"
|
||||||
|
@update:model-value="updateField('train', $event)"
|
||||||
|
/>
|
||||||
|
<span>%</span>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
<label class="dataset-split-field">
|
||||||
|
<span>验证集</span>
|
||||||
|
<span class="dataset-split-input">
|
||||||
|
<el-input-number
|
||||||
|
:model-value="modelValue.validation"
|
||||||
|
:min="0"
|
||||||
|
:max="100"
|
||||||
|
:step="1"
|
||||||
|
:precision="0"
|
||||||
|
controls-position="right"
|
||||||
|
:aria-label="ariaLabel('验证集')"
|
||||||
|
@update:model-value="updateField('validation', $event)"
|
||||||
|
/>
|
||||||
|
<span>%</span>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
<label class="dataset-split-field">
|
||||||
|
<span>测试集</span>
|
||||||
|
<span class="dataset-split-input">
|
||||||
|
<el-input-number
|
||||||
|
:model-value="modelValue.test"
|
||||||
|
:min="0"
|
||||||
|
:max="100"
|
||||||
|
:step="1"
|
||||||
|
:precision="0"
|
||||||
|
controls-position="right"
|
||||||
|
:aria-label="ariaLabel('测试集')"
|
||||||
|
@update:model-value="updateField('test', $event)"
|
||||||
|
/>
|
||||||
|
<span>%</span>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="dataset-split-summary" :class="{ 'is-invalid': splitTotal !== 100 }">
|
||||||
|
<span>总计 {{ splitTotal }}%</span>
|
||||||
|
<span v-if="splitTotal !== 100" role="alert">
|
||||||
|
训练集、验证集和测试集比例总和必须为 100%
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.generation-option-row {
|
||||||
|
display: flex;
|
||||||
|
min-height: 64px;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 24px;
|
||||||
|
padding: 12px 14px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border: 1px solid #e2e5ec;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.generation-option-copy {
|
||||||
|
display: grid;
|
||||||
|
gap: 4px;
|
||||||
|
|
||||||
|
strong {
|
||||||
|
color: #344054;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
small {
|
||||||
|
color: #8a93a3;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataset-split-row {
|
||||||
|
align-items: stretch;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataset-split-config {
|
||||||
|
display: grid;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataset-split-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||||
|
gap: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataset-split-field {
|
||||||
|
display: grid;
|
||||||
|
gap: 7px;
|
||||||
|
color: #5f6878;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataset-split-input {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
|
||||||
|
:deep(.el-input-number) {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataset-split-summary {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
color: #2ca66a;
|
||||||
|
font-size: 12px;
|
||||||
|
|
||||||
|
&.is-invalid {
|
||||||
|
color: #dc2626;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 900px) {
|
||||||
|
.dataset-split-grid {
|
||||||
|
grid-template-columns: minmax(0, 1fr);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataset-split-summary {
|
||||||
|
align-items: flex-start;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -95,7 +95,7 @@ function sectionValidationMessage() {
|
|||||||
@update:model-value="updateField('generationPrompt', $event)"
|
@update:model-value="updateField('generationPrompt', $event)"
|
||||||
/>
|
/>
|
||||||
<div class="prompt-variables-hint">
|
<div class="prompt-variables-hint">
|
||||||
提示:可在文本中通过 <code>{{ content }}</code> 引用当前正在处理的数据内容。
|
提示:可在文本中通过 <code v-text="'{{ content }}'" /> 引用当前正在处理的数据内容。
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,11 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, ref, watch } from 'vue'
|
import { computed, ref, watch } from 'vue'
|
||||||
import type { UploadFile } from 'element-plus'
|
import type { UploadFile } from 'element-plus'
|
||||||
import type { ExternalDataSource, ProcessType } from './types'
|
import type { ExternalDataSource, ProcessType, UploadedDataFile } from './types'
|
||||||
|
|
||||||
interface UploadedSourceFile {
|
|
||||||
uid: string | number
|
|
||||||
name: string
|
|
||||||
size: number
|
|
||||||
count: number
|
|
||||||
}
|
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
processType: ProcessType
|
processType: ProcessType
|
||||||
uploadedFiles: UploadedSourceFile[]
|
uploadedFiles: UploadedDataFile[]
|
||||||
externalSource: ExternalDataSource
|
externalSource: ExternalDataSource
|
||||||
externalPulling: boolean
|
externalPulling: boolean
|
||||||
externalConnected: boolean
|
externalConnected: boolean
|
||||||
|
|||||||
@@ -0,0 +1,270 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { ModelItem } from '@/types'
|
||||||
|
import type {
|
||||||
|
GenerationControlOptions,
|
||||||
|
PreprocessOption,
|
||||||
|
StructuredProcessOptions,
|
||||||
|
} from './types'
|
||||||
|
import DatasetSplitEditor from './DatasetSplitEditor.vue'
|
||||||
|
import GenerationOptionsPanel from './GenerationOptionsPanel.vue'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
options: StructuredProcessOptions
|
||||||
|
generationModels: ModelItem[]
|
||||||
|
validationAttempted: boolean
|
||||||
|
generationValidationMessage: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:options': [value: StructuredProcessOptions]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const PREPROCESS_OPTIONS: Array<{
|
||||||
|
value: PreprocessOption
|
||||||
|
label: string
|
||||||
|
description: string
|
||||||
|
}> = [
|
||||||
|
{ value: 'clean_invalid', label: '清理无效数据', description: '处理空行、空列和残缺行' },
|
||||||
|
{ value: 'detect_structure', label: '识别表格结构', description: '识别表头、多级表头和合并单元格' },
|
||||||
|
{ value: 'deduplicate', label: '重复数据去重', description: '删除完全重复或关键字段重复的数据' },
|
||||||
|
{ value: 'normalize_format', label: '数据格式标准化', description: '统一日期、数字、单位和枚举值格式' },
|
||||||
|
{ value: 'filter_anomaly', label: '异常数据过滤', description: '过滤乱码、无效内容和异常记录' },
|
||||||
|
{ value: 'desensitize', label: '敏感信息脱敏', description: '处理姓名、手机号、邮箱等敏感信息' },
|
||||||
|
]
|
||||||
|
|
||||||
|
function updateField<K extends keyof StructuredProcessOptions>(
|
||||||
|
field: K,
|
||||||
|
value: StructuredProcessOptions[K],
|
||||||
|
) {
|
||||||
|
emit('update:options', { ...props.options, [field]: value })
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateGenerationOptions(value: GenerationControlOptions) {
|
||||||
|
emit('update:options', { ...props.options, ...value })
|
||||||
|
}
|
||||||
|
|
||||||
|
function updatePreprocessOptions(value: Array<string | number | boolean>) {
|
||||||
|
const allowedValues = new Set(PREPROCESS_OPTIONS.map((option) => option.value))
|
||||||
|
const preprocessOptions = value.filter(
|
||||||
|
(option): option is PreprocessOption => typeof option === 'string' && allowedValues.has(option as PreprocessOption),
|
||||||
|
)
|
||||||
|
updateField('preprocessOptions', preprocessOptions)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="form-section structured-options-section">
|
||||||
|
<div class="section-title-row">
|
||||||
|
<div>
|
||||||
|
<h3>预处理选项</h3>
|
||||||
|
<p>选择在生成问答对之前需要执行的数据处理方式</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<el-checkbox-group
|
||||||
|
:model-value="options.preprocessOptions"
|
||||||
|
class="preprocess-option-grid"
|
||||||
|
@update:model-value="updatePreprocessOptions"
|
||||||
|
>
|
||||||
|
<el-checkbox
|
||||||
|
v-for="option in PREPROCESS_OPTIONS"
|
||||||
|
:key="option.value"
|
||||||
|
:value="option.value"
|
||||||
|
class="preprocess-option"
|
||||||
|
>
|
||||||
|
<span class="preprocess-option-copy">
|
||||||
|
<strong>{{ option.label }}</strong>
|
||||||
|
<small>{{ option.description }}</small>
|
||||||
|
</span>
|
||||||
|
</el-checkbox>
|
||||||
|
</el-checkbox-group>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-section generation-options-section">
|
||||||
|
<div class="section-title-row">
|
||||||
|
<div>
|
||||||
|
<h3>生成选项</h3>
|
||||||
|
<p>配置每条结构化记录生成问答对的方式和数量</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="generation-option-list">
|
||||||
|
<GenerationOptionsPanel
|
||||||
|
:options="options"
|
||||||
|
:models="generationModels"
|
||||||
|
section="quality"
|
||||||
|
:validation-message="validationAttempted ? generationValidationMessage : ''"
|
||||||
|
@update:options="updateGenerationOptions"
|
||||||
|
/>
|
||||||
|
<div class="generation-option-row">
|
||||||
|
<div class="generation-option-copy">
|
||||||
|
<strong>语义丰富表达</strong>
|
||||||
|
<small>使用大模型将问答表述得更自然、柔和</small>
|
||||||
|
</div>
|
||||||
|
<el-switch
|
||||||
|
:model-value="options.semanticEnrichment"
|
||||||
|
inline-prompt
|
||||||
|
active-text="开"
|
||||||
|
inactive-text="关"
|
||||||
|
@update:model-value="updateField('semanticEnrichment', Boolean($event))"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="generation-option-row">
|
||||||
|
<div class="generation-option-copy">
|
||||||
|
<strong>每行生成数量</strong>
|
||||||
|
<small>每行结构化数据生成的问答对数量</small>
|
||||||
|
</div>
|
||||||
|
<el-input-number
|
||||||
|
:model-value="options.qaPairsPerRow"
|
||||||
|
:min="1"
|
||||||
|
:max="5"
|
||||||
|
:step="1"
|
||||||
|
controls-position="right"
|
||||||
|
@update:model-value="updateField('qaPairsPerRow', Number($event) || 1)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<DatasetSplitEditor
|
||||||
|
:model-value="options.datasetSplit"
|
||||||
|
@update:model-value="updateField('datasetSplit', $event)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-section model-options-section">
|
||||||
|
<div class="section-title-row">
|
||||||
|
<div>
|
||||||
|
<h3>大模型</h3>
|
||||||
|
<p>选择数据生成模型,并设置模型输出内容的要求</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="generation-option-list">
|
||||||
|
<GenerationOptionsPanel
|
||||||
|
:options="options"
|
||||||
|
:models="generationModels"
|
||||||
|
section="model"
|
||||||
|
:validation-message="validationAttempted ? generationValidationMessage : ''"
|
||||||
|
@update:options="updateGenerationOptions"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.form-section {
|
||||||
|
padding: 0 0 26px;
|
||||||
|
margin-bottom: 26px;
|
||||||
|
border-bottom: 1px solid #edf0f5;
|
||||||
|
|
||||||
|
&:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
border-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
margin: 0 0 16px;
|
||||||
|
color: #2f3747;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 650;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-title-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 16px;
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin: 0;
|
||||||
|
color: #8a93a3;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.preprocess-option-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
gap: 12px;
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preprocess-option {
|
||||||
|
width: 100%;
|
||||||
|
min-height: 64px;
|
||||||
|
margin-right: 0;
|
||||||
|
padding: 12px 14px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
align-items: flex-start;
|
||||||
|
border: 1px solid #e2e5ec;
|
||||||
|
border-radius: 8px;
|
||||||
|
transition: border-color 0.18s ease, background-color 0.18s ease;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
border-color: #b7b2f7;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.is-checked {
|
||||||
|
background: #fafaff;
|
||||||
|
border-color: #8b82f4;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.el-checkbox__input) {
|
||||||
|
margin-top: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.el-checkbox__label) {
|
||||||
|
min-width: 0;
|
||||||
|
padding-left: 10px;
|
||||||
|
white-space: normal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.preprocess-option-copy,
|
||||||
|
.generation-option-copy {
|
||||||
|
display: grid;
|
||||||
|
gap: 4px;
|
||||||
|
|
||||||
|
strong {
|
||||||
|
color: #344054;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
small {
|
||||||
|
color: #8a93a3;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.generation-option-list {
|
||||||
|
display: grid;
|
||||||
|
gap: 12px;
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.generation-option-row {
|
||||||
|
display: flex;
|
||||||
|
min-height: 64px;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 24px;
|
||||||
|
padding: 12px 14px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border: 1px solid #e2e5ec;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 900px) {
|
||||||
|
.preprocess-option-grid {
|
||||||
|
grid-template-columns: minmax(0, 1fr);
|
||||||
|
}
|
||||||
|
|
||||||
|
.generation-option-row {
|
||||||
|
align-items: flex-start;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,604 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, ref, watch } from 'vue'
|
||||||
|
import type { ModelItem } from '@/types'
|
||||||
|
import type {
|
||||||
|
ChunkMethod,
|
||||||
|
GenerationControlOptions,
|
||||||
|
UnstructuredPreprocessOption,
|
||||||
|
UnstructuredProcessOptions,
|
||||||
|
} from './types'
|
||||||
|
import DatasetSplitEditor from './DatasetSplitEditor.vue'
|
||||||
|
import GenerationOptionsPanel from './GenerationOptionsPanel.vue'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
options: UnstructuredProcessOptions
|
||||||
|
generationModels: ModelItem[]
|
||||||
|
validationAttempted: boolean
|
||||||
|
generationValidationMessage: string
|
||||||
|
chunkValidationMessage: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:options': [value: UnstructuredProcessOptions]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const SMART_PREPROCESS_OPTIONS: UnstructuredPreprocessOption[] = [
|
||||||
|
'clean_invalid_content',
|
||||||
|
'detect_document_structure',
|
||||||
|
'merge_short_content',
|
||||||
|
'filter_low_quality',
|
||||||
|
'deduplicate_content',
|
||||||
|
'preserve_context',
|
||||||
|
]
|
||||||
|
|
||||||
|
const CHUNK_METHODS: Array<{ value: ChunkMethod; label: string }> = [
|
||||||
|
{ value: 'semantic', label: '自动语义切分' },
|
||||||
|
{ value: 'heading', label: '按标题和段落' },
|
||||||
|
{ value: 'fixed', label: '按固定长度' },
|
||||||
|
{ value: 'custom', label: '自定义分隔符' },
|
||||||
|
]
|
||||||
|
|
||||||
|
const UNSTRUCTURED_NUMBER_LIMITS = {
|
||||||
|
chunkSize: { min: 200, max: 2000 },
|
||||||
|
chunkOverlap: { min: 0, max: 500 },
|
||||||
|
minChunkSize: { min: 20, max: 500 },
|
||||||
|
qaPairsPerChunk: { min: 1, max: 3 },
|
||||||
|
} as const
|
||||||
|
|
||||||
|
type UnstructuredNumberField = keyof typeof UNSTRUCTURED_NUMBER_LIMITS
|
||||||
|
|
||||||
|
const advancedChunkSettingsOpen = ref(props.options.chunkMethod === 'custom')
|
||||||
|
|
||||||
|
const smartPreprocessEnabled = computed(() => SMART_PREPROCESS_OPTIONS.every(
|
||||||
|
(option) => props.options.preprocessOptions.includes(option),
|
||||||
|
))
|
||||||
|
|
||||||
|
const desensitizeEnabled = computed(() => props.options.preprocessOptions.includes('desensitize'))
|
||||||
|
|
||||||
|
const preserveSpecialContentEnabled = computed(() => (
|
||||||
|
props.options.preserveTables
|
||||||
|
&& props.options.preserveCodeBlocks
|
||||||
|
&& props.options.preserveLists
|
||||||
|
))
|
||||||
|
|
||||||
|
watch(() => props.options.chunkMethod, (method) => {
|
||||||
|
if (method === 'custom') advancedChunkSettingsOpen.value = true
|
||||||
|
})
|
||||||
|
|
||||||
|
watch(() => props.chunkValidationMessage, (message) => {
|
||||||
|
if (message) advancedChunkSettingsOpen.value = true
|
||||||
|
})
|
||||||
|
|
||||||
|
function updateField<K extends keyof UnstructuredProcessOptions>(
|
||||||
|
field: K,
|
||||||
|
value: UnstructuredProcessOptions[K],
|
||||||
|
) {
|
||||||
|
emit('update:options', { ...props.options, [field]: value })
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateGenerationOptions(value: GenerationControlOptions) {
|
||||||
|
emit('update:options', { ...props.options, ...value })
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateSmartPreprocess(value: string | number | boolean) {
|
||||||
|
const enabled = Boolean(value)
|
||||||
|
const remainingOptions = props.options.preprocessOptions.filter(
|
||||||
|
(option) => !SMART_PREPROCESS_OPTIONS.includes(option),
|
||||||
|
)
|
||||||
|
updateField(
|
||||||
|
'preprocessOptions',
|
||||||
|
enabled ? [...SMART_PREPROCESS_OPTIONS, ...remainingOptions] : remainingOptions,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateDesensitize(value: string | number | boolean) {
|
||||||
|
const preprocessOptions: UnstructuredPreprocessOption[] = props.options.preprocessOptions.filter(
|
||||||
|
(option) => option !== 'desensitize',
|
||||||
|
)
|
||||||
|
if (Boolean(value)) preprocessOptions.push('desensitize')
|
||||||
|
updateField('preprocessOptions', preprocessOptions)
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateSpecialContentProtection(value: string | number | boolean) {
|
||||||
|
const enabled = Boolean(value)
|
||||||
|
emit('update:options', {
|
||||||
|
...props.options,
|
||||||
|
preserveTables: enabled,
|
||||||
|
preserveCodeBlocks: enabled,
|
||||||
|
preserveLists: enabled,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateUnstructuredNumber(field: UnstructuredNumberField, value: number | undefined) {
|
||||||
|
const limits = UNSTRUCTURED_NUMBER_LIMITS[field]
|
||||||
|
const parsedValue = Number(value)
|
||||||
|
const nextValue = Number.isFinite(parsedValue) ? parsedValue : limits.min
|
||||||
|
updateField(field, Math.min(limits.max, Math.max(limits.min, nextValue)))
|
||||||
|
}
|
||||||
|
|
||||||
|
function revealValidation() {
|
||||||
|
advancedChunkSettingsOpen.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ revealValidation })
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="form-section unstructured-options-section">
|
||||||
|
<div class="section-title-row">
|
||||||
|
<div>
|
||||||
|
<h3>预处理选项</h3>
|
||||||
|
<p>默认使用推荐策略,只需决定是否需要脱敏</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="generation-option-list compact-option-list">
|
||||||
|
<div class="generation-option-row">
|
||||||
|
<div class="generation-option-copy">
|
||||||
|
<strong>智能预处理</strong>
|
||||||
|
<small>自动完成内容清理、结构解析、短段合并、质量过滤、去重及上下文保留</small>
|
||||||
|
</div>
|
||||||
|
<el-switch
|
||||||
|
:model-value="smartPreprocessEnabled"
|
||||||
|
aria-label="智能预处理"
|
||||||
|
inline-prompt
|
||||||
|
active-text="开"
|
||||||
|
inactive-text="关"
|
||||||
|
@update:model-value="updateSmartPreprocess"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="generation-option-row">
|
||||||
|
<div class="generation-option-copy">
|
||||||
|
<strong>敏感信息脱敏</strong>
|
||||||
|
<small>处理姓名、手机号、邮箱和证件号等信息</small>
|
||||||
|
</div>
|
||||||
|
<el-switch
|
||||||
|
:model-value="desensitizeEnabled"
|
||||||
|
aria-label="敏感信息脱敏"
|
||||||
|
inline-prompt
|
||||||
|
active-text="开"
|
||||||
|
inactive-text="关"
|
||||||
|
@update:model-value="updateDesensitize"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-section chunk-options-section">
|
||||||
|
<div class="section-title-row">
|
||||||
|
<div>
|
||||||
|
<h3>切分选项</h3>
|
||||||
|
<p>以语义完整为优先,将长文档拆成可独立生成问答的内容块</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="chunk-settings-grid is-basic">
|
||||||
|
<label class="config-field">
|
||||||
|
<span class="config-field-label">切分方式</span>
|
||||||
|
<el-select
|
||||||
|
:model-value="options.chunkMethod"
|
||||||
|
aria-label="切分方式"
|
||||||
|
@update:model-value="updateField('chunkMethod', $event)"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="method in CHUNK_METHODS"
|
||||||
|
:key="method.value"
|
||||||
|
:label="method.label"
|
||||||
|
:value="method.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
<small>推荐使用自动语义切分,在长度限制内优先保留完整句段</small>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label class="config-field">
|
||||||
|
<span class="config-field-label">切片长度</span>
|
||||||
|
<span class="unit-input">
|
||||||
|
<el-input-number
|
||||||
|
:model-value="options.chunkSize"
|
||||||
|
:min="200"
|
||||||
|
:max="2000"
|
||||||
|
:step="50"
|
||||||
|
:precision="0"
|
||||||
|
controls-position="right"
|
||||||
|
aria-label="切片长度"
|
||||||
|
@update:model-value="updateUnstructuredNumber('chunkSize', $event)"
|
||||||
|
/>
|
||||||
|
<span>Token</span>
|
||||||
|
</span>
|
||||||
|
<small>单个切片的目标上限,默认 800 Token</small>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label class="config-field">
|
||||||
|
<span class="config-field-label">重叠长度</span>
|
||||||
|
<span class="unit-input">
|
||||||
|
<el-input-number
|
||||||
|
:model-value="options.chunkOverlap"
|
||||||
|
:min="0"
|
||||||
|
:max="500"
|
||||||
|
:step="10"
|
||||||
|
:precision="0"
|
||||||
|
controls-position="right"
|
||||||
|
aria-label="重叠长度"
|
||||||
|
@update:model-value="updateUnstructuredNumber('chunkOverlap', $event)"
|
||||||
|
/>
|
||||||
|
<span>Token</span>
|
||||||
|
</span>
|
||||||
|
<small>在相邻切片中最多重复保留的上下文,默认 100 Token</small>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p class="chunk-estimation-note">
|
||||||
|
Token 数为轻量估算值,实际长度以训练使用的模型分词器为准。
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p v-if="chunkValidationMessage" class="option-validation-message" role="alert">
|
||||||
|
{{ chunkValidationMessage }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="advanced-settings-toggle"
|
||||||
|
:aria-expanded="advancedChunkSettingsOpen"
|
||||||
|
aria-controls="unstructured-advanced-settings"
|
||||||
|
@click="advancedChunkSettingsOpen = !advancedChunkSettingsOpen"
|
||||||
|
>
|
||||||
|
<span>
|
||||||
|
<strong>高级设置</strong>
|
||||||
|
<small>最小切片长度、自定义分隔符和特殊内容保护</small>
|
||||||
|
</span>
|
||||||
|
<i class="fa" :class="advancedChunkSettingsOpen ? 'fa-chevron-up' : 'fa-chevron-down'" />
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="advancedChunkSettingsOpen"
|
||||||
|
id="unstructured-advanced-settings"
|
||||||
|
class="advanced-settings-panel"
|
||||||
|
>
|
||||||
|
<div class="advanced-settings-grid">
|
||||||
|
<label class="config-field">
|
||||||
|
<span class="config-field-label">最小切片长度</span>
|
||||||
|
<span class="unit-input">
|
||||||
|
<el-input-number
|
||||||
|
:model-value="options.minChunkSize"
|
||||||
|
:min="20"
|
||||||
|
:max="500"
|
||||||
|
:step="10"
|
||||||
|
:precision="0"
|
||||||
|
controls-position="right"
|
||||||
|
aria-label="最小切片长度"
|
||||||
|
@update:model-value="updateUnstructuredNumber('minChunkSize', $event)"
|
||||||
|
/>
|
||||||
|
<span>Token</span>
|
||||||
|
</span>
|
||||||
|
<small>过短的尾部内容会尽量并入前一个切片</small>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label v-if="options.chunkMethod === 'custom'" class="config-field">
|
||||||
|
<span class="config-field-label">自定义分隔符</span>
|
||||||
|
<el-input
|
||||||
|
:model-value="options.customDelimiter"
|
||||||
|
maxlength="40"
|
||||||
|
show-word-limit
|
||||||
|
placeholder="例如:--- 或 ###"
|
||||||
|
aria-label="自定义分隔符"
|
||||||
|
@update:model-value="updateField('customDelimiter', $event)"
|
||||||
|
/>
|
||||||
|
<small>系统会优先在分隔符位置结束当前切片</small>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="generation-option-row advanced-protection-row">
|
||||||
|
<div class="generation-option-copy">
|
||||||
|
<strong>保护表格、代码和列表</strong>
|
||||||
|
<small>避免切分点破坏特殊内容块的完整性</small>
|
||||||
|
</div>
|
||||||
|
<el-switch
|
||||||
|
:model-value="preserveSpecialContentEnabled"
|
||||||
|
aria-label="保护表格、代码和列表"
|
||||||
|
inline-prompt
|
||||||
|
active-text="开"
|
||||||
|
inactive-text="关"
|
||||||
|
@update:model-value="updateSpecialContentProtection"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-section generation-options-section">
|
||||||
|
<div class="section-title-row">
|
||||||
|
<div>
|
||||||
|
<h3>生成选项</h3>
|
||||||
|
<p>只保留会直接影响输出的核心设置</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="generation-option-list">
|
||||||
|
<GenerationOptionsPanel
|
||||||
|
:options="options"
|
||||||
|
:models="generationModels"
|
||||||
|
section="quality"
|
||||||
|
:validation-message="validationAttempted ? generationValidationMessage : ''"
|
||||||
|
@update:options="updateGenerationOptions"
|
||||||
|
/>
|
||||||
|
<div class="generation-option-row">
|
||||||
|
<div class="generation-option-copy">
|
||||||
|
<strong>语义丰富表达</strong>
|
||||||
|
<small>使用大模型将问答表述得更自然、柔和</small>
|
||||||
|
</div>
|
||||||
|
<el-switch
|
||||||
|
:model-value="options.semanticEnrichment"
|
||||||
|
aria-label="非结构化语义丰富表达"
|
||||||
|
inline-prompt
|
||||||
|
active-text="开"
|
||||||
|
inactive-text="关"
|
||||||
|
@update:model-value="updateField('semanticEnrichment', Boolean($event))"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="generation-option-row">
|
||||||
|
<div class="generation-option-copy">
|
||||||
|
<strong>每个切片生成数量</strong>
|
||||||
|
<small>每个内容切片最多生成 3 个不同角度的问答对</small>
|
||||||
|
</div>
|
||||||
|
<el-input-number
|
||||||
|
:model-value="options.qaPairsPerChunk"
|
||||||
|
:min="1"
|
||||||
|
:max="3"
|
||||||
|
:step="1"
|
||||||
|
:precision="0"
|
||||||
|
controls-position="right"
|
||||||
|
aria-label="每个切片生成数量"
|
||||||
|
@update:model-value="updateUnstructuredNumber('qaPairsPerChunk', $event)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DatasetSplitEditor
|
||||||
|
:model-value="options.datasetSplit"
|
||||||
|
aria-label-prefix="非结构化"
|
||||||
|
@update:model-value="updateField('datasetSplit', $event)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-section model-options-section">
|
||||||
|
<div class="section-title-row">
|
||||||
|
<div>
|
||||||
|
<h3>大模型</h3>
|
||||||
|
<p>选择数据生成模型,并设置模型输出内容的要求</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="generation-option-list">
|
||||||
|
<GenerationOptionsPanel
|
||||||
|
:options="options"
|
||||||
|
:models="generationModels"
|
||||||
|
section="model"
|
||||||
|
:validation-message="validationAttempted ? generationValidationMessage : ''"
|
||||||
|
@update:options="updateGenerationOptions"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.form-section {
|
||||||
|
padding: 0 0 26px;
|
||||||
|
margin-bottom: 26px;
|
||||||
|
border-bottom: 1px solid #edf0f5;
|
||||||
|
|
||||||
|
&:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
border-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
margin: 0 0 16px;
|
||||||
|
color: #2f3747;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 650;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-title-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 16px;
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin: 0;
|
||||||
|
color: #8a93a3;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.generation-option-list {
|
||||||
|
display: grid;
|
||||||
|
gap: 12px;
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.compact-option-list {
|
||||||
|
gap: 8px;
|
||||||
|
|
||||||
|
.generation-option-row {
|
||||||
|
min-height: 58px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.generation-option-row {
|
||||||
|
display: flex;
|
||||||
|
min-height: 64px;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 24px;
|
||||||
|
padding: 12px 14px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border: 1px solid #e2e5ec;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.generation-option-copy {
|
||||||
|
display: grid;
|
||||||
|
gap: 4px;
|
||||||
|
|
||||||
|
strong {
|
||||||
|
color: #344054;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
small {
|
||||||
|
color: #8a93a3;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.chunk-settings-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||||
|
gap: 12px;
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-field {
|
||||||
|
display: grid;
|
||||||
|
align-content: start;
|
||||||
|
gap: 8px;
|
||||||
|
min-width: 0;
|
||||||
|
padding: 14px;
|
||||||
|
color: #344054;
|
||||||
|
background: #fff;
|
||||||
|
border: 1px solid #e2e5ec;
|
||||||
|
border-radius: 8px;
|
||||||
|
|
||||||
|
> small {
|
||||||
|
color: #8a93a3;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.el-select),
|
||||||
|
:deep(.el-input) {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.config-field-label {
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.unit-input {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
color: #7b8495;
|
||||||
|
font-size: 12px;
|
||||||
|
|
||||||
|
:deep(.el-input-number) {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.option-validation-message {
|
||||||
|
display: block;
|
||||||
|
margin: 8px 0 0;
|
||||||
|
color: #dc2626;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chunk-estimation-note {
|
||||||
|
margin: 9px 0 0;
|
||||||
|
color: #8a93a3;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.advanced-settings-toggle {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
min-height: 48px;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 16px;
|
||||||
|
margin-top: 12px;
|
||||||
|
padding: 10px 14px;
|
||||||
|
color: #344054;
|
||||||
|
text-align: left;
|
||||||
|
background: #fff;
|
||||||
|
border: 1px solid #e2e5ec;
|
||||||
|
border-radius: 8px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: border-color 0.18s ease, background-color 0.18s ease;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: #f8f7ff;
|
||||||
|
border-color: #b7b2f7;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:focus-visible {
|
||||||
|
outline: 2px solid #5b50f2;
|
||||||
|
outline-offset: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
> span {
|
||||||
|
display: grid;
|
||||||
|
gap: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
strong {
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
small {
|
||||||
|
color: #8a93a3;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
i {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
color: #7b8495;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.advanced-settings-panel {
|
||||||
|
display: grid;
|
||||||
|
gap: 12px;
|
||||||
|
margin-top: 8px;
|
||||||
|
padding: 12px;
|
||||||
|
background: #fff;
|
||||||
|
border: 1px solid #e2e5ec;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.advanced-settings-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 900px) {
|
||||||
|
.chunk-settings-grid,
|
||||||
|
.advanced-settings-grid {
|
||||||
|
grid-template-columns: minmax(0, 1fr);
|
||||||
|
}
|
||||||
|
|
||||||
|
.generation-option-row {
|
||||||
|
align-items: flex-start;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.compact-option-list .generation-option-row,
|
||||||
|
.advanced-protection-row {
|
||||||
|
align-items: center;
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
193
frontend/src/views/data-process/create/data-process-create.scss
Normal file
193
frontend/src/views/data-process/create/data-process-create.scss
Normal file
@@ -0,0 +1,193 @@
|
|||||||
|
.create-wizard-layout {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 100%;
|
||||||
|
border: 1px solid #eef0f5;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wizard-main {
|
||||||
|
flex: 1;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 32px;
|
||||||
|
|
||||||
|
&::-webkit-scrollbar {
|
||||||
|
width: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&::-webkit-scrollbar-thumb {
|
||||||
|
background: #cbd5e1;
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.wizard-main-inner {
|
||||||
|
min-height: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wizard-steps-container {
|
||||||
|
margin-bottom: 32px;
|
||||||
|
padding-bottom: 24px;
|
||||||
|
border-bottom: 1px dashed #e2e8f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.custom-wizard-steps {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
max-width: 860px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 0 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.step-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex: 1;
|
||||||
|
|
||||||
|
&:first-child {
|
||||||
|
flex: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.step-connector {
|
||||||
|
flex: 1;
|
||||||
|
height: 2px;
|
||||||
|
margin: 0 16px;
|
||||||
|
background-color: #e2e8f0;
|
||||||
|
transition: background-color 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.step-item.is-completed .step-connector,
|
||||||
|
.step-item.is-active .step-connector {
|
||||||
|
background-color: #5146e5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.step-node {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.step-icon {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 28px;
|
||||||
|
height: 28px;
|
||||||
|
color: #64748b;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 650;
|
||||||
|
background-color: #fff;
|
||||||
|
border: 2px solid #cbd5e1;
|
||||||
|
border-radius: 50%;
|
||||||
|
transition: all 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.step-title {
|
||||||
|
color: #64748b;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 600;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.step-item.is-active {
|
||||||
|
.step-icon {
|
||||||
|
color: #5146e5;
|
||||||
|
background-color: #eef2ff;
|
||||||
|
border-color: #5146e5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.step-title {
|
||||||
|
color: #1e293b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.step-item.is-completed {
|
||||||
|
.step-icon {
|
||||||
|
color: #fff;
|
||||||
|
background-color: #5146e5;
|
||||||
|
border-color: #5146e5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.step-title {
|
||||||
|
color: #1e293b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.wizard-content {
|
||||||
|
min-height: 400px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wizard-footer {
|
||||||
|
display: grid;
|
||||||
|
flex-shrink: 0;
|
||||||
|
grid-template-columns: 1fr auto 1fr;
|
||||||
|
align-items: center;
|
||||||
|
height: 64px;
|
||||||
|
padding: 0 32px;
|
||||||
|
background: #fff;
|
||||||
|
border-top: 1px solid #e2e8f0;
|
||||||
|
box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.02);
|
||||||
|
|
||||||
|
.footer-left {
|
||||||
|
justify-self: start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer-center {
|
||||||
|
justify-self: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer-right {
|
||||||
|
justify-self: end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.wizard-primary-action {
|
||||||
|
min-width: 160px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 760px) {
|
||||||
|
.wizard-main {
|
||||||
|
padding: 24px 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.custom-wizard-steps {
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.step-connector {
|
||||||
|
margin: 0 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.step-node {
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.step-title {
|
||||||
|
max-width: 72px;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.35;
|
||||||
|
white-space: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wizard-footer {
|
||||||
|
padding: 0 20px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 600px) {
|
||||||
|
.step-title {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.step-connector {
|
||||||
|
margin: 0 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wizard-primary-action {
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import type { StructuredProcessOptions, UnstructuredProcessOptions } from './types'
|
||||||
|
|
||||||
|
export const DEFAULT_GENERATION_PROMPT = '你是一名专业的数据生成助手。请根据输入内容生成准确、完整、可直接用于模型训练的问答数据。仅输出符合目标格式的内容,答案应事实清晰、语言自然,不要添加分析过程、说明或无关内容。'
|
||||||
|
|
||||||
|
export function createDefaultStructuredOptions(): StructuredProcessOptions {
|
||||||
|
return {
|
||||||
|
preprocessOptions: ['clean_invalid', 'detect_structure', 'deduplicate', 'normalize_format'],
|
||||||
|
semanticEnrichment: false,
|
||||||
|
qaPairsPerRow: 1,
|
||||||
|
datasetSplit: { train: 80, validation: 10, test: 10 },
|
||||||
|
generationModelId: '',
|
||||||
|
generationPrompt: DEFAULT_GENERATION_PROMPT,
|
||||||
|
temperature: 0.7,
|
||||||
|
maxTokens: 1024,
|
||||||
|
jsonMode: false,
|
||||||
|
qualityFilterEnabled: false,
|
||||||
|
filterLowQuality: true,
|
||||||
|
filterShortContent: true,
|
||||||
|
minOutputLength: 20,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createDefaultUnstructuredOptions(): UnstructuredProcessOptions {
|
||||||
|
return {
|
||||||
|
preprocessOptions: [
|
||||||
|
'clean_invalid_content',
|
||||||
|
'detect_document_structure',
|
||||||
|
'merge_short_content',
|
||||||
|
'filter_low_quality',
|
||||||
|
'deduplicate_content',
|
||||||
|
'preserve_context',
|
||||||
|
],
|
||||||
|
chunkMethod: 'semantic',
|
||||||
|
chunkSize: 800,
|
||||||
|
chunkOverlap: 100,
|
||||||
|
minChunkSize: 100,
|
||||||
|
customDelimiter: '',
|
||||||
|
preserveTables: true,
|
||||||
|
preserveCodeBlocks: true,
|
||||||
|
preserveLists: true,
|
||||||
|
semanticEnrichment: false,
|
||||||
|
qaPairsPerChunk: 1,
|
||||||
|
datasetSplit: { train: 80, validation: 10, test: 10 },
|
||||||
|
generationModelId: '',
|
||||||
|
generationPrompt: DEFAULT_GENERATION_PROMPT,
|
||||||
|
temperature: 0.7,
|
||||||
|
maxTokens: 1024,
|
||||||
|
jsonMode: false,
|
||||||
|
qualityFilterEnabled: false,
|
||||||
|
filterLowQuality: true,
|
||||||
|
filterShortContent: true,
|
||||||
|
minOutputLength: 20,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -71,6 +71,14 @@ export interface ExternalDataSource {
|
|||||||
limit: number
|
limit: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface UploadedDataFile {
|
||||||
|
uid: string | number
|
||||||
|
name: string
|
||||||
|
size: number
|
||||||
|
count: number
|
||||||
|
content: string
|
||||||
|
}
|
||||||
|
|
||||||
export interface SourceLine {
|
export interface SourceLine {
|
||||||
number: number
|
number: number
|
||||||
content: string
|
content: string
|
||||||
|
|||||||
147
frontend/src/views/data-process/create/useDataProcessDraft.ts
Normal file
147
frontend/src/views/data-process/create/useDataProcessDraft.ts
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
import { nextTick, type Reactive, type Ref } from 'vue'
|
||||||
|
import { ElMessage } from 'element-plus'
|
||||||
|
import type {
|
||||||
|
ExternalDataSource,
|
||||||
|
ProcessType,
|
||||||
|
StepId,
|
||||||
|
StructuredProcessOptions,
|
||||||
|
UnstructuredProcessOptions,
|
||||||
|
} from './types'
|
||||||
|
|
||||||
|
export const DATA_PROCESS_DRAFT_STORAGE_KEY = 'yg-data-process-create-draft'
|
||||||
|
export const DATA_PROCESS_DRAFT_SCHEMA_VERSION = 6
|
||||||
|
|
||||||
|
interface DraftSnapshot {
|
||||||
|
schemaVersion?: number
|
||||||
|
currentStepId?: StepId
|
||||||
|
task?: { name?: string; description?: string }
|
||||||
|
processType?: ProcessType
|
||||||
|
structuredOptions?: Partial<StructuredProcessOptions>
|
||||||
|
unstructuredOptions?: Partial<UnstructuredProcessOptions>
|
||||||
|
externalSource?: Partial<ExternalDataSource>
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DraftBindings {
|
||||||
|
currentStepId: Readonly<Ref<StepId>>
|
||||||
|
task: Reactive<{ name: string; description: string }>
|
||||||
|
processType: Ref<ProcessType>
|
||||||
|
structuredOptions: Ref<StructuredProcessOptions>
|
||||||
|
unstructuredOptions: Ref<UnstructuredProcessOptions>
|
||||||
|
externalSource: Reactive<ExternalDataSource>
|
||||||
|
restoringDraft: Ref<boolean>
|
||||||
|
dirty: Ref<boolean>
|
||||||
|
goToStep: (stepId: StepId) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
function sanitizeExternalSource(source: Partial<ExternalDataSource>) {
|
||||||
|
return {
|
||||||
|
type: typeof source.type === 'string' ? source.type : 'mysql',
|
||||||
|
url: typeof source.url === 'string' ? source.url : '',
|
||||||
|
authMode: typeof source.authMode === 'string' ? source.authMode : 'none',
|
||||||
|
username: typeof source.username === 'string' ? source.username : '',
|
||||||
|
limit: Number.isFinite(source.limit) ? Number(source.limit) : 1000,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function isDraftSnapshot(value: unknown): value is DraftSnapshot {
|
||||||
|
return Boolean(value && typeof value === 'object')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 只持久化可重建的配置。密码、令牌、文件正文、预览与结果都不进入 localStorage。
|
||||||
|
*/
|
||||||
|
export function useDataProcessDraft(bindings: DraftBindings) {
|
||||||
|
function draftSnapshot(): DraftSnapshot {
|
||||||
|
return {
|
||||||
|
schemaVersion: DATA_PROCESS_DRAFT_SCHEMA_VERSION,
|
||||||
|
currentStepId: bindings.currentStepId.value,
|
||||||
|
task: { ...bindings.task },
|
||||||
|
processType: bindings.processType.value,
|
||||||
|
structuredOptions: {
|
||||||
|
...bindings.structuredOptions.value,
|
||||||
|
preprocessOptions: [...bindings.structuredOptions.value.preprocessOptions],
|
||||||
|
datasetSplit: { ...bindings.structuredOptions.value.datasetSplit },
|
||||||
|
},
|
||||||
|
unstructuredOptions: {
|
||||||
|
...bindings.unstructuredOptions.value,
|
||||||
|
preprocessOptions: [...bindings.unstructuredOptions.value.preprocessOptions],
|
||||||
|
datasetSplit: { ...bindings.unstructuredOptions.value.datasetSplit },
|
||||||
|
},
|
||||||
|
externalSource: sanitizeExternalSource(bindings.externalSource),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeDraft(showWarning: boolean) {
|
||||||
|
try {
|
||||||
|
localStorage.setItem(DATA_PROCESS_DRAFT_STORAGE_KEY, JSON.stringify(draftSnapshot()))
|
||||||
|
} catch {
|
||||||
|
if (showWarning) ElMessage.warning('草稿保存失败,请检查浏览器存储空间')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function persistDraft() {
|
||||||
|
if (!bindings.restoringDraft.value) writeDraft(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
function restoreDraft() {
|
||||||
|
try {
|
||||||
|
const raw = localStorage.getItem(DATA_PROCESS_DRAFT_STORAGE_KEY)
|
||||||
|
if (!raw) return
|
||||||
|
const snapshot: unknown = JSON.parse(raw)
|
||||||
|
if (!isDraftSnapshot(snapshot)) return
|
||||||
|
|
||||||
|
bindings.restoringDraft.value = true
|
||||||
|
bindings.goToStep('create')
|
||||||
|
bindings.task.name = snapshot.task?.name || ''
|
||||||
|
bindings.task.description = snapshot.task?.description || ''
|
||||||
|
bindings.processType.value = snapshot.processType === 'structured' || snapshot.processType === 'external'
|
||||||
|
? snapshot.processType
|
||||||
|
: 'unstructured'
|
||||||
|
|
||||||
|
if (snapshot.structuredOptions) {
|
||||||
|
bindings.structuredOptions.value = {
|
||||||
|
...bindings.structuredOptions.value,
|
||||||
|
...snapshot.structuredOptions,
|
||||||
|
preprocessOptions: Array.isArray(snapshot.structuredOptions.preprocessOptions)
|
||||||
|
? snapshot.structuredOptions.preprocessOptions
|
||||||
|
: bindings.structuredOptions.value.preprocessOptions,
|
||||||
|
datasetSplit: {
|
||||||
|
...bindings.structuredOptions.value.datasetSplit,
|
||||||
|
...snapshot.structuredOptions.datasetSplit,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (snapshot.unstructuredOptions) {
|
||||||
|
bindings.unstructuredOptions.value = {
|
||||||
|
...bindings.unstructuredOptions.value,
|
||||||
|
...snapshot.unstructuredOptions,
|
||||||
|
preprocessOptions: Array.isArray(snapshot.unstructuredOptions.preprocessOptions)
|
||||||
|
? snapshot.unstructuredOptions.preprocessOptions
|
||||||
|
: bindings.unstructuredOptions.value.preprocessOptions,
|
||||||
|
datasetSplit: {
|
||||||
|
...bindings.unstructuredOptions.value.datasetSplit,
|
||||||
|
...snapshot.unstructuredOptions.datasetSplit,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.assign(bindings.externalSource, sanitizeExternalSource(snapshot.externalSource || {}), {
|
||||||
|
password: '',
|
||||||
|
token: '',
|
||||||
|
})
|
||||||
|
bindings.dirty.value = false
|
||||||
|
|
||||||
|
nextTick(() => {
|
||||||
|
bindings.restoringDraft.value = false
|
||||||
|
// 立即覆盖 v5 及更早草稿,清除其中可能存在的敏感值和大段正文。
|
||||||
|
writeDraft(false)
|
||||||
|
})
|
||||||
|
ElMessage.info('已恢复上次的任务配置,请重新上传或拉取源数据')
|
||||||
|
} catch {
|
||||||
|
localStorage.removeItem(DATA_PROCESS_DRAFT_STORAGE_KEY)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { draftSnapshot, persistDraft, restoreDraft }
|
||||||
|
}
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
import { reactive, ref, type Ref } from 'vue'
|
||||||
|
import { ElMessage } from 'element-plus'
|
||||||
|
import { createResults } from './previewModel'
|
||||||
|
import type {
|
||||||
|
GenerationState,
|
||||||
|
PreviewItem,
|
||||||
|
ProcessType,
|
||||||
|
ResultItem,
|
||||||
|
StructuredProcessOptions,
|
||||||
|
UnstructuredProcessOptions,
|
||||||
|
} from './types'
|
||||||
|
|
||||||
|
interface GenerationBindings {
|
||||||
|
previewItems: Ref<PreviewItem[]>
|
||||||
|
processType: Ref<ProcessType>
|
||||||
|
structuredOptions: Ref<StructuredProcessOptions>
|
||||||
|
unstructuredOptions: Ref<UnstructuredProcessOptions>
|
||||||
|
dirty: Ref<boolean>
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useDataProcessGeneration(bindings: GenerationBindings) {
|
||||||
|
const results = ref<ResultItem[]>([])
|
||||||
|
const selectedResultId = ref<string | null>(null)
|
||||||
|
const generation = reactive<GenerationState>({
|
||||||
|
status: 'idle',
|
||||||
|
progress: 0,
|
||||||
|
message: '确认摘要后即可开始生成,过程中可查看实时进度。',
|
||||||
|
})
|
||||||
|
let generationTimer: ReturnType<typeof setInterval> | null = null
|
||||||
|
|
||||||
|
function stopGenerationTimer() {
|
||||||
|
if (generationTimer) clearInterval(generationTimer)
|
||||||
|
generationTimer = null
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetDownstream() {
|
||||||
|
stopGenerationTimer()
|
||||||
|
generation.status = 'idle'
|
||||||
|
generation.progress = 0
|
||||||
|
generation.message = '确认摘要后即可开始生成,过程中可查看实时进度。'
|
||||||
|
results.value = []
|
||||||
|
selectedResultId.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
function startGeneration() {
|
||||||
|
stopGenerationTimer()
|
||||||
|
generation.status = 'running'
|
||||||
|
generation.progress = 0
|
||||||
|
generation.message = '正在应用预览修改并生成标准化结果,请稍候。'
|
||||||
|
|
||||||
|
generationTimer = setInterval(() => {
|
||||||
|
generation.progress = Math.min(100, generation.progress + 8)
|
||||||
|
if (generation.progress < 100) return
|
||||||
|
|
||||||
|
stopGenerationTimer()
|
||||||
|
generation.status = 'success'
|
||||||
|
results.value = createResults(
|
||||||
|
bindings.previewItems.value,
|
||||||
|
bindings.processType.value === 'structured'
|
||||||
|
? bindings.structuredOptions.value
|
||||||
|
: bindings.processType.value === 'unstructured'
|
||||||
|
? bindings.unstructuredOptions.value
|
||||||
|
: undefined,
|
||||||
|
)
|
||||||
|
generation.message = `已完成 ${results.value.length.toLocaleString()} 条数据处理,可进入结果页检查。`
|
||||||
|
selectedResultId.value = results.value[0]?.id ?? null
|
||||||
|
bindings.dirty.value = true
|
||||||
|
ElMessage.success('数据处理完成')
|
||||||
|
}, 180)
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopGeneration() {
|
||||||
|
stopGenerationTimer()
|
||||||
|
generation.status = 'failed'
|
||||||
|
generation.message = '任务已停止,预览修改仍然保留,可以重新生成。'
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateResultField(id: string, field: 'instruction' | 'input' | 'output', value: string) {
|
||||||
|
const item = results.value.find((entry) => entry.id === id)
|
||||||
|
if (!item) return
|
||||||
|
item[field] = value
|
||||||
|
const valid = item.instruction.trim() && item.output.trim()
|
||||||
|
item.error = valid ? undefined : 'Instruction 和 Output 不能为空'
|
||||||
|
const changed = item.instruction !== item.originalInstruction
|
||||||
|
|| item.input !== item.originalInput
|
||||||
|
|| item.output !== item.originalOutput
|
||||||
|
item.status = item.error ? 'invalid' : changed ? 'modified' : 'valid'
|
||||||
|
bindings.dirty.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function restoreResult(id: string) {
|
||||||
|
const item = results.value.find((entry) => entry.id === id)
|
||||||
|
if (!item) return
|
||||||
|
item.instruction = item.originalInstruction
|
||||||
|
item.input = item.originalInput
|
||||||
|
item.output = item.originalOutput
|
||||||
|
item.error = undefined
|
||||||
|
item.status = 'valid'
|
||||||
|
bindings.dirty.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateResults() {
|
||||||
|
let firstInvalidId: string | null = null
|
||||||
|
for (const item of results.value) {
|
||||||
|
if (!item.instruction.trim() || !item.output.trim()) {
|
||||||
|
item.error = 'Instruction 和 Output 不能为空'
|
||||||
|
item.status = 'invalid'
|
||||||
|
firstInvalidId ??= item.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (firstInvalidId) selectedResultId.value = firstInvalidId
|
||||||
|
return firstInvalidId == null
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
generation,
|
||||||
|
results,
|
||||||
|
selectedResultId,
|
||||||
|
resetDownstream,
|
||||||
|
restoreResult,
|
||||||
|
startGeneration,
|
||||||
|
stopGeneration,
|
||||||
|
stopGenerationTimer,
|
||||||
|
updateResultField,
|
||||||
|
validateResults,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,14 +14,13 @@ import {
|
|||||||
import { DATASET_TYPE_MAP, STORAGE_MAP } from '@/constants'
|
import { DATASET_TYPE_MAP, STORAGE_MAP } from '@/constants'
|
||||||
import { parseDatasetRecords, updateDatasetRecord } from './datasetRecords'
|
import { parseDatasetRecords, updateDatasetRecord } from './datasetRecords'
|
||||||
import type { DatasetRecord } from './datasetRecords'
|
import type { DatasetRecord } from './datasetRecords'
|
||||||
|
import DatasetVersionBar from './preview/DatasetVersionBar.vue'
|
||||||
|
import DatasetRecordTable from './preview/DatasetRecordTable.vue'
|
||||||
|
import DatasetRecordEditorDialog from './preview/DatasetRecordEditorDialog.vue'
|
||||||
|
import DatasetRawPreview from './preview/DatasetRawPreview.vue'
|
||||||
|
import type { EditField } from './preview/types'
|
||||||
import type { DatasetFile, DatasetItem, DatasetVersion } from '@/types'
|
import type { DatasetFile, DatasetItem, DatasetVersion } from '@/types'
|
||||||
|
|
||||||
interface EditField {
|
|
||||||
key: string
|
|
||||||
value: string
|
|
||||||
isJson: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const datasetId = route.params.id as string
|
const datasetId = route.params.id as string
|
||||||
|
|
||||||
@@ -32,9 +31,6 @@ const selectedFileId = ref('')
|
|||||||
const previewContent = ref('')
|
const previewContent = ref('')
|
||||||
const baseVersionContent = ref('')
|
const baseVersionContent = ref('')
|
||||||
const previewError = ref('')
|
const previewError = ref('')
|
||||||
const searchText = ref('')
|
|
||||||
const currentPage = ref(1)
|
|
||||||
const pageSize = 10
|
|
||||||
const editorVisible = ref(false)
|
const editorVisible = ref(false)
|
||||||
const editingRecord = ref<DatasetRecord | null>(null)
|
const editingRecord = ref<DatasetRecord | null>(null)
|
||||||
const editFields = ref<EditField[]>([])
|
const editFields = ref<EditField[]>([])
|
||||||
@@ -56,37 +52,9 @@ const totalLines = computed(() => previewContent.value ? previewContent.value.sp
|
|||||||
const recordResult = computed(() => parseDatasetRecords(previewContent.value, selectedFile.value?.name || ''))
|
const recordResult = computed(() => parseDatasetRecords(previewContent.value, selectedFile.value?.name || ''))
|
||||||
const isRecordFile = computed(() => recordResult.value.supported)
|
const isRecordFile = computed(() => recordResult.value.supported)
|
||||||
const records = computed(() => recordResult.value.records)
|
const records = computed(() => recordResult.value.records)
|
||||||
const invalidRecordCount = computed(() => records.value.filter((record) => record.kind === 'invalid').length)
|
|
||||||
const allTableFieldKeys = computed(() => {
|
|
||||||
const keys = new Set<string>()
|
|
||||||
records.value.forEach((record) => {
|
|
||||||
if (record.kind !== 'object') return
|
|
||||||
Object.keys(record.value as Record<string, unknown>).forEach((key) => keys.add(key))
|
|
||||||
})
|
|
||||||
const preferred = ['instruction', 'question', 'prompt', 'input', 'context', 'output', 'answer', 'response']
|
|
||||||
return [...keys].sort((a, b) => {
|
|
||||||
const rank = (key: string) => {
|
|
||||||
const index = preferred.indexOf(key)
|
|
||||||
return index === -1 ? preferred.length : index
|
|
||||||
}
|
|
||||||
return rank(a) - rank(b)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
const tableFieldKeys = computed(() => allTableFieldKeys.value.slice(0, 6))
|
|
||||||
const hasExtraTableFields = computed(() => allTableFieldKeys.value.length > tableFieldKeys.value.length)
|
|
||||||
const viewedVersion = computed(() => versions.value.find((item) => item.id === loadedVersionId.value))
|
const viewedVersion = computed(() => versions.value.find((item) => item.id === loadedVersionId.value))
|
||||||
const isViewingActiveVersion = computed(() => Boolean(loadedVersionId.value) && loadedVersionId.value === activeVersionId.value)
|
const isViewingActiveVersion = computed(() => Boolean(loadedVersionId.value) && loadedVersionId.value === activeVersionId.value)
|
||||||
const nextVersionNumber = computed(() => Math.max(0, ...versions.value.map((item) => item.version)) + 1)
|
const nextVersionNumber = computed(() => Math.max(0, ...versions.value.map((item) => item.version)) + 1)
|
||||||
const filteredRecords = computed(() => {
|
|
||||||
const query = searchText.value.trim().toLowerCase()
|
|
||||||
if (!query) return records.value
|
|
||||||
return records.value.filter((record) => JSON.stringify(record.value).toLowerCase().includes(query))
|
|
||||||
})
|
|
||||||
const pagedRecords = computed(() => {
|
|
||||||
const start = (currentPage.value - 1) * pageSize
|
|
||||||
return filteredRecords.value.slice(start, start + pageSize)
|
|
||||||
})
|
|
||||||
const rawPreviewLines = computed(() => previewContent.value ? previewContent.value.split('\n').slice(0, 100) : [])
|
|
||||||
const currentDraft = computed(() => editingRecord.value?.kind === 'object'
|
const currentDraft = computed(() => editingRecord.value?.kind === 'object'
|
||||||
? JSON.stringify(editFields.value)
|
? JSON.stringify(editFields.value)
|
||||||
: rawDraft.value)
|
: rawDraft.value)
|
||||||
@@ -105,47 +73,10 @@ const createdAt = computed(() => dataset.value?.create_time
|
|||||||
? new Date(dataset.value.create_time).toLocaleString('zh-CN')
|
? new Date(dataset.value.create_time).toLocaleString('zh-CN')
|
||||||
: '-')
|
: '-')
|
||||||
|
|
||||||
function formatVersionTime(value: string) {
|
|
||||||
return new Date(value).toLocaleString('zh-CN', { hour12: false })
|
|
||||||
}
|
|
||||||
|
|
||||||
function versionOptionLabel(version: DatasetVersion) {
|
|
||||||
const status = version.id === activeVersionId.value ? '当前版本' : '历史版本'
|
|
||||||
return `V${version.version} · ${status} · ${formatVersionTime(version.create_time)}`
|
|
||||||
}
|
|
||||||
|
|
||||||
function fileKey(file: DatasetFile) {
|
function fileKey(file: DatasetFile) {
|
||||||
return String(file.id || file.name)
|
return String(file.id || file.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatFieldValue(value: unknown) {
|
|
||||||
if (typeof value === 'string') return value || '(空)'
|
|
||||||
return JSON.stringify(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
function asDatasetRecord(row: unknown) {
|
|
||||||
return row as DatasetRecord
|
|
||||||
}
|
|
||||||
|
|
||||||
function recordFieldValue(record: DatasetRecord, key: string) {
|
|
||||||
if (record.kind !== 'object') return record.kind === 'invalid' ? record.raw : formatFieldValue(record.value)
|
|
||||||
const data = record.value as Record<string, unknown>
|
|
||||||
return Object.prototype.hasOwnProperty.call(data, key) ? formatFieldValue(data[key]) : '-'
|
|
||||||
}
|
|
||||||
|
|
||||||
function extraFieldValue(record: DatasetRecord) {
|
|
||||||
if (record.kind !== 'object') return '-'
|
|
||||||
const data = record.value as Record<string, unknown>
|
|
||||||
return allTableFieldKeys.value
|
|
||||||
.filter((key) => !tableFieldKeys.value.includes(key) && Object.prototype.hasOwnProperty.call(data, key))
|
|
||||||
.map((key) => `${key}: ${formatFieldValue(data[key])}`)
|
|
||||||
.join(';') || '-'
|
|
||||||
}
|
|
||||||
|
|
||||||
function recordRowClassName({ row }: { row: unknown }) {
|
|
||||||
return asDatasetRecord(row).kind === 'invalid' ? 'record-table-row-invalid' : ''
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadDataset() {
|
async function loadDataset() {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
@@ -174,6 +105,7 @@ async function loadVersions(file: DatasetFile) {
|
|||||||
loadedVersionId.value = result.active_version_id
|
loadedVersionId.value = result.active_version_id
|
||||||
previewContent.value = activeContent.content
|
previewContent.value = activeContent.content
|
||||||
baseVersionContent.value = activeContent.content
|
baseVersionContent.value = activeContent.content
|
||||||
|
resetRecordEditor()
|
||||||
} catch {
|
} catch {
|
||||||
if (requestId === versionRequestId) previewError.value = '版本内容加载失败,请稍后重试'
|
if (requestId === versionRequestId) previewError.value = '版本内容加载失败,请稍后重试'
|
||||||
} finally {
|
} finally {
|
||||||
@@ -197,8 +129,7 @@ async function handleViewedVersionChange(nextVersionId: string) {
|
|||||||
previewContent.value = result.content
|
previewContent.value = result.content
|
||||||
baseVersionContent.value = result.content
|
baseVersionContent.value = result.content
|
||||||
loadedVersionId.value = result.version.id
|
loadedVersionId.value = result.version.id
|
||||||
currentPage.value = 1
|
resetRecordEditor()
|
||||||
searchText.value = ''
|
|
||||||
} catch {
|
} catch {
|
||||||
if (requestId === versionRequestId) selectedVersionId.value = previousVersionId
|
if (requestId === versionRequestId) selectedVersionId.value = previousVersionId
|
||||||
} finally {
|
} finally {
|
||||||
@@ -259,6 +190,19 @@ function openRecordEditor(record: DatasetRecord) {
|
|||||||
originalDraft.value = record.kind === 'object' ? JSON.stringify(editFields.value) : rawDraft.value
|
originalDraft.value = record.kind === 'object' ? JSON.stringify(editFields.value) : rawDraft.value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resetRecordEditor() {
|
||||||
|
editorVisible.value = false
|
||||||
|
editingRecord.value = null
|
||||||
|
editFields.value = []
|
||||||
|
rawDraft.value = ''
|
||||||
|
originalDraft.value = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateEditField(index: number, value: string) {
|
||||||
|
const field = editFields.value[index]
|
||||||
|
if (field) field.value = value
|
||||||
|
}
|
||||||
|
|
||||||
async function confirmDiscardChanges(message = '当前存在尚未保存为版本的修改,放弃后将无法恢复。') {
|
async function confirmDiscardChanges(message = '当前存在尚未保存为版本的修改,放弃后将无法恢复。') {
|
||||||
if (!hasUnsavedChanges.value) return true
|
if (!hasUnsavedChanges.value) return true
|
||||||
try {
|
try {
|
||||||
@@ -287,18 +231,11 @@ async function confirmEditorDiscardChanges() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function closeRecordEditor() {
|
async function closeRecordEditor(done?: () => void) {
|
||||||
if (savingRecord.value) return
|
if (savingRecord.value) return
|
||||||
if (!await confirmEditorDiscardChanges()) return
|
if (!await confirmEditorDiscardChanges()) return
|
||||||
editorVisible.value = false
|
resetRecordEditor()
|
||||||
editingRecord.value = null
|
done?.()
|
||||||
}
|
|
||||||
|
|
||||||
async function handleDialogBeforeClose(done: () => void) {
|
|
||||||
if (savingRecord.value) return
|
|
||||||
if (!await confirmEditorDiscardChanges()) return
|
|
||||||
editingRecord.value = null
|
|
||||||
done()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildNextRecordValue() {
|
function buildNextRecordValue() {
|
||||||
@@ -330,9 +267,7 @@ async function saveRecord() {
|
|||||||
nextValue,
|
nextValue,
|
||||||
)
|
)
|
||||||
previewContent.value = nextContent
|
previewContent.value = nextContent
|
||||||
originalDraft.value = currentDraft.value
|
resetRecordEditor()
|
||||||
editorVisible.value = false
|
|
||||||
editingRecord.value = null
|
|
||||||
ElMessage.success(`第 ${record.displayIndex} 条修改已暂存`)
|
ElMessage.success(`第 ${record.displayIndex} 条修改已暂存`)
|
||||||
} finally {
|
} finally {
|
||||||
savingRecord.value = false
|
savingRecord.value = false
|
||||||
@@ -370,13 +305,6 @@ async function saveVersion() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleEditorKeydown(event: KeyboardEvent) {
|
|
||||||
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === 's') {
|
|
||||||
event.preventDefault()
|
|
||||||
saveRecord()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleBeforeUnload(event: BeforeUnloadEvent) {
|
function handleBeforeUnload(event: BeforeUnloadEvent) {
|
||||||
if (!hasUnsavedChanges.value) return
|
if (!hasUnsavedChanges.value) return
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
@@ -419,46 +347,19 @@ onBeforeUnmount(() => window.removeEventListener('beforeunload', handleBeforeUnl
|
|||||||
<div class="overview-item overview-item-wide"><span>创建时间</span><strong>{{ createdAt }}</strong></div>
|
<div class="overview-item overview-item-wide"><span>创建时间</span><strong>{{ createdAt }}</strong></div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="version-control-bar" aria-label="数据集版本控制">
|
<DatasetVersionBar
|
||||||
<div class="version-selector-group">
|
|
||||||
<label for="dataset-version-select">数据版本</label>
|
|
||||||
<el-select
|
|
||||||
id="dataset-version-select"
|
|
||||||
v-model="selectedVersionId"
|
v-model="selectedVersionId"
|
||||||
class="version-select"
|
:versions="versions"
|
||||||
:loading="versionLoading"
|
:viewed-version="viewedVersion"
|
||||||
:disabled="versionLoading || savingRecord"
|
:active-version-id="activeVersionId"
|
||||||
aria-label="选择要查看的数据集版本"
|
:is-viewing-active-version="isViewingActiveVersion"
|
||||||
|
:has-pending-version-changes="hasPendingVersionChanges"
|
||||||
|
:version-loading="versionLoading"
|
||||||
|
:saving-record="savingRecord"
|
||||||
|
:activating-version="activatingVersion"
|
||||||
@change="handleViewedVersionChange"
|
@change="handleViewedVersionChange"
|
||||||
>
|
@activate="activateViewedVersion"
|
||||||
<el-option
|
|
||||||
v-for="version in versions"
|
|
||||||
:key="version.id"
|
|
||||||
:label="versionOptionLabel(version)"
|
|
||||||
:value="version.id"
|
|
||||||
/>
|
/>
|
||||||
</el-select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="version-status" role="status" aria-live="polite">
|
|
||||||
<template v-if="viewedVersion">
|
|
||||||
<el-tag v-if="isViewingActiveVersion" type="success">V{{ viewedVersion.version }} · 当前版本</el-tag>
|
|
||||||
<el-tag v-else type="info">V{{ viewedVersion.version }} · 历史版本(只读)</el-tag>
|
|
||||||
<el-tag v-if="hasPendingVersionChanges" type="warning">有待保存修改</el-tag>
|
|
||||||
<span>{{ viewedVersion.description || '无版本说明' }} · {{ formatVersionTime(viewedVersion.create_time) }}</span>
|
|
||||||
</template>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<el-button
|
|
||||||
v-if="viewedVersion && !isViewingActiveVersion"
|
|
||||||
type="primary"
|
|
||||||
:loading="activatingVersion"
|
|
||||||
@click="activateViewedVersion"
|
|
||||||
>
|
|
||||||
<i class="fa fa-check-circle" />
|
|
||||||
设为当前版本
|
|
||||||
</el-button>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<el-alert
|
<el-alert
|
||||||
v-if="viewedVersion && !isViewingActiveVersion"
|
v-if="viewedVersion && !isViewingActiveVersion"
|
||||||
@@ -508,78 +409,19 @@ onBeforeUnmount(() => window.removeEventListener('beforeunload', handleBeforeUnl
|
|||||||
</div>
|
</div>
|
||||||
<div v-else-if="!previewContent" class="viewer-state"><i class="fa fa-file-o" aria-hidden="true" /><span>当前文件暂无可预览内容</span></div>
|
<div v-else-if="!previewContent" class="viewer-state"><i class="fa fa-file-o" aria-hidden="true" /><span>当前文件暂无可预览内容</span></div>
|
||||||
|
|
||||||
<div v-else-if="isRecordFile" class="records-viewer">
|
<DatasetRecordTable
|
||||||
<div class="records-toolbar">
|
v-else-if="isRecordFile"
|
||||||
<div><strong>样本数据</strong><span>共 {{ records.length.toLocaleString() }} 条</span><el-tag v-if="invalidRecordCount" size="small" type="danger">{{ invalidRecordCount }} 条格式错误</el-tag></div>
|
:records="records"
|
||||||
<el-input v-model="searchText" class="record-search" clearable placeholder="搜索样本内容" aria-label="搜索样本内容" @input="currentPage = 1">
|
:is-viewing-active-version="isViewingActiveVersion"
|
||||||
<template #prefix><i class="fa fa-search" /></template>
|
:version-id="loadedVersionId"
|
||||||
</el-input>
|
@edit="openRecordEditor"
|
||||||
</div>
|
/>
|
||||||
|
|
||||||
<div v-if="!filteredRecords.length" class="viewer-state record-empty-state"><i class="fa fa-search" aria-hidden="true" /><span>没有找到匹配的样本</span></div>
|
<DatasetRawPreview
|
||||||
<div v-else class="record-table-shell" aria-label="数据样本表格">
|
v-else
|
||||||
<el-table
|
:content="previewContent"
|
||||||
:data="pagedRecords"
|
:file-name="selectedFile?.name"
|
||||||
row-key="sourceIndex"
|
/>
|
||||||
stripe
|
|
||||||
border
|
|
||||||
class="record-table"
|
|
||||||
:row-class-name="recordRowClassName"
|
|
||||||
>
|
|
||||||
<el-table-column label="序号" width="76" align="center">
|
|
||||||
<template #default="{ row }">
|
|
||||||
<div class="table-index">
|
|
||||||
<strong>{{ asDatasetRecord(row).displayIndex }}</strong>
|
|
||||||
<small>第 {{ asDatasetRecord(row).sourceIndex + 1 }} 行</small>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column v-for="fieldKey in tableFieldKeys" :key="fieldKey" :label="fieldKey" min-width="220">
|
|
||||||
<template #default="{ row }">
|
|
||||||
<el-tooltip :content="recordFieldValue(asDatasetRecord(row), fieldKey)" placement="top" :show-after="400">
|
|
||||||
<div class="table-cell-text">{{ recordFieldValue(asDatasetRecord(row), fieldKey) }}</div>
|
|
||||||
</el-tooltip>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column v-if="hasExtraTableFields" label="其他字段" min-width="240">
|
|
||||||
<template #default="{ row }">
|
|
||||||
<el-tooltip :content="extraFieldValue(asDatasetRecord(row))" placement="top" :show-after="400">
|
|
||||||
<div class="table-cell-text">{{ extraFieldValue(asDatasetRecord(row)) }}</div>
|
|
||||||
</el-tooltip>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column label="状态" width="96" align="center">
|
|
||||||
<template #default="{ row }">
|
|
||||||
<el-tag v-if="asDatasetRecord(row).kind === 'invalid'" size="small" type="danger">格式错误</el-tag>
|
|
||||||
<el-tag v-else-if="asDatasetRecord(row).kind === 'primitive'" size="small" type="warning">非对象</el-tag>
|
|
||||||
<el-tag v-else size="small" type="success">正常</el-tag>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column label="操作" width="96" align="center" fixed="right">
|
|
||||||
<template #default="{ row }">
|
|
||||||
<el-button
|
|
||||||
type="primary"
|
|
||||||
link
|
|
||||||
:disabled="!isViewingActiveVersion"
|
|
||||||
:title="isViewingActiveVersion ? '' : '历史版本为只读,请先设为当前版本'"
|
|
||||||
:aria-label="`${asDatasetRecord(row).kind === 'invalid' ? '修复' : '编辑'}第 ${asDatasetRecord(row).displayIndex} 条数据`"
|
|
||||||
@click="openRecordEditor(asDatasetRecord(row))"
|
|
||||||
>
|
|
||||||
<i :class="asDatasetRecord(row).kind === 'invalid' ? 'fa fa-wrench' : 'fa fa-pencil'" />
|
|
||||||
{{ asDatasetRecord(row).kind === 'invalid' ? '修复' : '编辑' }}
|
|
||||||
</el-button>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
</el-table>
|
|
||||||
</div>
|
|
||||||
<div v-if="filteredRecords.length > pageSize" class="records-pagination">
|
|
||||||
<el-pagination v-model:current-page="currentPage" :page-size="pageSize" :total="filteredRecords.length" layout="prev, pager, next" background />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-else class="code-viewer" tabindex="0" :aria-label="`${selectedFile?.name || ''} 文件内容`">
|
|
||||||
<div v-for="(line, index) in rawPreviewLines" :key="index" class="code-line"><span class="line-number" aria-hidden="true">{{ index + 1 }}</span><code>{{ line || ' ' }}</code></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="viewer-footer"><span v-if="isRecordFile"><i class="fa fa-list-alt" aria-hidden="true" /> 逐条查看与编辑</span><span v-else><i class="fa fa-eye" aria-hidden="true" /> 文本预览</span><span>UTF-8</span></div>
|
<div class="viewer-footer"><span v-if="isRecordFile"><i class="fa fa-list-alt" aria-hidden="true" /> 逐条查看与编辑</span><span v-else><i class="fa fa-eye" aria-hidden="true" /> 文本预览</span><span>UTF-8</span></div>
|
||||||
@@ -590,30 +432,19 @@ onBeforeUnmount(() => window.removeEventListener('beforeunload', handleBeforeUnl
|
|||||||
<span class="empty-icon" aria-hidden="true"><i class="fa fa-folder-open-o" /></span><h2>暂无数据文件</h2><p>该数据集还没有可供预览的文件。</p>
|
<span class="empty-icon" aria-hidden="true"><i class="fa fa-folder-open-o" /></span><h2>暂无数据文件</h2><p>该数据集还没有可供预览的文件。</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<el-dialog v-model="editorVisible" class="record-editor-dialog" width="min(720px, 92vw)" :title="editingRecord ? `编辑第 ${editingRecord.displayIndex} 条数据` : '编辑数据'" :close-on-click-modal="false" :close-on-press-escape="!savingRecord" :show-close="!savingRecord" :before-close="handleDialogBeforeClose" destroy-on-close>
|
<DatasetRecordEditorDialog
|
||||||
<div v-if="editingRecord" class="record-editor" @keydown="handleEditorKeydown">
|
:model-value="editorVisible"
|
||||||
<div class="editor-hint">
|
:record="editingRecord"
|
||||||
<i class="fa fa-info-circle" aria-hidden="true" />
|
:edit-fields="editFields"
|
||||||
当前修改会先暂存;完成多条修改后,点击文件工具栏中的“保存版本”创建 V{{ nextVersionNumber }}。
|
:raw-draft="rawDraft"
|
||||||
</div>
|
:saving-record="savingRecord"
|
||||||
<el-form v-if="editingRecord.kind === 'object'" label-position="top">
|
:has-draft-changes="hasEditorDraftChanges"
|
||||||
<el-form-item v-for="field in editFields" :key="field.key" :label="field.key">
|
:next-version-number="nextVersionNumber"
|
||||||
<el-input v-model="field.value" type="textarea" :rows="field.isJson ? 5 : 3" :aria-label="`编辑字段 ${field.key}`" :placeholder="field.isJson ? '请输入合法 JSON' : `请输入 ${field.key}`" />
|
@close="closeRecordEditor"
|
||||||
<small v-if="field.isJson" class="field-helper">该字段为对象、数组或数值,请保持合法 JSON 格式。</small>
|
@save="saveRecord"
|
||||||
</el-form-item>
|
@update:field="updateEditField"
|
||||||
</el-form>
|
@update:raw-draft="rawDraft = $event"
|
||||||
<div v-else class="raw-record-editor">
|
/>
|
||||||
<label for="raw-record-draft">{{ editingRecord.kind === 'invalid' ? '修复 JSON 内容' : 'JSON 内容' }}</label>
|
|
||||||
<el-input id="raw-record-draft" v-model="rawDraft" type="textarea" :rows="10" aria-label="编辑当前条 JSON 内容" placeholder="请输入合法 JSON" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<template #footer>
|
|
||||||
<div class="record-editor-actions">
|
|
||||||
<span>{{ hasEditorDraftChanges ? '有未暂存修改' : '尚未修改' }} · Ctrl/⌘ + S 暂存</span>
|
|
||||||
<div><el-button :disabled="savingRecord" @click="closeRecordEditor">取消</el-button><el-button type="primary" :loading="savingRecord" :disabled="!hasEditorDraftChanges" @click="saveRecord">暂存修改</el-button></div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</el-dialog>
|
|
||||||
</PageCard>
|
</PageCard>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -715,61 +546,6 @@ onBeforeUnmount(() => window.removeEventListener('beforeunload', handleBeforeUnl
|
|||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.version-control-bar {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 16px;
|
|
||||||
min-height: 64px;
|
|
||||||
margin-bottom: 12px;
|
|
||||||
padding: 10px 14px;
|
|
||||||
box-sizing: border-box;
|
|
||||||
border: 1px solid #dfe5ee;
|
|
||||||
border-radius: 10px;
|
|
||||||
background: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
.version-selector-group {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 10px;
|
|
||||||
flex: 0 0 auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.version-selector-group label {
|
|
||||||
color: #344054;
|
|
||||||
font-size: 13px;
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
.version-select {
|
|
||||||
width: 300px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.version-status {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
flex: 1;
|
|
||||||
gap: 10px;
|
|
||||||
min-width: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.version-status > span {
|
|
||||||
overflow: hidden;
|
|
||||||
color: #7c8799;
|
|
||||||
font-size: 12px;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.version-control-bar > .el-button {
|
|
||||||
min-height: 40px;
|
|
||||||
flex: 0 0 auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.version-control-bar > .el-button i {
|
|
||||||
margin-right: 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.historical-version-alert {
|
.historical-version-alert {
|
||||||
margin-bottom: 12px;
|
margin-bottom: 12px;
|
||||||
}
|
}
|
||||||
@@ -868,153 +644,6 @@ onBeforeUnmount(() => window.removeEventListener('beforeunload', handleBeforeUnl
|
|||||||
background: #fbfcfe;
|
background: #fbfcfe;
|
||||||
}
|
}
|
||||||
|
|
||||||
.records-viewer {
|
|
||||||
min-height: 468px;
|
|
||||||
padding: 16px;
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
.records-toolbar {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
gap: 16px;
|
|
||||||
margin-bottom: 14px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.records-toolbar > div {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 8px;
|
|
||||||
min-width: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.records-toolbar strong {
|
|
||||||
color: #253047;
|
|
||||||
font-size: 14px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.records-toolbar span {
|
|
||||||
color: #8a94a6;
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.record-search {
|
|
||||||
width: 240px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.record-table-shell {
|
|
||||||
overflow: hidden;
|
|
||||||
border: 1px solid #e4e9f1;
|
|
||||||
border-radius: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.record-table {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.record-table :deep(.el-table__header th) {
|
|
||||||
height: 44px;
|
|
||||||
background: #f5f7fa;
|
|
||||||
color: #475467;
|
|
||||||
font-size: 12px;
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
.record-table :deep(.el-table__cell) {
|
|
||||||
padding: 10px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.record-table :deep(.record-table-row-invalid td) {
|
|
||||||
background: #fff7f7 !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.table-index {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 1px;
|
|
||||||
color: #667085;
|
|
||||||
font-variant-numeric: tabular-nums;
|
|
||||||
}
|
|
||||||
|
|
||||||
.table-index strong {
|
|
||||||
font-size: 13px;
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
.table-index small {
|
|
||||||
color: #98a2b3;
|
|
||||||
font-size: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.table-cell-text {
|
|
||||||
display: -webkit-box;
|
|
||||||
overflow: hidden;
|
|
||||||
color: #526076;
|
|
||||||
font-size: 12px;
|
|
||||||
line-height: 1.6;
|
|
||||||
overflow-wrap: anywhere;
|
|
||||||
-webkit-box-orient: vertical;
|
|
||||||
-webkit-line-clamp: 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.record-table .el-button i {
|
|
||||||
margin-right: 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.records-pagination {
|
|
||||||
display: flex;
|
|
||||||
justify-content: flex-end;
|
|
||||||
margin-top: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.record-empty-state {
|
|
||||||
min-height: 320px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.code-viewer {
|
|
||||||
height: 100%;
|
|
||||||
max-height: 468px;
|
|
||||||
overflow: auto;
|
|
||||||
padding: 12px 0 18px;
|
|
||||||
outline: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.code-viewer:focus-visible {
|
|
||||||
box-shadow: inset 0 0 0 2px var(--el-color-primary-light-5);
|
|
||||||
}
|
|
||||||
|
|
||||||
.code-line {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 54px minmax(0, 1fr);
|
|
||||||
min-height: 25px;
|
|
||||||
color: #344054;
|
|
||||||
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
|
|
||||||
font-size: 12px;
|
|
||||||
line-height: 1.65;
|
|
||||||
}
|
|
||||||
|
|
||||||
.code-line:hover {
|
|
||||||
background: #f4f6fa;
|
|
||||||
}
|
|
||||||
|
|
||||||
.line-number {
|
|
||||||
padding-right: 14px;
|
|
||||||
border-right: 1px solid #edf0f5;
|
|
||||||
color: #a4adbc;
|
|
||||||
font-variant-numeric: tabular-nums;
|
|
||||||
text-align: right;
|
|
||||||
user-select: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.code-line code {
|
|
||||||
display: block;
|
|
||||||
min-width: max-content;
|
|
||||||
padding: 0 18px;
|
|
||||||
white-space: pre;
|
|
||||||
}
|
|
||||||
|
|
||||||
.viewer-state {
|
.viewer-state {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -1057,47 +686,6 @@ onBeforeUnmount(() => window.removeEventListener('beforeunload', handleBeforeUnl
|
|||||||
margin-right: 5px;
|
margin-right: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.editor-hint {
|
|
||||||
margin-bottom: 18px;
|
|
||||||
padding: 10px 12px;
|
|
||||||
border: 1px solid #dbe2ff;
|
|
||||||
border-radius: 8px;
|
|
||||||
background: #f5f7ff;
|
|
||||||
color: #56627a;
|
|
||||||
font-size: 13px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.editor-hint i {
|
|
||||||
margin-right: 6px;
|
|
||||||
color: var(--primary-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.field-helper {
|
|
||||||
margin-top: 5px;
|
|
||||||
color: #8a94a6;
|
|
||||||
line-height: 1.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
.raw-record-editor label {
|
|
||||||
display: block;
|
|
||||||
margin-bottom: 8px;
|
|
||||||
color: #344054;
|
|
||||||
font-size: 13px;
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
.record-editor-actions {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
gap: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.record-editor-actions > span {
|
|
||||||
color: #8a94a6;
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.empty-files {
|
.empty-files {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -1149,18 +737,6 @@ onBeforeUnmount(() => window.removeEventListener('beforeunload', handleBeforeUnl
|
|||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
}
|
}
|
||||||
|
|
||||||
.version-control-bar,
|
|
||||||
.version-selector-group,
|
|
||||||
.version-status {
|
|
||||||
align-items: stretch;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
.version-select,
|
|
||||||
.version-control-bar > .el-button {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.overview-item {
|
.overview-item {
|
||||||
padding: 0 0 12px;
|
padding: 0 0 12px;
|
||||||
border-right: 0;
|
border-right: 0;
|
||||||
@@ -1176,22 +752,6 @@ onBeforeUnmount(() => window.removeEventListener('beforeunload', handleBeforeUnl
|
|||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
}
|
}
|
||||||
|
|
||||||
.records-toolbar,
|
|
||||||
.record-editor-actions {
|
|
||||||
align-items: stretch;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
.record-search {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.record-editor-actions > div {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 1fr 1fr;
|
|
||||||
gap: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.download-button {
|
.download-button {
|
||||||
width: 44px;
|
width: 44px;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
@@ -1204,7 +764,4 @@ onBeforeUnmount(() => window.removeEventListener('beforeunload', handleBeforeUnl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-reduced-motion: reduce) {
|
|
||||||
.record-table :deep(.el-table__row) { transition: none; }
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
63
frontend/src/views/dataset/preview/DatasetRawPreview.vue
Normal file
63
frontend/src/views/dataset/preview/DatasetRawPreview.vue
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed } from 'vue'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
content: string
|
||||||
|
fileName?: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const lines = computed(() => props.content.split('\n').slice(0, 100))
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="code-viewer" tabindex="0" :aria-label="`${fileName || ''} 文件内容`">
|
||||||
|
<div v-for="(line, index) in lines" :key="index" class="code-line">
|
||||||
|
<span class="line-number" aria-hidden="true">{{ index + 1 }}</span>
|
||||||
|
<code>{{ line || ' ' }}</code>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.code-viewer {
|
||||||
|
height: 100%;
|
||||||
|
max-height: 468px;
|
||||||
|
overflow: auto;
|
||||||
|
padding: 12px 0 18px;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.code-viewer:focus-visible {
|
||||||
|
box-shadow: inset 0 0 0 2px var(--el-color-primary-light-5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.code-line {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 54px minmax(0, 1fr);
|
||||||
|
min-height: 25px;
|
||||||
|
color: #344054;
|
||||||
|
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.65;
|
||||||
|
}
|
||||||
|
|
||||||
|
.code-line:hover {
|
||||||
|
background: #f4f6fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.line-number {
|
||||||
|
padding-right: 14px;
|
||||||
|
border-right: 1px solid #edf0f5;
|
||||||
|
color: #a4adbc;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
text-align: right;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.code-line code {
|
||||||
|
display: block;
|
||||||
|
min-width: max-content;
|
||||||
|
padding: 0 18px;
|
||||||
|
white-space: pre;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
155
frontend/src/views/dataset/preview/DatasetRecordEditorDialog.vue
Normal file
155
frontend/src/views/dataset/preview/DatasetRecordEditorDialog.vue
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { DatasetRecord } from '../datasetRecords'
|
||||||
|
import type { EditField } from './types'
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
modelValue: boolean
|
||||||
|
record: DatasetRecord | null
|
||||||
|
editFields: EditField[]
|
||||||
|
rawDraft: string
|
||||||
|
savingRecord: boolean
|
||||||
|
hasDraftChanges: boolean
|
||||||
|
nextVersionNumber: number
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
close: [done?: () => void]
|
||||||
|
save: []
|
||||||
|
'update:field': [index: number, value: string]
|
||||||
|
'update:rawDraft': [value: string]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
function handleBeforeClose(done: () => void) {
|
||||||
|
emit('close', done)
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleKeydown(event: KeyboardEvent) {
|
||||||
|
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === 's') {
|
||||||
|
event.preventDefault()
|
||||||
|
emit('save')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<el-dialog
|
||||||
|
:model-value="modelValue"
|
||||||
|
class="record-editor-dialog"
|
||||||
|
width="min(720px, 92vw)"
|
||||||
|
:title="record ? `编辑第 ${record.displayIndex} 条数据` : '编辑数据'"
|
||||||
|
:close-on-click-modal="false"
|
||||||
|
:close-on-press-escape="!savingRecord"
|
||||||
|
:show-close="!savingRecord"
|
||||||
|
:before-close="handleBeforeClose"
|
||||||
|
destroy-on-close
|
||||||
|
>
|
||||||
|
<div v-if="record" class="record-editor" @keydown="handleKeydown">
|
||||||
|
<div class="editor-hint">
|
||||||
|
<i class="fa fa-info-circle" aria-hidden="true" />
|
||||||
|
当前修改会先暂存;完成多条修改后,点击文件工具栏中的“保存版本”创建
|
||||||
|
V{{ nextVersionNumber }}。
|
||||||
|
</div>
|
||||||
|
<el-form v-if="record.kind === 'object'" label-position="top">
|
||||||
|
<el-form-item v-for="(field, index) in editFields" :key="field.key" :label="field.key">
|
||||||
|
<el-input
|
||||||
|
:model-value="field.value"
|
||||||
|
type="textarea"
|
||||||
|
:rows="field.isJson ? 5 : 3"
|
||||||
|
:aria-label="`编辑字段 ${field.key}`"
|
||||||
|
:placeholder="field.isJson ? '请输入合法 JSON' : `请输入 ${field.key}`"
|
||||||
|
@update:model-value="emit('update:field', index, $event)"
|
||||||
|
/>
|
||||||
|
<small v-if="field.isJson" class="field-helper">
|
||||||
|
该字段为对象、数组或数值,请保持合法 JSON 格式。
|
||||||
|
</small>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<div v-else class="raw-record-editor">
|
||||||
|
<label for="raw-record-draft">
|
||||||
|
{{ record.kind === 'invalid' ? '修复 JSON 内容' : 'JSON 内容' }}
|
||||||
|
</label>
|
||||||
|
<el-input
|
||||||
|
id="raw-record-draft"
|
||||||
|
:model-value="rawDraft"
|
||||||
|
type="textarea"
|
||||||
|
:rows="10"
|
||||||
|
aria-label="编辑当前条 JSON 内容"
|
||||||
|
placeholder="请输入合法 JSON"
|
||||||
|
@update:model-value="emit('update:rawDraft', $event)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<template #footer>
|
||||||
|
<div class="record-editor-actions">
|
||||||
|
<span>{{ hasDraftChanges ? '有未暂存修改' : '尚未修改' }} · Ctrl/⌘ + S 暂存</span>
|
||||||
|
<div>
|
||||||
|
<el-button :disabled="savingRecord" @click="emit('close')">取消</el-button>
|
||||||
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
:loading="savingRecord"
|
||||||
|
:disabled="!hasDraftChanges"
|
||||||
|
@click="emit('save')"
|
||||||
|
>
|
||||||
|
暂存修改
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.editor-hint {
|
||||||
|
margin-bottom: 18px;
|
||||||
|
padding: 10px 12px;
|
||||||
|
border: 1px solid #dbe2ff;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #f5f7ff;
|
||||||
|
color: #56627a;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.editor-hint i {
|
||||||
|
margin-right: 6px;
|
||||||
|
color: var(--primary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.field-helper {
|
||||||
|
margin-top: 5px;
|
||||||
|
color: #8a94a6;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.raw-record-editor label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
color: #344054;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.record-editor-actions {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.record-editor-actions > span {
|
||||||
|
color: #8a94a6;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 680px) {
|
||||||
|
.record-editor-actions {
|
||||||
|
align-items: stretch;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.record-editor-actions > div {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
335
frontend/src/views/dataset/preview/DatasetRecordTable.vue
Normal file
335
frontend/src/views/dataset/preview/DatasetRecordTable.vue
Normal file
@@ -0,0 +1,335 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, ref, watch } from 'vue'
|
||||||
|
import type { DatasetRecord } from '../datasetRecords'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
records: DatasetRecord[]
|
||||||
|
isViewingActiveVersion: boolean
|
||||||
|
versionId: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
edit: [record: DatasetRecord]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const pageSize = 10
|
||||||
|
const searchText = ref('')
|
||||||
|
const currentPage = ref(1)
|
||||||
|
|
||||||
|
const allTableFieldKeys = computed(() => {
|
||||||
|
const keys = new Set<string>()
|
||||||
|
props.records.forEach((record) => {
|
||||||
|
if (record.kind !== 'object') return
|
||||||
|
Object.keys(record.value as Record<string, unknown>).forEach((key) => keys.add(key))
|
||||||
|
})
|
||||||
|
const preferred = ['instruction', 'question', 'prompt', 'input', 'context', 'output', 'answer', 'response']
|
||||||
|
return [...keys].sort((a, b) => {
|
||||||
|
const rank = (key: string) => {
|
||||||
|
const index = preferred.indexOf(key)
|
||||||
|
return index === -1 ? preferred.length : index
|
||||||
|
}
|
||||||
|
return rank(a) - rank(b)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
const tableFieldKeys = computed(() => allTableFieldKeys.value.slice(0, 6))
|
||||||
|
const invalidRecordCount = computed(() => props.records.filter((record) => record.kind === 'invalid').length)
|
||||||
|
const hasExtraTableFields = computed(() => allTableFieldKeys.value.length > tableFieldKeys.value.length)
|
||||||
|
const filteredRecords = computed(() => {
|
||||||
|
const query = searchText.value.trim().toLowerCase()
|
||||||
|
if (!query) return props.records
|
||||||
|
return props.records.filter((record) => JSON.stringify(record.value).toLowerCase().includes(query))
|
||||||
|
})
|
||||||
|
const pagedRecords = computed(() => {
|
||||||
|
const start = (currentPage.value - 1) * pageSize
|
||||||
|
return filteredRecords.value.slice(start, start + pageSize)
|
||||||
|
})
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.versionId,
|
||||||
|
() => {
|
||||||
|
searchText.value = ''
|
||||||
|
currentPage.value = 1
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
function asDatasetRecord(row: unknown) {
|
||||||
|
return row as DatasetRecord
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatFieldValue(value: unknown) {
|
||||||
|
if (typeof value === 'string') return value || '(空)'
|
||||||
|
return JSON.stringify(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
function recordFieldValue(record: DatasetRecord, key: string) {
|
||||||
|
if (record.kind !== 'object') {
|
||||||
|
return record.kind === 'invalid' ? record.raw : formatFieldValue(record.value)
|
||||||
|
}
|
||||||
|
const data = record.value as Record<string, unknown>
|
||||||
|
return Object.prototype.hasOwnProperty.call(data, key) ? formatFieldValue(data[key]) : '-'
|
||||||
|
}
|
||||||
|
|
||||||
|
function extraFieldValue(record: DatasetRecord) {
|
||||||
|
if (record.kind !== 'object') return '-'
|
||||||
|
const data = record.value as Record<string, unknown>
|
||||||
|
return allTableFieldKeys.value
|
||||||
|
.filter((key) => !tableFieldKeys.value.includes(key) && Object.prototype.hasOwnProperty.call(data, key))
|
||||||
|
.map((key) => `${key}: ${formatFieldValue(data[key])}`)
|
||||||
|
.join(';') || '-'
|
||||||
|
}
|
||||||
|
|
||||||
|
function recordRowClassName({ row }: { row: unknown }) {
|
||||||
|
return asDatasetRecord(row).kind === 'invalid' ? 'record-table-row-invalid' : ''
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="records-viewer">
|
||||||
|
<div class="records-toolbar">
|
||||||
|
<div>
|
||||||
|
<strong>样本数据</strong>
|
||||||
|
<span>共 {{ records.length.toLocaleString() }} 条</span>
|
||||||
|
<el-tag v-if="invalidRecordCount" size="small" type="danger">
|
||||||
|
{{ invalidRecordCount }} 条格式错误
|
||||||
|
</el-tag>
|
||||||
|
</div>
|
||||||
|
<el-input
|
||||||
|
v-model="searchText"
|
||||||
|
class="record-search"
|
||||||
|
clearable
|
||||||
|
placeholder="搜索样本内容"
|
||||||
|
aria-label="搜索样本内容"
|
||||||
|
@input="currentPage = 1"
|
||||||
|
>
|
||||||
|
<template #prefix><i class="fa fa-search" /></template>
|
||||||
|
</el-input>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="!filteredRecords.length" class="viewer-state record-empty-state">
|
||||||
|
<i class="fa fa-search" aria-hidden="true" />
|
||||||
|
<span>没有找到匹配的样本</span>
|
||||||
|
</div>
|
||||||
|
<div v-else class="record-table-shell" aria-label="数据样本表格">
|
||||||
|
<el-table
|
||||||
|
:data="pagedRecords"
|
||||||
|
row-key="sourceIndex"
|
||||||
|
stripe
|
||||||
|
border
|
||||||
|
class="record-table"
|
||||||
|
:row-class-name="recordRowClassName"
|
||||||
|
>
|
||||||
|
<el-table-column label="序号" width="76" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<div class="table-index">
|
||||||
|
<strong>{{ asDatasetRecord(row).displayIndex }}</strong>
|
||||||
|
<small>第 {{ asDatasetRecord(row).sourceIndex + 1 }} 行</small>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column
|
||||||
|
v-for="fieldKey in tableFieldKeys"
|
||||||
|
:key="fieldKey"
|
||||||
|
:label="fieldKey"
|
||||||
|
min-width="220"
|
||||||
|
>
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-tooltip
|
||||||
|
:content="recordFieldValue(asDatasetRecord(row), fieldKey)"
|
||||||
|
placement="top"
|
||||||
|
:show-after="400"
|
||||||
|
>
|
||||||
|
<div class="table-cell-text">
|
||||||
|
{{ recordFieldValue(asDatasetRecord(row), fieldKey) }}
|
||||||
|
</div>
|
||||||
|
</el-tooltip>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column v-if="hasExtraTableFields" label="其他字段" min-width="240">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-tooltip
|
||||||
|
:content="extraFieldValue(asDatasetRecord(row))"
|
||||||
|
placement="top"
|
||||||
|
:show-after="400"
|
||||||
|
>
|
||||||
|
<div class="table-cell-text">{{ extraFieldValue(asDatasetRecord(row)) }}</div>
|
||||||
|
</el-tooltip>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="状态" width="96" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-tag v-if="asDatasetRecord(row).kind === 'invalid'" size="small" type="danger">
|
||||||
|
格式错误
|
||||||
|
</el-tag>
|
||||||
|
<el-tag v-else-if="asDatasetRecord(row).kind === 'primitive'" size="small" type="warning">
|
||||||
|
非对象
|
||||||
|
</el-tag>
|
||||||
|
<el-tag v-else size="small" type="success">正常</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="操作" width="96" align="center" fixed="right">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
link
|
||||||
|
:disabled="!isViewingActiveVersion"
|
||||||
|
:title="isViewingActiveVersion ? '' : '历史版本为只读,请先设为当前版本'"
|
||||||
|
:aria-label="`${asDatasetRecord(row).kind === 'invalid' ? '修复' : '编辑'}第 ${asDatasetRecord(row).displayIndex} 条数据`"
|
||||||
|
@click="emit('edit', asDatasetRecord(row))"
|
||||||
|
>
|
||||||
|
<i :class="asDatasetRecord(row).kind === 'invalid' ? 'fa fa-wrench' : 'fa fa-pencil'" />
|
||||||
|
{{ asDatasetRecord(row).kind === 'invalid' ? '修复' : '编辑' }}
|
||||||
|
</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
</div>
|
||||||
|
<div v-if="filteredRecords.length > pageSize" class="records-pagination">
|
||||||
|
<el-pagination
|
||||||
|
v-model:current-page="currentPage"
|
||||||
|
:page-size="pageSize"
|
||||||
|
:total="filteredRecords.length"
|
||||||
|
layout="prev, pager, next"
|
||||||
|
background
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.records-viewer {
|
||||||
|
min-height: 468px;
|
||||||
|
padding: 16px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.records-toolbar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 16px;
|
||||||
|
margin-bottom: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.records-toolbar > div {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.records-toolbar strong {
|
||||||
|
color: #253047;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.records-toolbar span {
|
||||||
|
color: #8a94a6;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.record-search {
|
||||||
|
width: 240px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.record-table-shell {
|
||||||
|
overflow: hidden;
|
||||||
|
border: 1px solid #e4e9f1;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.record-table {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.record-table :deep(.el-table__header th) {
|
||||||
|
height: 44px;
|
||||||
|
background: #f5f7fa;
|
||||||
|
color: #475467;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.record-table :deep(.el-table__cell) {
|
||||||
|
padding: 10px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.record-table :deep(.record-table-row-invalid td) {
|
||||||
|
background: #fff7f7 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-index {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1px;
|
||||||
|
color: #667085;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-index strong {
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-index small {
|
||||||
|
color: #98a2b3;
|
||||||
|
font-size: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-cell-text {
|
||||||
|
display: -webkit-box;
|
||||||
|
overflow: hidden;
|
||||||
|
color: #526076;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.6;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
-webkit-line-clamp: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.record-table .el-button i {
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.records-pagination {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.viewer-state {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
height: 100%;
|
||||||
|
min-height: 400px;
|
||||||
|
color: #8b96a8;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.viewer-state > i {
|
||||||
|
color: #aeb7c5;
|
||||||
|
font-size: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.record-empty-state {
|
||||||
|
min-height: 320px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 680px) {
|
||||||
|
.records-toolbar {
|
||||||
|
align-items: stretch;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.record-search {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
.record-table :deep(.el-table__row) { transition: none; }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
154
frontend/src/views/dataset/preview/DatasetVersionBar.vue
Normal file
154
frontend/src/views/dataset/preview/DatasetVersionBar.vue
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { DatasetVersion } from '@/types'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
modelValue: string
|
||||||
|
versions: DatasetVersion[]
|
||||||
|
viewedVersion?: DatasetVersion
|
||||||
|
activeVersionId: string
|
||||||
|
isViewingActiveVersion: boolean
|
||||||
|
hasPendingVersionChanges: boolean
|
||||||
|
versionLoading: boolean
|
||||||
|
savingRecord: boolean
|
||||||
|
activatingVersion: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:modelValue': [value: string]
|
||||||
|
change: [versionId: string]
|
||||||
|
activate: []
|
||||||
|
}>()
|
||||||
|
|
||||||
|
function formatVersionTime(value: string) {
|
||||||
|
return new Date(value).toLocaleString('zh-CN', { hour12: false })
|
||||||
|
}
|
||||||
|
|
||||||
|
function versionOptionLabel(version: DatasetVersion) {
|
||||||
|
const status = version.id === props.activeVersionId ? '当前版本' : '历史版本'
|
||||||
|
return `V${version.version} · ${status} · ${formatVersionTime(version.create_time)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleVersionChange(versionId: string) {
|
||||||
|
emit('update:modelValue', versionId)
|
||||||
|
emit('change', versionId)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<section class="version-control-bar" aria-label="数据集版本控制">
|
||||||
|
<div class="version-selector-group">
|
||||||
|
<label for="dataset-version-select">数据版本</label>
|
||||||
|
<el-select
|
||||||
|
id="dataset-version-select"
|
||||||
|
:model-value="modelValue"
|
||||||
|
class="version-select"
|
||||||
|
:loading="versionLoading"
|
||||||
|
:disabled="versionLoading || savingRecord"
|
||||||
|
aria-label="选择要查看的数据集版本"
|
||||||
|
@change="handleVersionChange"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="version in versions"
|
||||||
|
:key="version.id"
|
||||||
|
:label="versionOptionLabel(version)"
|
||||||
|
:value="version.id"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="version-status" role="status" aria-live="polite">
|
||||||
|
<template v-if="viewedVersion">
|
||||||
|
<el-tag v-if="isViewingActiveVersion" type="success">
|
||||||
|
V{{ viewedVersion.version }} · 当前版本
|
||||||
|
</el-tag>
|
||||||
|
<el-tag v-else type="info">V{{ viewedVersion.version }} · 历史版本(只读)</el-tag>
|
||||||
|
<el-tag v-if="hasPendingVersionChanges" type="warning">有待保存修改</el-tag>
|
||||||
|
<span>
|
||||||
|
{{ viewedVersion.description || '无版本说明' }} ·
|
||||||
|
{{ formatVersionTime(viewedVersion.create_time) }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<el-button
|
||||||
|
v-if="viewedVersion && !isViewingActiveVersion"
|
||||||
|
type="primary"
|
||||||
|
:loading="activatingVersion"
|
||||||
|
@click="emit('activate')"
|
||||||
|
>
|
||||||
|
<i class="fa fa-check-circle" />
|
||||||
|
设为当前版本
|
||||||
|
</el-button>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.version-control-bar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 16px;
|
||||||
|
min-height: 64px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
padding: 10px 14px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border: 1px solid #dfe5ee;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.version-selector-group {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.version-selector-group label {
|
||||||
|
color: #344054;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.version-select {
|
||||||
|
width: 300px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.version-status {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex: 1;
|
||||||
|
gap: 10px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.version-status > span {
|
||||||
|
overflow: hidden;
|
||||||
|
color: #7c8799;
|
||||||
|
font-size: 12px;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.version-control-bar > .el-button {
|
||||||
|
min-height: 40px;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.version-control-bar > .el-button i {
|
||||||
|
margin-right: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 680px) {
|
||||||
|
.version-control-bar,
|
||||||
|
.version-selector-group,
|
||||||
|
.version-status {
|
||||||
|
align-items: stretch;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.version-select,
|
||||||
|
.version-control-bar > .el-button {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
5
frontend/src/views/dataset/preview/types.ts
Normal file
5
frontend/src/views/dataset/preview/types.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export interface EditField {
|
||||||
|
key: string
|
||||||
|
value: string
|
||||||
|
isJson: boolean
|
||||||
|
}
|
||||||
@@ -14,6 +14,14 @@ import { getModelList } from '@/api/modules/model'
|
|||||||
import { getDatasetList } from '@/api/modules/dataset'
|
import { getDatasetList } from '@/api/modules/dataset'
|
||||||
import { getSystemInfo } from '@/api/modules/system'
|
import { getSystemInfo } from '@/api/modules/system'
|
||||||
import { TEMPLATE_GROUPS, LR_SCHEDULER_OPTIONS, QUANTIZATION_BIT_OPTIONS, QUANT_METHOD_OPTIONS, GGUF_FORMAT_OPTIONS } from '@/constants'
|
import { TEMPLATE_GROUPS, LR_SCHEDULER_OPTIONS, QUANTIZATION_BIT_OPTIONS, QUANT_METHOD_OPTIONS, GGUF_FORMAT_OPTIONS } from '@/constants'
|
||||||
|
import {
|
||||||
|
DEFAULT_TRAINING_PARAMS,
|
||||||
|
buildFineTuneCommand,
|
||||||
|
buildFineTunePayload,
|
||||||
|
createDefaultFineTuneForm,
|
||||||
|
toCreateFineTunePayload,
|
||||||
|
} from './fineTuneFormModel'
|
||||||
|
import type { FineTuneFormModel } from './fineTuneFormModel'
|
||||||
import type { ModelItem, DatasetItem, GpuInfo } from '@/types'
|
import type { ModelItem, DatasetItem, GpuInfo } from '@/types'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -26,36 +34,7 @@ const gpus = ref<GpuInfo[]>([])
|
|||||||
const selectedGpus = ref<number[]>([])
|
const selectedGpus = ref<number[]>([])
|
||||||
const modelDialogVisible = ref(false)
|
const modelDialogVisible = ref(false)
|
||||||
|
|
||||||
const form = reactive({
|
const form = reactive(createDefaultFineTuneForm())
|
||||||
name: '',
|
|
||||||
description: '',
|
|
||||||
train_type: 'SFT' as 'SFT' | 'DPO' | 'CPT',
|
|
||||||
base_model: '' as string | number,
|
|
||||||
template: 'qwen',
|
|
||||||
train_method: 'lora' as 'lora' | 'full',
|
|
||||||
train_dataset_id: '' as string | number,
|
|
||||||
auto_merge: false,
|
|
||||||
// 训练参数
|
|
||||||
batch_size: 1,
|
|
||||||
learning_rate: 0.0001,
|
|
||||||
n_epochs: 1,
|
|
||||||
save_steps: 100,
|
|
||||||
lr_scheduler_type: 'cosine',
|
|
||||||
max_length: 512,
|
|
||||||
warmup_ratio: 0.05,
|
|
||||||
weight_decay: 0.01,
|
|
||||||
// LoRA 参数
|
|
||||||
lora_alpha: 16, // 修复原项目 lora_alpha 默认值不一致 bug
|
|
||||||
lora_dropout: 0.1,
|
|
||||||
lora_rank: 8,
|
|
||||||
// 量化参数
|
|
||||||
quantization_bit: 0, // 训练时量化(QLoRA):0=不量化
|
|
||||||
export_quantized: false, // 训练后是否导出量化模型
|
|
||||||
quant_method: 'bnb', // 导出量化方法
|
|
||||||
quant_bits: 4, // 导出量化位数
|
|
||||||
quant_group_size: 128, // 分组大小(GPTQ/AWQ)
|
|
||||||
export_format: 'Q4_K_M', // GGUF 导出格式
|
|
||||||
})
|
|
||||||
|
|
||||||
const rules: FormRules = {
|
const rules: FormRules = {
|
||||||
name: [
|
name: [
|
||||||
@@ -78,45 +57,8 @@ const selectedModel = computed(() => models.value.find((model) => model.id === f
|
|||||||
|
|
||||||
const modelDialogTitle = computed(() => selectedModel.value?.name || '')
|
const modelDialogTitle = computed(() => selectedModel.value?.name || '')
|
||||||
|
|
||||||
/** 训练命令实时预览 */
|
/** 训练命令与提交载荷共用同一份表单模型。 */
|
||||||
const commandPreview = computed(() => {
|
const commandPreview = computed(() => buildFineTuneCommand(form, selectedGpus.value))
|
||||||
const gpuIds = selectedGpus.value.length ? selectedGpus.value.join(',') : '0'
|
|
||||||
let cmd = `CUDA_VISIBLE_DEVICES=${gpuIds} llamafactory-cli train \\\n`
|
|
||||||
cmd += ` --stage ${form.train_type === 'DPO' ? 'dpo' : form.train_type === 'CPT' ? 'cpt' : 'sft'} \\\n`
|
|
||||||
cmd += ` --do_train \\\n`
|
|
||||||
cmd += ` --model_name_or_path <base_model_path> \\\n`
|
|
||||||
cmd += ` --dataset <dataset> \\\n`
|
|
||||||
cmd += ` --template ${form.template} \\\n`
|
|
||||||
cmd += ` --finetuning_type ${form.train_method} \\\n`
|
|
||||||
cmd += ` --output_dir ./saves/${form.name || 'output'} \\\n`
|
|
||||||
cmd += ` --per_device_train_batch_size ${form.batch_size} \\\n`
|
|
||||||
cmd += ` --learning_rate ${form.learning_rate} \\\n`
|
|
||||||
cmd += ` --num_train_epochs ${form.n_epochs} \\\n`
|
|
||||||
cmd += ` --save_steps ${form.save_steps} \\\n`
|
|
||||||
cmd += ` --lr_scheduler_type ${form.lr_scheduler_type} \\\n`
|
|
||||||
cmd += ` --cutoff_len ${form.max_length} \\\n`
|
|
||||||
cmd += ` --warmup_ratio ${form.warmup_ratio} \\\n`
|
|
||||||
cmd += ` --weight_decay ${form.weight_decay}`
|
|
||||||
if (showLoraParams.value) {
|
|
||||||
cmd += ` \\\n --lora_alpha ${form.lora_alpha}`
|
|
||||||
cmd += ` \\\n --lora_dropout ${form.lora_dropout}`
|
|
||||||
cmd += ` \\\n --lora_rank ${form.lora_rank}`
|
|
||||||
}
|
|
||||||
if (showLoraParams.value && form.quantization_bit) {
|
|
||||||
cmd += ` \\\n --quantization_bit ${form.quantization_bit}`
|
|
||||||
}
|
|
||||||
if (form.export_quantized) {
|
|
||||||
const method = form.quant_method
|
|
||||||
const bits = form.quant_bits
|
|
||||||
cmd += ` \\\n # 训练后导出量化模型:${method} ${bits}bit`
|
|
||||||
if (method === 'gguf') {
|
|
||||||
cmd += ` \\\n # export_format=${form.export_format}`
|
|
||||||
} else if (method === 'gptq' || method === 'awq') {
|
|
||||||
cmd += ` \\\n # group_size=${form.quant_group_size}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cmd
|
|
||||||
})
|
|
||||||
|
|
||||||
/** GPU 多选切换 */
|
/** GPU 多选切换 */
|
||||||
function toggleGpu(index: number) {
|
function toggleGpu(index: number) {
|
||||||
@@ -140,31 +82,26 @@ function handleModelConfirm(modelId: string | number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function resetParams() {
|
function resetParams() {
|
||||||
Object.assign(form, {
|
Object.assign(form, DEFAULT_TRAINING_PARAMS)
|
||||||
batch_size: 1,
|
|
||||||
learning_rate: 0.0001,
|
|
||||||
n_epochs: 1,
|
|
||||||
save_steps: 100,
|
|
||||||
lr_scheduler_type: 'cosine',
|
|
||||||
max_length: 512,
|
|
||||||
warmup_ratio: 0.05,
|
|
||||||
weight_decay: 0.01,
|
|
||||||
lora_alpha: 16,
|
|
||||||
lora_dropout: 0.1,
|
|
||||||
lora_rank: 8,
|
|
||||||
quantization_bit: 0,
|
|
||||||
export_quantized: false,
|
|
||||||
quant_method: 'bnb',
|
|
||||||
quant_bits: 4,
|
|
||||||
quant_group_size: 128,
|
|
||||||
export_format: 'Q4_K_M',
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const isParamsExpanded = ref(false)
|
const isParamsExpanded = ref(false)
|
||||||
|
|
||||||
|
interface ParameterDefinition {
|
||||||
|
key: keyof FineTuneFormModel
|
||||||
|
name: string
|
||||||
|
desc: string
|
||||||
|
hint: string
|
||||||
|
type: 'number' | 'select'
|
||||||
|
min?: number
|
||||||
|
max?: number
|
||||||
|
step?: number
|
||||||
|
precision?: number
|
||||||
|
options?: Array<{ label: string; value: string | number }>
|
||||||
|
}
|
||||||
|
|
||||||
const allParams = computed(() => {
|
const allParams = computed(() => {
|
||||||
const params = [
|
const params: ParameterDefinition[] = [
|
||||||
{ key: 'batch_size', name: 'batch_size', desc: '批次大小,代表模型训练过程中,模型更新一次参数所需要的数据样本数。', hint: '[1, 64], step:1', type: 'number', min: 1, max: 64, step: 1 },
|
{ key: 'batch_size', name: 'batch_size', desc: '批次大小,代表模型训练过程中,模型更新一次参数所需要的数据样本数。', hint: '[1, 64], step:1', type: 'number', min: 1, max: 64, step: 1 },
|
||||||
{ key: 'learning_rate', name: 'learning_rate', desc: '学习率,代表每次更新数据的增量参数权重比例。', hint: '[0.000001, 1]', type: 'number', min: 0.000001, max: 1, step: 0.00001, precision: 6 },
|
{ key: 'learning_rate', name: 'learning_rate', desc: '学习率,代表每次更新数据的增量参数权重比例。', hint: '[0.000001, 1]', type: 'number', min: 0.000001, max: 1, step: 0.00001, precision: 6 },
|
||||||
{ key: 'n_epochs', name: 'n_epochs', desc: '循环次数,代表模型训练过程中模型学习数据集的次数,可理解为看几遍数据,一般建议的范围是 1-3 遍即可,可依据需求进行调整', hint: '[1, 100], step:1', type: 'number', min: 1, max: 100, step: 1 },
|
{ key: 'n_epochs', name: 'n_epochs', desc: '循环次数,代表模型训练过程中模型学习数据集的次数,可理解为看几遍数据,一般建议的范围是 1-3 遍即可,可依据需求进行调整', hint: '[1, 100], step:1', type: 'number', min: 1, max: 100, step: 1 },
|
||||||
@@ -178,7 +115,7 @@ const allParams = computed(() => {
|
|||||||
params.push(
|
params.push(
|
||||||
{ key: 'lora_alpha', name: 'lora_alpha', desc: 'LoRA 缩放系数。', hint: '16/32/64/128', type: 'select', options: [{ label: '16', value: 16 }, { label: '32', value: 32 }, { label: '64', value: 64 }, { label: '128', value: 128 }] },
|
{ key: 'lora_alpha', name: 'lora_alpha', desc: 'LoRA 缩放系数。', hint: '16/32/64/128', type: 'select', options: [{ label: '16', value: 16 }, { label: '32', value: 32 }, { label: '64', value: 64 }, { label: '128', value: 128 }] },
|
||||||
{ key: 'lora_rank', name: 'lora_rank', desc: 'LoRA 秩大小,控制低秩矩阵的维度。', hint: '8/16/32/64', type: 'select', options: [{ label: '8', value: 8 }, { label: '16', value: 16 }, { label: '32', value: 32 }, { label: '64', value: 64 }] },
|
{ key: 'lora_rank', name: 'lora_rank', desc: 'LoRA 秩大小,控制低秩矩阵的维度。', hint: '8/16/32/64', type: 'select', options: [{ label: '8', value: 8 }, { label: '16', value: 16 }, { label: '32', value: 32 }, { label: '64', value: 64 }] },
|
||||||
{ key: 'lora_dropout', name: 'lora_dropout', desc: 'LoRA 层的 dropout 比例。', hint: '[0, 1]', type: 'number', min: 0, max: 1, step: 0.05, precision: 2 }
|
{ key: 'lora_dropout', name: 'lora_dropout', desc: 'LoRA 层的 dropout 比例。', hint: '[0, 1]', type: 'number', min: 0, max: 1, step: 0.05, precision: 2 },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return params
|
return params
|
||||||
@@ -188,6 +125,15 @@ const visibleParams = computed(() => {
|
|||||||
return isParamsExpanded.value ? allParams.value : allParams.value.slice(0, 3)
|
return isParamsExpanded.value ? allParams.value : allParams.value.slice(0, 3)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function parameterValue(key: keyof FineTuneFormModel) {
|
||||||
|
const value = form[key]
|
||||||
|
return typeof value === 'boolean' ? Number(value) : value
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateParameterValue(key: keyof FineTuneFormModel, value: string | number | undefined) {
|
||||||
|
if (value !== undefined) Reflect.set(form, key, value)
|
||||||
|
}
|
||||||
|
|
||||||
async function loadModels() {
|
async function loadModels() {
|
||||||
try {
|
try {
|
||||||
models.value = (await getModelList()) || []
|
models.value = (await getModelList()) || []
|
||||||
@@ -225,88 +171,32 @@ async function handleSubmit() {
|
|||||||
}
|
}
|
||||||
submitting.value = true
|
submitting.value = true
|
||||||
try {
|
try {
|
||||||
// 任务名查重
|
let check: { exists: boolean }
|
||||||
const check = await checkFineTuneName(form.name).catch(() => ({ exists: false }))
|
try {
|
||||||
if ((check as any).exists) {
|
check = await checkFineTuneName(form.name)
|
||||||
|
} catch {
|
||||||
|
ElMessage.error('任务名校验失败,请稍后重试')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (check.exists) {
|
||||||
ElMessage.error('任务名称已存在,请更换')
|
ElMessage.error('任务名称已存在,请更换')
|
||||||
submitting.value = false
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 第一步:创建任务记录
|
const payload = buildFineTunePayload(form, selectedGpus.value)
|
||||||
const taskData = {
|
const createRes = await createFineTune(toCreateFineTunePayload(payload))
|
||||||
name: form.name,
|
const taskId = createRes.id
|
||||||
description: form.description,
|
|
||||||
base_model: form.base_model,
|
|
||||||
template: form.template,
|
|
||||||
train_type: form.train_type,
|
|
||||||
train_method: form.train_method,
|
|
||||||
gpus: selectedGpus.value,
|
|
||||||
train_dataset_id: form.train_dataset_id,
|
|
||||||
auto_merge: form.train_type === 'SFT' && form.auto_merge,
|
|
||||||
output_model_name: form.name,
|
|
||||||
batch_size: form.batch_size,
|
|
||||||
learning_rate: form.learning_rate,
|
|
||||||
n_epochs: form.n_epochs,
|
|
||||||
save_steps: form.save_steps,
|
|
||||||
lr_scheduler_type: form.lr_scheduler_type,
|
|
||||||
max_length: form.max_length,
|
|
||||||
warmup_ratio: form.warmup_ratio,
|
|
||||||
weight_decay: form.weight_decay,
|
|
||||||
lora_alpha: form.lora_alpha,
|
|
||||||
lora_dropout: form.lora_dropout,
|
|
||||||
lora_rank: form.lora_rank,
|
|
||||||
quantization_bit: form.train_method === 'lora' ? form.quantization_bit : 0,
|
|
||||||
export_quantized: form.export_quantized,
|
|
||||||
quant_method: form.export_quantized ? form.quant_method : '',
|
|
||||||
quant_bits: form.export_quantized ? form.quant_bits : 0,
|
|
||||||
quant_group_size: form.export_quantized ? form.quant_group_size : 0,
|
|
||||||
export_format: form.export_quantized && form.quant_method === 'gguf' ? form.export_format : '',
|
|
||||||
status: 'pending',
|
|
||||||
progress: 0,
|
|
||||||
}
|
|
||||||
const createRes: any = await createFineTune(taskData)
|
|
||||||
const taskId = createRes?.id || createRes
|
|
||||||
|
|
||||||
// 第二步:启动训练
|
|
||||||
try {
|
try {
|
||||||
await startFineTune({
|
await startFineTune({ ...payload, task_id: taskId })
|
||||||
task_id: taskId,
|
|
||||||
name: form.name,
|
|
||||||
base_model: form.base_model,
|
|
||||||
template: form.template,
|
|
||||||
train_type: form.train_type,
|
|
||||||
train_method: form.train_method,
|
|
||||||
train_dataset_id: form.train_dataset_id,
|
|
||||||
auto_merge: form.train_type === 'SFT' && form.auto_merge,
|
|
||||||
output_model_name: form.name,
|
|
||||||
gpus: selectedGpus.value,
|
|
||||||
batch_size: form.batch_size,
|
|
||||||
learning_rate: form.learning_rate,
|
|
||||||
n_epochs: form.n_epochs,
|
|
||||||
save_steps: form.save_steps,
|
|
||||||
lr_scheduler_type: form.lr_scheduler_type,
|
|
||||||
max_length: form.max_length,
|
|
||||||
warmup_ratio: form.warmup_ratio,
|
|
||||||
weight_decay: form.weight_decay,
|
|
||||||
lora_alpha: form.lora_alpha,
|
|
||||||
lora_dropout: form.lora_dropout,
|
|
||||||
lora_rank: form.lora_rank,
|
|
||||||
quantization_bit: form.train_method === 'lora' ? form.quantization_bit : 0,
|
|
||||||
export_quantized: form.export_quantized,
|
|
||||||
quant_method: form.export_quantized ? form.quant_method : '',
|
|
||||||
quant_bits: form.export_quantized ? form.quant_bits : 0,
|
|
||||||
quant_group_size: form.export_quantized ? form.quant_group_size : 0,
|
|
||||||
export_format: form.export_quantized && form.quant_method === 'gguf' ? form.export_format : '',
|
|
||||||
})
|
|
||||||
ElMessage.success('训练任务已创建并启动')
|
ElMessage.success('训练任务已创建并启动')
|
||||||
} catch (e) {
|
} catch {
|
||||||
// 启动失败,回写状态
|
|
||||||
await updateFineTune(taskId, { status: 'failed' })
|
await updateFineTune(taskId, { status: 'failed' })
|
||||||
|
ElMessage.error('任务已创建,但训练启动失败')
|
||||||
}
|
}
|
||||||
router.push('/fine-tune')
|
router.push('/fine-tune')
|
||||||
} catch {
|
} catch {
|
||||||
// ignore
|
ElMessage.error('训练任务创建失败,请稍后重试')
|
||||||
} finally {
|
} finally {
|
||||||
submitting.value = false
|
submitting.value = false
|
||||||
}
|
}
|
||||||
@@ -427,15 +317,17 @@ onMounted(() => {
|
|||||||
<div class="param-col config">
|
<div class="param-col config">
|
||||||
<el-input-number
|
<el-input-number
|
||||||
v-if="param.type === 'number'"
|
v-if="param.type === 'number'"
|
||||||
v-model="(form as any)[param.key]"
|
:model-value="Number(parameterValue(param.key))"
|
||||||
:min="param.min" :max="param.max" :step="param.step" :precision="param.precision"
|
:min="param.min" :max="param.max" :step="param.step" :precision="param.precision"
|
||||||
controls-position="right"
|
controls-position="right"
|
||||||
style="width: 200px"
|
style="width: 200px"
|
||||||
|
@update:model-value="updateParameterValue(param.key, $event)"
|
||||||
/>
|
/>
|
||||||
<el-select
|
<el-select
|
||||||
v-else-if="param.type === 'select'"
|
v-else-if="param.type === 'select'"
|
||||||
v-model="(form as any)[param.key]"
|
:model-value="parameterValue(param.key)"
|
||||||
style="width: 200px"
|
style="width: 200px"
|
||||||
|
@update:model-value="updateParameterValue(param.key, $event)"
|
||||||
>
|
>
|
||||||
<el-option v-for="o in param.options" :key="o.value" :label="o.label" :value="o.value" />
|
<el-option v-for="o in param.options" :key="o.value" :label="o.label" :value="o.value" />
|
||||||
</el-select>
|
</el-select>
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ const filteredList = computed(() => {
|
|||||||
if (filters.value.trainType.length && !filters.value.trainType.includes(row.train_type)) {
|
if (filters.value.trainType.length && !filters.value.trainType.includes(row.train_type)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (filters.value.trainMethod.length && !filters.value.trainMethod.includes(row.train_method)) {
|
if (filters.value.trainMethod.length && (!row.train_method || !filters.value.trainMethod.includes(row.train_method))) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|||||||
146
frontend/src/views/fine-tune/fineTuneFormModel.ts
Normal file
146
frontend/src/views/fine-tune/fineTuneFormModel.ts
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
import type { FineTuneStartPayload, FineTuneTask } from '@/types'
|
||||||
|
|
||||||
|
export type FineTuneFormModel = {
|
||||||
|
name: string
|
||||||
|
description: string
|
||||||
|
train_type: 'SFT' | 'DPO' | 'CPT'
|
||||||
|
base_model: string | number
|
||||||
|
template: string
|
||||||
|
train_method: 'lora' | 'full'
|
||||||
|
train_dataset_id: string | number
|
||||||
|
auto_merge: boolean
|
||||||
|
batch_size: number
|
||||||
|
learning_rate: number
|
||||||
|
n_epochs: number
|
||||||
|
save_steps: number
|
||||||
|
lr_scheduler_type: string
|
||||||
|
max_length: number
|
||||||
|
warmup_ratio: number
|
||||||
|
weight_decay: number
|
||||||
|
lora_alpha: number
|
||||||
|
lora_dropout: number
|
||||||
|
lora_rank: number
|
||||||
|
quantization_bit: number
|
||||||
|
export_quantized: boolean
|
||||||
|
quant_method: string
|
||||||
|
quant_bits: number
|
||||||
|
quant_group_size: number
|
||||||
|
export_format: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export const DEFAULT_TRAINING_PARAMS = {
|
||||||
|
batch_size: 1,
|
||||||
|
learning_rate: 0.0001,
|
||||||
|
n_epochs: 1,
|
||||||
|
save_steps: 100,
|
||||||
|
lr_scheduler_type: 'cosine',
|
||||||
|
max_length: 512,
|
||||||
|
warmup_ratio: 0.05,
|
||||||
|
weight_decay: 0.01,
|
||||||
|
lora_alpha: 16,
|
||||||
|
lora_dropout: 0.1,
|
||||||
|
lora_rank: 8,
|
||||||
|
quantization_bit: 0,
|
||||||
|
export_quantized: false,
|
||||||
|
quant_method: 'bnb',
|
||||||
|
quant_bits: 4,
|
||||||
|
quant_group_size: 128,
|
||||||
|
export_format: 'Q4_K_M',
|
||||||
|
} as const
|
||||||
|
|
||||||
|
export function createDefaultFineTuneForm(): FineTuneFormModel {
|
||||||
|
return {
|
||||||
|
name: '',
|
||||||
|
description: '',
|
||||||
|
train_type: 'SFT',
|
||||||
|
base_model: '',
|
||||||
|
template: 'qwen',
|
||||||
|
train_method: 'lora',
|
||||||
|
train_dataset_id: '',
|
||||||
|
auto_merge: false,
|
||||||
|
...DEFAULT_TRAINING_PARAMS,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildFineTunePayload(
|
||||||
|
form: FineTuneFormModel,
|
||||||
|
gpus: number[],
|
||||||
|
): Omit<FineTuneStartPayload, 'task_id'> {
|
||||||
|
return {
|
||||||
|
name: form.name,
|
||||||
|
description: form.description,
|
||||||
|
base_model: form.base_model,
|
||||||
|
template: form.template,
|
||||||
|
train_type: form.train_type,
|
||||||
|
train_method: form.train_method,
|
||||||
|
gpus: [...gpus],
|
||||||
|
train_dataset_id: form.train_dataset_id,
|
||||||
|
auto_merge: form.train_type === 'SFT' && form.auto_merge,
|
||||||
|
output_model_name: form.name,
|
||||||
|
batch_size: form.batch_size,
|
||||||
|
learning_rate: form.learning_rate,
|
||||||
|
n_epochs: form.n_epochs,
|
||||||
|
save_steps: form.save_steps,
|
||||||
|
lr_scheduler_type: form.lr_scheduler_type,
|
||||||
|
max_length: form.max_length,
|
||||||
|
warmup_ratio: form.warmup_ratio,
|
||||||
|
weight_decay: form.weight_decay,
|
||||||
|
lora_alpha: form.lora_alpha,
|
||||||
|
lora_dropout: form.lora_dropout,
|
||||||
|
lora_rank: form.lora_rank,
|
||||||
|
quantization_bit: form.train_method === 'lora' ? form.quantization_bit : 0,
|
||||||
|
export_quantized: form.export_quantized,
|
||||||
|
quant_method: form.export_quantized ? form.quant_method : '',
|
||||||
|
quant_bits: form.export_quantized ? form.quant_bits : 0,
|
||||||
|
quant_group_size: form.export_quantized ? form.quant_group_size : 0,
|
||||||
|
export_format: form.export_quantized && form.quant_method === 'gguf' ? form.export_format : '',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildFineTuneCommand(form: FineTuneFormModel, gpus: number[]) {
|
||||||
|
const gpuIds = gpus.length ? gpus.join(',') : '0'
|
||||||
|
const stage = form.train_type === 'DPO' ? 'dpo' : form.train_type === 'CPT' ? 'cpt' : 'sft'
|
||||||
|
const lines = [
|
||||||
|
`CUDA_VISIBLE_DEVICES=${gpuIds} llamafactory-cli train`,
|
||||||
|
` --stage ${stage}`,
|
||||||
|
' --do_train',
|
||||||
|
' --model_name_or_path <base_model_path>',
|
||||||
|
' --dataset <dataset>',
|
||||||
|
` --template ${form.template}`,
|
||||||
|
` --finetuning_type ${form.train_method}`,
|
||||||
|
` --output_dir ./saves/${form.name || 'output'}`,
|
||||||
|
` --per_device_train_batch_size ${form.batch_size}`,
|
||||||
|
` --learning_rate ${form.learning_rate}`,
|
||||||
|
` --num_train_epochs ${form.n_epochs}`,
|
||||||
|
` --save_steps ${form.save_steps}`,
|
||||||
|
` --lr_scheduler_type ${form.lr_scheduler_type}`,
|
||||||
|
` --cutoff_len ${form.max_length}`,
|
||||||
|
` --warmup_ratio ${form.warmup_ratio}`,
|
||||||
|
` --weight_decay ${form.weight_decay}`,
|
||||||
|
]
|
||||||
|
|
||||||
|
if (form.train_method === 'lora') {
|
||||||
|
lines.push(
|
||||||
|
` --lora_alpha ${form.lora_alpha}`,
|
||||||
|
` --lora_dropout ${form.lora_dropout}`,
|
||||||
|
` --lora_rank ${form.lora_rank}`,
|
||||||
|
)
|
||||||
|
if (form.quantization_bit) lines.push(` --quantization_bit ${form.quantization_bit}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (form.export_quantized) {
|
||||||
|
lines.push(` # 训练后导出量化模型:${form.quant_method} ${form.quant_bits}bit`)
|
||||||
|
if (form.quant_method === 'gguf') lines.push(` # export_format=${form.export_format}`)
|
||||||
|
if (form.quant_method === 'gptq' || form.quant_method === 'awq') {
|
||||||
|
lines.push(` # group_size=${form.quant_group_size}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lines.join(' \\\n')
|
||||||
|
}
|
||||||
|
|
||||||
|
export function toCreateFineTunePayload(
|
||||||
|
payload: Omit<FineTuneStartPayload, 'task_id'>,
|
||||||
|
): Partial<FineTuneTask> {
|
||||||
|
return { ...payload, status: 'pending', progress: 0 }
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,88 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import PageCard from '@/components/PageCard.vue'
|
||||||
|
import { DATASET_TYPE_MAP, STORAGE_MAP, TRAIN_METHOD_MAP, TRAIN_TYPE_MAP } from '@/constants'
|
||||||
|
import type { DatasetItem, FineTuneTask } from '@/types'
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
task: FineTuneTask | null
|
||||||
|
dataset: DatasetItem | null
|
||||||
|
baseModelName: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
function formatDateTime(value?: string) {
|
||||||
|
if (!value) return '-'
|
||||||
|
const date = new Date(value)
|
||||||
|
if (Number.isNaN(date.getTime())) return value
|
||||||
|
return date.toLocaleString('zh-CN', { hour12: false })
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<PageCard class="task-overview" title="任务信息" subtitle="模型、数据集与运行配置">
|
||||||
|
<div class="overview-layout" aria-label="训练任务信息">
|
||||||
|
<el-descriptions class="task-descriptions task-profile" :column="2" border>
|
||||||
|
<el-descriptions-item label="任务 ID">{{ task?.id ?? '-' }}</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="创建时间">{{ formatDateTime(task?.create_time) }}</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="基座模型">{{ baseModelName }}</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="输出模型">{{ task?.output_model_name || '暂未生成' }}</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="训练方式">
|
||||||
|
{{ task?.train_type ? (TRAIN_TYPE_MAP[task.train_type] || task.train_type) : '未配置' }}
|
||||||
|
</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="训练方法">
|
||||||
|
{{ task?.train_method ? (TRAIN_METHOD_MAP[task.train_method] || task.train_method) : '未配置' }}
|
||||||
|
</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="训练数据集" class-name="dataset-profile">
|
||||||
|
{{ dataset?.name || (task?.train_dataset_id ? '正在加载' : '未配置') }}
|
||||||
|
</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="数据类型">
|
||||||
|
{{ dataset ? (DATASET_TYPE_MAP[dataset.type] || dataset.type || '未配置') : '未配置' }}
|
||||||
|
</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="数据条数">
|
||||||
|
{{ dataset?.count?.toLocaleString('zh-CN') ?? '未配置' }}{{ dataset?.count != null ? ' 条' : '' }}
|
||||||
|
</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="数据大小">{{ dataset?.size || '未配置' }}</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="训练开始时间" class-name="runtime-panel">
|
||||||
|
{{ formatDateTime(task?.create_time) }}
|
||||||
|
</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="训练时长">{{ task?.train_duration || '未配置' }}</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="存储位置">
|
||||||
|
{{ STORAGE_MAP[dataset?.storage_type || ''] || dataset?.storage_type || '未配置' }}
|
||||||
|
</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="使用 GPU">
|
||||||
|
{{ task?.gpus?.length ? task.gpus.join('、') : '未配置' }}
|
||||||
|
</el-descriptions-item>
|
||||||
|
</el-descriptions>
|
||||||
|
</div>
|
||||||
|
</PageCard>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.task-overview {
|
||||||
|
margin-bottom: 0;
|
||||||
|
border: 1px solid #e4e7ed !important;
|
||||||
|
border-radius: 8px !important;
|
||||||
|
box-shadow: none !important;
|
||||||
|
}
|
||||||
|
.overview-layout { width: 100%; }
|
||||||
|
.task-descriptions :deep(.el-descriptions__label) {
|
||||||
|
width: 132px;
|
||||||
|
color: #606266;
|
||||||
|
font-weight: 500;
|
||||||
|
background: #f7f8fa !important;
|
||||||
|
}
|
||||||
|
.task-descriptions :deep(.el-descriptions__content) {
|
||||||
|
color: #303133;
|
||||||
|
font-weight: 500;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
}
|
||||||
|
.task-descriptions :deep(.el-descriptions__cell) { padding: 12px 16px !important; }
|
||||||
|
|
||||||
|
@media (max-width: 700px) {
|
||||||
|
.task-descriptions :deep(.el-descriptions__body),
|
||||||
|
.task-descriptions :deep(.el-descriptions__table),
|
||||||
|
.task-descriptions :deep(.el-descriptions__tbody),
|
||||||
|
.task-descriptions :deep(.el-descriptions__row),
|
||||||
|
.task-descriptions :deep(.el-descriptions__cell) { display: block; width: 100%; box-sizing: border-box; }
|
||||||
|
.task-descriptions :deep(.el-descriptions__label) { width: 100%; border-bottom: 0 !important; }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
165
frontend/src/views/system/training-log/trainingLogModel.ts
Normal file
165
frontend/src/views/system/training-log/trainingLogModel.ts
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
import type { EChartsOption } from 'echarts'
|
||||||
|
import type { FineTuneTask, TrainingLogFile } from '@/types'
|
||||||
|
|
||||||
|
export interface TrainingMetricData {
|
||||||
|
loss: number[]
|
||||||
|
gradNorm: number[]
|
||||||
|
lr: number[]
|
||||||
|
epoch: number[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TrainingSummary {
|
||||||
|
epoch: string
|
||||||
|
trainLoss: string
|
||||||
|
runtime: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ParsedTrainingLog {
|
||||||
|
metrics: TrainingMetricData
|
||||||
|
summary: TrainingSummary
|
||||||
|
}
|
||||||
|
|
||||||
|
const NUMBER_SOURCE = '[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][-+]?\\d+)?'
|
||||||
|
|
||||||
|
function escapeRegExp(value: string) {
|
||||||
|
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
||||||
|
}
|
||||||
|
|
||||||
|
function extractNumber(source: string, key: string) {
|
||||||
|
const match = source.match(new RegExp(`['"]?${escapeRegExp(key)}['"]?\\s*:\\s*(${NUMBER_SOURCE})`, 'i'))
|
||||||
|
return match ? Number(match[1]) : undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
function extractSummaryValue(source: string, key: string) {
|
||||||
|
const match = source.match(new RegExp(`['"]?${escapeRegExp(key)}['"]?\\s*(?:=|:)\\s*(${NUMBER_SOURCE})`, 'i'))
|
||||||
|
return match?.[1] || ''
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 根据任务精确选择日志;PID 优先,任务名仅作为明确兜底。 */
|
||||||
|
export function resolveTrainingLogFile(
|
||||||
|
files: TrainingLogFile[],
|
||||||
|
task: Pick<FineTuneTask, 'process_id' | 'name'>,
|
||||||
|
) {
|
||||||
|
const processId = task.process_id
|
||||||
|
if (processId != null) {
|
||||||
|
const pidMatch = files.find((file) => file.pid === processId)
|
||||||
|
if (pidMatch) return pidMatch
|
||||||
|
|
||||||
|
const pidPattern = new RegExp(`(?:^|[^0-9])(?:pid)?${processId}(?:[^0-9]|$)`, 'i')
|
||||||
|
const filenameMatch = files.find((file) => pidPattern.test(file.file))
|
||||||
|
if (filenameMatch) return filenameMatch
|
||||||
|
}
|
||||||
|
|
||||||
|
const taskName = task.name.trim()
|
||||||
|
if (!taskName) return undefined
|
||||||
|
return files.find((file) => file.name.includes(taskName) || file.file.includes(taskName))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 解析日志中的逐步指标。字段顺序和常见数值格式均不受限制。 */
|
||||||
|
export function parseTrainingMetrics(text: string): TrainingMetricData {
|
||||||
|
const metrics: TrainingMetricData = { loss: [], gradNorm: [], lr: [], epoch: [] }
|
||||||
|
const blocks = text.match(/\{[^{}\r\n]*\}/g) || []
|
||||||
|
|
||||||
|
for (const block of blocks) {
|
||||||
|
const loss = extractNumber(block, 'loss')
|
||||||
|
const gradNorm = extractNumber(block, 'grad_norm')
|
||||||
|
const learningRate = extractNumber(block, 'learning_rate')
|
||||||
|
const epoch = extractNumber(block, 'epoch')
|
||||||
|
if (loss == null || gradNorm == null || learningRate == null) continue
|
||||||
|
metrics.loss.push(loss)
|
||||||
|
metrics.gradNorm.push(gradNorm)
|
||||||
|
metrics.lr.push(learningRate)
|
||||||
|
if (epoch != null) metrics.epoch.push(epoch)
|
||||||
|
}
|
||||||
|
|
||||||
|
return metrics
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 每次都返回新对象,日志截断或切换时不会残留上一轮汇总。 */
|
||||||
|
export function parseTrainingSummary(text: string): TrainingSummary {
|
||||||
|
const emptySummary: TrainingSummary = { epoch: '', trainLoss: '', runtime: '' }
|
||||||
|
const startMatch = /\*{5}\s*train metrics\s*\*{5}/i.exec(text)
|
||||||
|
if (!startMatch) return emptySummary
|
||||||
|
|
||||||
|
const tail = text.slice(startMatch.index + startMatch[0].length)
|
||||||
|
const endMatch = /\*{5}\s*train metrics end\s*\*{5}/i.exec(tail)
|
||||||
|
const body = endMatch ? tail.slice(0, endMatch.index) : tail
|
||||||
|
return {
|
||||||
|
epoch: extractSummaryValue(body, 'epoch'),
|
||||||
|
trainLoss: extractSummaryValue(body, 'train_loss'),
|
||||||
|
runtime: extractSummaryValue(body, 'train_runtime'),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseTrainingLog(text: string): ParsedTrainingLog {
|
||||||
|
return {
|
||||||
|
metrics: parseTrainingMetrics(text),
|
||||||
|
summary: parseTrainingSummary(text),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 构建单条训练指标曲线。 */
|
||||||
|
export function buildMetricChartOption(
|
||||||
|
label: string,
|
||||||
|
data: number[],
|
||||||
|
color: string,
|
||||||
|
logScale = false,
|
||||||
|
): EChartsOption {
|
||||||
|
return {
|
||||||
|
grid: { top: 24, right: 20, bottom: 56, left: 56 },
|
||||||
|
tooltip: {
|
||||||
|
trigger: 'axis',
|
||||||
|
axisPointer: { type: 'cross' },
|
||||||
|
backgroundColor: 'rgba(15, 23, 42, 0.9)',
|
||||||
|
borderWidth: 0,
|
||||||
|
textStyle: { color: '#fff', fontSize: 12 },
|
||||||
|
},
|
||||||
|
xAxis: {
|
||||||
|
type: 'category',
|
||||||
|
boundaryGap: false,
|
||||||
|
name: 'Step',
|
||||||
|
nameTextStyle: { color: '#94a3b8', fontSize: 11 },
|
||||||
|
axisLine: { lineStyle: { color: '#e2e8f0' } },
|
||||||
|
axisLabel: { color: '#94a3b8', fontSize: 11 },
|
||||||
|
splitLine: { show: false },
|
||||||
|
},
|
||||||
|
yAxis: {
|
||||||
|
type: logScale ? 'log' : 'value',
|
||||||
|
name: label,
|
||||||
|
nameTextStyle: { color: '#94a3b8', fontSize: 11 },
|
||||||
|
axisLine: { show: false },
|
||||||
|
axisTick: { show: false },
|
||||||
|
axisLabel: { color: '#94a3b8', fontSize: 11 },
|
||||||
|
splitLine: { lineStyle: { color: '#f1f5f9' } },
|
||||||
|
},
|
||||||
|
dataZoom: data.length > 30
|
||||||
|
? [
|
||||||
|
{ type: 'inside', start: 0, end: 100 },
|
||||||
|
{ type: 'slider', height: 16, bottom: 8, borderColor: 'transparent', fillerColor: 'rgba(79,70,229,0.08)', handleStyle: { color: '#4f46e5' } },
|
||||||
|
]
|
||||||
|
: [],
|
||||||
|
series: [
|
||||||
|
{
|
||||||
|
name: label,
|
||||||
|
type: 'line',
|
||||||
|
data,
|
||||||
|
smooth: true,
|
||||||
|
symbol: 'none',
|
||||||
|
lineStyle: { width: 2, color },
|
||||||
|
areaStyle: {
|
||||||
|
color: {
|
||||||
|
type: 'linear',
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
x2: 0,
|
||||||
|
y2: 1,
|
||||||
|
colorStops: [
|
||||||
|
{ offset: 0, color: `${color}55` },
|
||||||
|
{ offset: 1, color: `${color}05` },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user