From ddce6638ad27f5507a0abd0b129b851a677bd343 Mon Sep 17 00:00:00 2001 From: "guangfei.zhao" Date: Fri, 7 Nov 2025 10:10:40 +0800 Subject: [PATCH] feat(knowledge): add build mode support for configuration components add build mode parameter to all configuration components to toggle between built-in and pipeline modes export new common items and update chunk method form to handle build mode selection --- .../knowledge/components/ChunkMethodForm.tsx | 52 +++++++++++++-- src/pages/knowledge/configuration/audio.tsx | 40 ++++++------ src/pages/knowledge/configuration/book.tsx | 38 +++++------ src/pages/knowledge/configuration/email.tsx | 26 ++++---- src/pages/knowledge/configuration/index.tsx | 2 +- .../configuration/knowledge-graph.tsx | 44 ++++++------- src/pages/knowledge/configuration/laws.tsx | 26 ++++---- src/pages/knowledge/configuration/manual.tsx | 44 ++++++------- src/pages/knowledge/configuration/naive.tsx | 63 +++++-------------- src/pages/knowledge/configuration/one.tsx | 44 ++++++------- src/pages/knowledge/configuration/paper.tsx | 44 ++++++------- src/pages/knowledge/configuration/picture.tsx | 26 ++++---- .../knowledge/configuration/presentation.tsx | 44 ++++++------- src/pages/knowledge/configuration/qa.tsx | 26 ++++---- src/pages/knowledge/configuration/resume.tsx | 26 ++++---- src/pages/knowledge/configuration/table.tsx | 26 ++++---- src/pages/knowledge/configuration/tag.tsx | 28 +++++---- 17 files changed, 318 insertions(+), 281 deletions(-) diff --git a/src/pages/knowledge/components/ChunkMethodForm.tsx b/src/pages/knowledge/components/ChunkMethodForm.tsx index d7df034..5528cf8 100644 --- a/src/pages/knowledge/components/ChunkMethodForm.tsx +++ b/src/pages/knowledge/components/ChunkMethodForm.tsx @@ -1,10 +1,12 @@ -import React, { useMemo } from 'react'; +import React, { useMemo, useState, useEffect } from 'react'; import { useFormContext, useWatch, type UseFormReturn } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; import { Box, Typography, Button, + Card, + CardContent, } from '@mui/material'; import { DOCUMENT_PARSER_TYPES, type DocumentParserType } from '@/constants/knowledge'; import { type IParserConfig } from '@/interfaces/database/knowledge'; @@ -20,7 +22,12 @@ import { PresentationConfiguration, OneConfiguration, TagConfiguration, + ConfigurationFormContainer, + MainContainer, } from '../configuration'; +import { ChunkMethodItem } from '../configuration'; +import { PipelineSelectorItem } from '../configuration/common-items'; +import { RadioFormField } from '@/components/FormField'; // 配置组件映射表 const ConfigurationComponentMap = { @@ -86,9 +93,9 @@ function ChunkMethodForm({ } catch (error) { contextForm = null; } - + const form = propForm || contextForm; - + if (!form) { console.error('ChunkMethodForm: No form context found. Component must be used within a FormProvider or receive a form prop.'); return ( @@ -108,6 +115,16 @@ function ChunkMethodForm({ name: 'parser_id', }); + // 监听 pipeline_id,自动决定构建模式 + const pipeline_id = useWatch({ + control, + name: 'pipeline_id', + }); + const [buildMode, setBuildMode] = useState<'buildIn' | 'pipeline'>(pipeline_id ? 'pipeline' : 'buildIn'); + useEffect(() => { + setBuildMode(pipeline_id ? 'pipeline' : 'buildIn'); + }, [pipeline_id]); + // 根据parser_id动态选择配置组件 const ConfigurationComponent = useMemo(() => { const parser = parser_id as DocumentParserType; @@ -117,9 +134,32 @@ function ChunkMethodForm({ return ( - {/* 动态配置内容 */} - - + {/* 构建模式选择与联动 */} + + + setBuildMode(String(v) as 'buildIn' | 'pipeline')} + /> + + {/* 基于模式:内置显示切片方法,Pipeline 显示选择器 */} + {buildMode === 'buildIn' ? ( + + ) : ( + + )} + + + + {/* 动态配置内容:始终渲染,内部按 buildMode 控制基础配置显示 */} + + {/* 表单操作按钮 - 仅在有onSubmit回调时显示 */} {onSubmit && ( diff --git a/src/pages/knowledge/configuration/audio.tsx b/src/pages/knowledge/configuration/audio.tsx index 23c171b..8a991b4 100644 --- a/src/pages/knowledge/configuration/audio.tsx +++ b/src/pages/knowledge/configuration/audio.tsx @@ -19,7 +19,7 @@ import { KnowledgeGraphConfigItems, } from './common-items'; -export function AudioConfiguration() { +export function AudioConfiguration({ buildMode = 'buildIn' }: { buildMode?: 'buildIn' | 'pipeline' }) { const { formState: { errors } } = useFormContext(); const { t } = useTranslation(); @@ -27,25 +27,27 @@ export function AudioConfiguration() { {/* 第一部分:basicConfig 基础配置 */} - - }> - {t('knowledge.config.basicConfig')} - - - {/* 切片方法 */} - - - - + {buildMode === 'buildIn' && ( + + }> + {t('knowledge.config.basicConfig')} + + + {/* 切片方法 */} + + + + - - {/* 自动关键词提取 */} - - {/* 自动问题提取 */} - - - - + + {/* 自动关键词提取 */} + + {/* 自动问题提取 */} + + + + + )} {/* 第二部分:RAPTOR策略 */} diff --git a/src/pages/knowledge/configuration/book.tsx b/src/pages/knowledge/configuration/book.tsx index 8c8dbb4..31c10d3 100644 --- a/src/pages/knowledge/configuration/book.tsx +++ b/src/pages/knowledge/configuration/book.tsx @@ -12,30 +12,32 @@ import { KnowledgeGraphConfigItems } from './common-items'; -export function BookConfiguration() { +export function BookConfiguration({ buildMode = 'buildIn' }: { buildMode?: 'buildIn' | 'pipeline' }) { const { t } = useTranslation(); return ( {/* 第一部分:基础配置 */} - - }> - {t('knowledge.config.basicConfig')} - - - - {/* 分块方法 */} - - {/* 分块token数 */} - - {/* 分隔符 */} - - {/* 目录增强 */} - - - - + {buildMode === 'buildIn' && ( + + }> + {t('knowledge.config.basicConfig')} + + + + {/* 分块方法 */} + + {/* 分块token数 */} + + {/* 分隔符 */} + + {/* 目录增强 */} + + + + + )} {/* 第二部分:RAPTOR策略 */} diff --git a/src/pages/knowledge/configuration/email.tsx b/src/pages/knowledge/configuration/email.tsx index dfff693..cb0d3a4 100644 --- a/src/pages/knowledge/configuration/email.tsx +++ b/src/pages/knowledge/configuration/email.tsx @@ -9,24 +9,26 @@ import { KnowledgeGraphConfigItems } from './common-items'; -export function EmailConfiguration() { +export function EmailConfiguration({ buildMode = 'buildIn' }: { buildMode?: 'buildIn' | 'pipeline' }) { const { t } = useTranslation(); return ( {/* 第一部分:基础配置 */} - - }> - {t('knowledge.config.basicConfig')} - - - - {/* 分块方法 */} - - - - + {buildMode === 'buildIn' && ( + + }> + {t('knowledge.config.basicConfig')} + + + + {/* 分块方法 */} + + + + + )} {/* 第二部分:RAPTOR策略 */} diff --git a/src/pages/knowledge/configuration/index.tsx b/src/pages/knowledge/configuration/index.tsx index bdf8dc3..a72756f 100644 --- a/src/pages/knowledge/configuration/index.tsx +++ b/src/pages/knowledge/configuration/index.tsx @@ -1,5 +1,5 @@ // 配置组件统一导出 -export { ChunkMethodItem, EmbeddingModelItem } from './common-items'; +export { ChunkMethodItem, EmbeddingModelItem, PipelineSelectorItem, BasicConfigItems } from './common-items'; export { ConfigurationFormContainer, MainContainer } from './configuration-form-container'; // 所有解析器配置组件 diff --git a/src/pages/knowledge/configuration/knowledge-graph.tsx b/src/pages/knowledge/configuration/knowledge-graph.tsx index 97ed245..c61a650 100644 --- a/src/pages/knowledge/configuration/knowledge-graph.tsx +++ b/src/pages/knowledge/configuration/knowledge-graph.tsx @@ -29,7 +29,7 @@ import { CommunityReportItem, } from './common-items'; -export function KnowledgeGraphConfiguration() { +export function KnowledgeGraphConfiguration({ buildMode = 'buildIn' }: { buildMode?: 'buildIn' | 'pipeline' }) { const { formState: { errors } } = useFormContext(); const { t } = useTranslation(); @@ -37,27 +37,29 @@ export function KnowledgeGraphConfiguration() { {/* 第一部分:basicConfig 基础配置 */} - - }> - {t('knowledge.config.basicConfig')} - - - {/* 切片方法 */} - - - - + {buildMode === 'buildIn' && ( + + }> + {t('knowledge.config.basicConfig')} + + + {/* 切片方法 */} + + + + - - {/* 嵌入模型 */} - - {/* 自动关键词提取 */} - - {/* 自动问题提取 */} - - - - + + {/* 嵌入模型 */} + + {/* 自动关键词提取 */} + + {/* 自动问题提取 */} + + + + + )} {/* 第二部分:RAPTOR策略 */} diff --git a/src/pages/knowledge/configuration/laws.tsx b/src/pages/knowledge/configuration/laws.tsx index 0857158..f59cac8 100644 --- a/src/pages/knowledge/configuration/laws.tsx +++ b/src/pages/knowledge/configuration/laws.tsx @@ -9,24 +9,26 @@ import { KnowledgeGraphConfigItems } from './common-items'; -export function LawsConfiguration() { +export function LawsConfiguration({ buildMode = 'buildIn' }: { buildMode?: 'buildIn' | 'pipeline' }) { const { t } = useTranslation(); return ( {/* 第一部分:基础配置 */} - - }> - {t('knowledge.config.basicConfig')} - - - - {/* 分块方法 */} - - - - + {buildMode === 'buildIn' && ( + + }> + {t('knowledge.config.basicConfig')} + + + + {/* 分块方法 */} + + + + + )} {/* 第二部分:RAPTOR策略 */} diff --git a/src/pages/knowledge/configuration/manual.tsx b/src/pages/knowledge/configuration/manual.tsx index e04a160..54bde25 100644 --- a/src/pages/knowledge/configuration/manual.tsx +++ b/src/pages/knowledge/configuration/manual.tsx @@ -34,7 +34,7 @@ import { KnowledgeGraphConfigItems, } from './common-items'; -export function ManualConfiguration() { +export function ManualConfiguration({ buildMode = 'buildIn' }: { buildMode?: 'buildIn' | 'pipeline' }) { const { formState: { errors } } = useFormContext(); const { t } = useTranslation(); @@ -42,27 +42,29 @@ export function ManualConfiguration() { {/* 第一部分:basicConfig 基础配置 */} - - }> - {t('knowledge.config.basicConfig')} - - - {/* 切片方法 */} - - - - + {buildMode === 'buildIn' && ( + + }> + {t('knowledge.config.basicConfig')} + + + {/* 切片方法 */} + + + + - - {/* 版面识别 */} - - {/* 自动关键词提取 */} - - {/* 自动问题提取 */} - - - - + + {/* 版面识别 */} + + {/* 自动关键词提取 */} + + {/* 自动问题提取 */} + + + + + )} {/* 第二部分:RAPTOR策略 */} diff --git a/src/pages/knowledge/configuration/naive.tsx b/src/pages/knowledge/configuration/naive.tsx index acf33b6..bbb0b92 100644 --- a/src/pages/knowledge/configuration/naive.tsx +++ b/src/pages/knowledge/configuration/naive.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React from 'react'; import { Box, Typography, @@ -11,60 +11,29 @@ import { ExpandMore as ExpandMoreIcon } from '@mui/icons-material'; import { useFormContext } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; import { ConfigurationFormContainer, MainContainer } from './configuration-form-container'; -import { - ChunkMethodItem, - RaptorConfigItems, - KnowledgeGraphConfigItems, - PipelineSelectorItem, - BasicConfigItems, -} from './common-items'; -import { RadioFormField } from '@/components/FormField'; +import { RaptorConfigItems, KnowledgeGraphConfigItems, BasicConfigItems } from './common-items'; +// import { RadioFormField } from '@/components/FormField'; -export function NaiveConfiguration() { - const { formState: { errors }, watch } = useFormContext(); +export function NaiveConfiguration({ buildMode = 'buildIn' }: { buildMode?: 'buildIn' | 'pipeline' }) { + const { formState: { errors } } = useFormContext(); const { t } = useTranslation(); - const [buildMode, setBuildMode] = useState<'buildIn' | 'pipeline'>('buildIn'); - - // 根据表单的 pipeline_id 自动切换 buildMode - const pipelineId = watch('pipeline_id'); - useEffect(() => { - setBuildMode(pipelineId ? 'pipeline' : 'buildIn'); - }, [pipelineId]); return ( {/* 第一部分:basicConfig 基础配置 */} - - }> - {t('knowledge.config.basicConfig')} - - - {/* 切片方法 */} - - setBuildMode(String(v) as 'buildIn' | 'pipeline')} - /> - {buildMode === 'buildIn' ? ( - - ) : ( - - )} - - - - {buildMode === 'buildIn' && ( + {buildMode === 'buildIn' && ( + + }> + {t('knowledge.config.basicConfig')} + + + - )} - - - + + + + )} {/* 第二部分:RAPTOR策略 */} diff --git a/src/pages/knowledge/configuration/one.tsx b/src/pages/knowledge/configuration/one.tsx index b7392e7..be2f0e3 100644 --- a/src/pages/knowledge/configuration/one.tsx +++ b/src/pages/knowledge/configuration/one.tsx @@ -23,7 +23,7 @@ import { KnowledgeGraphConfigItems, } from './common-items'; -export function OneConfiguration() { +export function OneConfiguration({ buildMode = 'buildIn' }: { buildMode?: 'buildIn' | 'pipeline' }) { const { formState: { errors } } = useFormContext(); const { t } = useTranslation(); @@ -31,27 +31,29 @@ export function OneConfiguration() { {/* 第一部分:basicConfig 基础配置 */} - - }> - {t('knowledge.config.basicConfig')} - - - {/* 切片方法 */} - - - - + {buildMode === 'buildIn' && ( + + }> + {t('knowledge.config.basicConfig')} + + + {/* 切片方法 */} + + + + - - {/* 版面识别 */} - - {/* 自动关键词提取 */} - - {/* 自动问题提取 */} - - - - + + {/* 版面识别 */} + + {/* 自动关键词提取 */} + + {/* 自动问题提取 */} + + + + + )} {/* 第二部分:RAPTOR策略 */} diff --git a/src/pages/knowledge/configuration/paper.tsx b/src/pages/knowledge/configuration/paper.tsx index db8cf5a..967a1ca 100644 --- a/src/pages/knowledge/configuration/paper.tsx +++ b/src/pages/knowledge/configuration/paper.tsx @@ -20,7 +20,7 @@ import { KnowledgeGraphConfigItems, } from './common-items'; -export function PaperConfiguration() { +export function PaperConfiguration({ buildMode = 'buildIn' }: { buildMode?: 'buildIn' | 'pipeline' }) { const { formState: { errors } } = useFormContext(); const { t } = useTranslation(); @@ -28,27 +28,29 @@ export function PaperConfiguration() { {/* 第一部分:basicConfig 基础配置 */} - - }> - {t('knowledge.config.basicConfig')} - - - {/* 切片方法 */} - - - - + {buildMode === 'buildIn' && ( + + }> + {t('knowledge.config.basicConfig')} + + + {/* 切片方法 */} + + + + - - {/* 版面识别 */} - - {/* 自动关键词提取 */} - - {/* 自动问题提取 */} - - - - + + {/* 版面识别 */} + + {/* 自动关键词提取 */} + + {/* 自动问题提取 */} + + + + + )} {/* 第二部分:RAPTOR策略 */} diff --git a/src/pages/knowledge/configuration/picture.tsx b/src/pages/knowledge/configuration/picture.tsx index cd0452f..f6112ea 100644 --- a/src/pages/knowledge/configuration/picture.tsx +++ b/src/pages/knowledge/configuration/picture.tsx @@ -9,24 +9,26 @@ import { KnowledgeGraphConfigItems } from './common-items'; -export function PictureConfiguration() { +export function PictureConfiguration({ buildMode = 'buildIn' }: { buildMode?: 'buildIn' | 'pipeline' }) { const { t } = useTranslation(); return ( {/* 第一部分:基础配置 */} - - }> - {t('knowledge.config.basicConfig')} - - - - {/* 分块方法 */} - - - - + {buildMode === 'buildIn' && ( + + }> + {t('knowledge.config.basicConfig')} + + + + {/* 分块方法 */} + + + + + )} {/* 第二部分:RAPTOR策略 */} diff --git a/src/pages/knowledge/configuration/presentation.tsx b/src/pages/knowledge/configuration/presentation.tsx index 3fb7ef6..4d0eeda 100644 --- a/src/pages/knowledge/configuration/presentation.tsx +++ b/src/pages/knowledge/configuration/presentation.tsx @@ -12,34 +12,36 @@ import { AutoQuestionsItem } from './common-items'; -export function PresentationConfiguration() { +export function PresentationConfiguration({ buildMode = 'buildIn' }: { buildMode?: 'buildIn' | 'pipeline' }) { const { t } = useTranslation(); return ( {/* 第一部分:基础配置 */} - - }> - {t('knowledge.config.basicConfig')} - - - {/* 切片方法 */} - - - - + {buildMode === 'buildIn' && ( + + }> + {t('knowledge.config.basicConfig')} + + + {/* 切片方法 */} + + + + - - {/* 版面识别 */} - - {/* 自动关键词提取 */} - - {/* 自动问题提取 */} - - - - + + {/* 版面识别 */} + + {/* 自动关键词提取 */} + + {/* 自动问题提取 */} + + + + + )} {/* 第二部分:RAPTOR策略 */} diff --git a/src/pages/knowledge/configuration/qa.tsx b/src/pages/knowledge/configuration/qa.tsx index cacb264..98a7c94 100644 --- a/src/pages/knowledge/configuration/qa.tsx +++ b/src/pages/knowledge/configuration/qa.tsx @@ -9,24 +9,26 @@ import { KnowledgeGraphConfigItems } from './common-items'; -export function QAConfiguration() { +export function QAConfiguration({ buildMode = 'buildIn' }: { buildMode?: 'buildIn' | 'pipeline' }) { const { t } = useTranslation(); return ( {/* 第一部分:基础配置 */} - - }> - {t('knowledge.config.basicConfig')} - - - - {/* 分块方法 */} - - - - + {buildMode === 'buildIn' && ( + + }> + {t('knowledge.config.basicConfig')} + + + + {/* 分块方法 */} + + + + + )} {/* 第二部分:RAPTOR策略 */} diff --git a/src/pages/knowledge/configuration/resume.tsx b/src/pages/knowledge/configuration/resume.tsx index d882849..463ba5c 100644 --- a/src/pages/knowledge/configuration/resume.tsx +++ b/src/pages/knowledge/configuration/resume.tsx @@ -9,24 +9,26 @@ import { KnowledgeGraphConfigItems } from './common-items'; -export function ResumeConfiguration() { +export function ResumeConfiguration({ buildMode = 'buildIn' }: { buildMode?: 'buildIn' | 'pipeline' }) { const { t } = useTranslation(); return ( {/* 第一部分:基础配置 */} - - }> - {t('knowledge.config.basicConfig')} - - - - {/* 分块方法 */} - - - - + {buildMode === 'buildIn' && ( + + }> + {t('knowledge.config.basicConfig')} + + + + {/* 分块方法 */} + + + + + )} {/* 第二部分:RAPTOR策略 */} diff --git a/src/pages/knowledge/configuration/table.tsx b/src/pages/knowledge/configuration/table.tsx index e5e8ccb..cdb03b2 100644 --- a/src/pages/knowledge/configuration/table.tsx +++ b/src/pages/knowledge/configuration/table.tsx @@ -9,24 +9,26 @@ import { KnowledgeGraphConfigItems } from './common-items'; -export function TableConfiguration() { +export function TableConfiguration({ buildMode = 'buildIn' }: { buildMode?: 'buildIn' | 'pipeline' }) { const { t } = useTranslation(); return ( {/* 第一部分:基础配置 */} - - }> - {t('knowledge.config.basicConfig')} - - - - {/* 分块方法 */} - - - - + {buildMode === 'buildIn' && ( + + }> + {t('knowledge.config.basicConfig')} + + + + {/* 分块方法 */} + + + + + )} {/* 第二部分:RAPTOR策略 */} diff --git a/src/pages/knowledge/configuration/tag.tsx b/src/pages/knowledge/configuration/tag.tsx index 93716ea..06fc8bc 100644 --- a/src/pages/knowledge/configuration/tag.tsx +++ b/src/pages/knowledge/configuration/tag.tsx @@ -12,25 +12,27 @@ import { AutoQuestionsItem } from './common-items'; -export function TagConfiguration() { +export function TagConfiguration({ buildMode = 'buildIn' }: { buildMode?: 'buildIn' | 'pipeline' }) { const { t } = useTranslation(); return ( {/* 第一部分:基础配置 */} - - }> - {t('knowledge.config.basicConfig')} - - - {/* 切片方法 */} - - - - - - + {buildMode === 'buildIn' && ( + + }> + {t('knowledge.config.basicConfig')} + + + {/* 切片方法 */} + + + + + + + )} {/* 第二部分:RAPTOR策略 */}