From 4cea0248c81f0f6587fa16dfafad47c85549cd28 Mon Sep 17 00:00:00 2001 From: AkaraChen Date: Tue, 26 Nov 2024 16:05:58 +0800 Subject: [PATCH] chore: upd --- .../datasets/create/step-two/index.tsx | 54 ++++++++----------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/web/app/components/datasets/create/step-two/index.tsx b/web/app/components/datasets/create/step-two/index.tsx index 0f929888c8..df52370e40 100644 --- a/web/app/components/datasets/create/step-two/index.tsx +++ b/web/app/components/datasets/create/step-two/index.tsx @@ -97,7 +97,8 @@ type StepTwoProps = { enum SegmentType { AUTO = 'automatic', - CUSTOM = 'custom', + GENERAL = 'general', + PARENT_CHILD = 'parent_child', } enum IndexingType { QUALIFIED = 'high_quality', @@ -165,7 +166,7 @@ const StepTwo = ({ const [scrolled, setScrolled] = useState(false) const previewScrollRef = useRef(null) const [previewScrolled, setPreviewScrolled] = useState(false) - const [segmentationType, setSegmentationType] = useState(SegmentType.AUTO) + const [segmentationType, setSegmentationType] = useState(SegmentType.GENERAL) const [segmentIdentifier, doSetSegmentIdentifier] = useState(DEFAULT_SEGMENT_IDENTIFIER) const setSegmentIdentifier = useCallback((value: string) => { doSetSegmentIdentifier(value ? escape(value) : DEFAULT_SEGMENT_IDENTIFIER) @@ -191,11 +192,12 @@ const StepTwo = ({ const [QATipHide, setQATipHide] = useState(false) const [previewSwitched, setPreviewSwitched] = useState(false) const [showPreview, { setTrue: setShowPreview, setFalse: hidePreview }] = useBoolean() - const [customFileIndexingEstimate, setCustomFileIndexingEstimate] = useState(null) + const [generalFileIndexingEstimate, setGeneralFileIndexingEstimate] = useState(null) const [automaticFileIndexingEstimate, setAutomaticFileIndexingEstimate] = useState(null) + // TODO: refactor this const fileIndexingEstimate = (() => { - return segmentationType === SegmentType.AUTO ? automaticFileIndexingEstimate : customFileIndexingEstimate + return segmentationType === SegmentType.AUTO ? automaticFileIndexingEstimate : generalFileIndexingEstimate })() const [isCreating, setIsCreating] = useState(false) @@ -247,7 +249,7 @@ const StepTwo = ({ if (defaultConfig) { setSegmentIdentifier(defaultConfig.segmentation.separator) setMax(defaultConfig.segmentation.max_tokens) - setOverlap(defaultConfig.segmentation.chunk_overlap) + setOverlap(defaultConfig.segmentation.chunk_overlap!) setRules(defaultConfig.pre_processing_rules) } setParentChildConfig(defaultParentChildConfig) @@ -256,18 +258,18 @@ const StepTwo = ({ const fetchFileIndexingEstimate = async (docForm = DocForm.TEXT, language?: string) => { // eslint-disable-next-line @typescript-eslint/no-use-before-define const res = await didFetchFileIndexingEstimate(getFileIndexingEstimateParams(docForm, language)!) - if (segmentationType === SegmentType.CUSTOM) - setCustomFileIndexingEstimate(res) + if (segmentationType === SegmentType.GENERAL) + setGeneralFileIndexingEstimate(res) else setAutomaticFileIndexingEstimate(res) } const confirmChangeCustomConfig = () => { - if (segmentationType === SegmentType.CUSTOM && max > 4000) { + if (segmentationType === SegmentType.GENERAL && max > 4000) { Toast.notify({ type: 'error', message: t('datasetCreation.stepTwo.maxLengthCheck') }) return } - setCustomFileIndexingEstimate(null) + setGeneralFileIndexingEstimate(null) setShowPreview() fetchFileIndexingEstimate() setPreviewSwitched(false) @@ -280,7 +282,7 @@ const StepTwo = ({ rules: {} as any, // api will check this. It will be removed after api refactored. mode: segmentationType, } - if (segmentationType === SegmentType.CUSTOM) { + if (segmentationType === SegmentType.GENERAL) { const ruleObj = { pre_processing_rules: rules, segmentation: { @@ -390,11 +392,11 @@ const StepTwo = ({ ) const getCreationParams = () => { let params - if (segmentationType === SegmentType.CUSTOM && overlap > max) { + if (segmentationType === SegmentType.GENERAL && overlap > max) { Toast.notify({ type: 'error', message: t('datasetCreation.stepTwo.overlapCheck') }) return } - if (segmentationType === SegmentType.CUSTOM && max > 4000) { + if (segmentationType === SegmentType.GENERAL && max > 4000) { Toast.notify({ type: 'error', message: t('datasetCreation.stepTwo.maxLengthCheck') }) return } @@ -549,10 +551,8 @@ const StepTwo = ({ const previewSwitch = async (language?: string) => { setPreviewSwitched(true) setIsLanguageSelectDisabled(true) - if (segmentationType === SegmentType.AUTO) - setAutomaticFileIndexingEstimate(null) - else - setCustomFileIndexingEstimate(null) + if (segmentationType === SegmentType.GENERAL) + setGeneralFileIndexingEstimate(null) try { await fetchFileIndexingEstimate(DocForm.QA, language) } @@ -617,17 +617,9 @@ const StepTwo = ({ }, [isAPIKeySet, indexingType, datasetId]) useEffect(() => { - if (segmentationType === SegmentType.AUTO) { - setAutomaticFileIndexingEstimate(null) - !isMobile && setShowPreview() - fetchFileIndexingEstimate() - setPreviewSwitched(false) - } - else { - hidePreview() - setCustomFileIndexingEstimate(null) - setPreviewSwitched(false) - } + hidePreview() + setGeneralFileIndexingEstimate(null) + setPreviewSwitched(false) }, [segmentationType, indexType]) const [retrievalConfig, setRetrievalConfig] = useState(currentDataset?.retrieval_model_dict || { @@ -654,8 +646,8 @@ const StepTwo = ({ icon={{t('datasetCreation.stepTwo.general')}} activeHeaderClassName='bg-gradient-to-r from-[#EFF0F9] to-[#F9FAFB]' description={t('datasetCreation.stepTwo.generalTip')} - isActive={SegmentType.AUTO === segmentationType} - onClick={() => setSegmentationType(SegmentType.AUTO)} + isActive={SegmentType.GENERAL === segmentationType} + onClick={() => setSegmentationType(SegmentType.GENERAL)} actions={ <>