| 'use client' | 'use client' | ||||
| import type { FC } from 'react' | import type { FC } from 'react' | ||||
| import React, { useCallback, useState } from 'react' | |||||
| import React, { useCallback, useMemo, useState } from 'react' | |||||
| import { useBoolean } from 'ahooks' | import { useBoolean } from 'ahooks' | ||||
| import { RiArrowDownSLine } from '@remixicon/react' | import { RiArrowDownSLine } from '@remixicon/react' | ||||
| import { useTranslation } from 'react-i18next' | import { useTranslation } from 'react-i18next' | ||||
| }, | }, | ||||
| }) | }) | ||||
| const documentsList = data?.data | const documentsList = data?.data | ||||
| const isGeneralMode = chunkingMode === ChunkingMode.text | |||||
| const isParentChild = chunkingMode === ChunkingMode.parentChild | const isParentChild = chunkingMode === ChunkingMode.parentChild | ||||
| const isQAMode = chunkingMode === ChunkingMode.qa | |||||
| const TypeIcon = isParentChild ? ParentChildChunk : GeneralChunk | const TypeIcon = isParentChild ? ParentChildChunk : GeneralChunk | ||||
| const [open, { | const [open, { | ||||
| setOpen(false) | setOpen(false) | ||||
| }, [documentsList, onChange, setOpen]) | }, [documentsList, onChange, setOpen]) | ||||
| const parentModeLabel = useMemo(() => { | |||||
| if (!parentMode) | |||||
| return '--' | |||||
| return parentMode === 'paragraph' ? t('dataset.parentMode.paragraph') : t('dataset.parentMode.fullDoc') | |||||
| }, [parentMode, t]) | |||||
| return ( | return ( | ||||
| <PortalToFollowElem | <PortalToFollowElem | ||||
| open={open} | open={open} | ||||
| <div className='flex h-3 items-center space-x-0.5 text-text-tertiary'> | <div className='flex h-3 items-center space-x-0.5 text-text-tertiary'> | ||||
| <TypeIcon className='h-3 w-3' /> | <TypeIcon className='h-3 w-3' /> | ||||
| <span className={cn('system-2xs-medium-uppercase', isParentChild && 'mt-0.5' /* to icon problem cause not ver align */)}> | <span className={cn('system-2xs-medium-uppercase', isParentChild && 'mt-0.5' /* to icon problem cause not ver align */)}> | ||||
| {isParentChild ? t('dataset.chunkingMode.parentChild') : t('dataset.chunkingMode.general')} | |||||
| {isParentChild && ` · ${!parentMode ? '--' : parentMode === 'paragraph' ? t('dataset.parentMode.paragraph') : t('dataset.parentMode.fullDoc')}`} | |||||
| {isGeneralMode && t('dataset.chunkingMode.general')} | |||||
| {isQAMode && t('dataset.chunkingMode.qa')} | |||||
| {isParentChild && `${t('dataset.chunkingMode.parentChild')} · ${parentModeLabel}`} | |||||
| </span> | </span> | ||||
| </div> | </div> | ||||
| </div> | </div> |
| import Divider from '@/app/components/base/divider' | import Divider from '@/app/components/base/divider' | ||||
| import Loading from '@/app/components/base/loading' | import Loading from '@/app/components/base/loading' | ||||
| import Toast from '@/app/components/base/toast' | import Toast from '@/app/components/base/toast' | ||||
| import type { ChunkingMode, FileItem } from '@/models/datasets' | |||||
| import { ChunkingMode } from '@/models/datasets' | |||||
| import type { FileItem } from '@/models/datasets' | |||||
| import { useDatasetDetailContextWithSelector } from '@/context/dataset-detail' | import { useDatasetDetailContextWithSelector } from '@/context/dataset-detail' | ||||
| import FloatRightContainer from '@/app/components/base/float-right-container' | import FloatRightContainer from '@/app/components/base/float-right-container' | ||||
| import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' | import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' | ||||
| } | } | ||||
| } | } | ||||
| const mode = useMemo(() => { | |||||
| if (documentDetail?.document_process_rule?.mode) | |||||
| return documentDetail.document_process_rule.mode | |||||
| return documentDetail?.doc_form === 'hierarchical_model' ? 'hierarchical' : 'custom' | |||||
| }, [documentDetail?.document_process_rule?.mode, documentDetail?.dataset_process_rule?.mode]) | |||||
| const parentMode = useMemo(() => { | const parentMode = useMemo(() => { | ||||
| return documentDetail?.document_process_rule?.rules?.parent_mode || documentDetail?.dataset_process_rule?.rules?.parent_mode || 'paragraph' | return documentDetail?.document_process_rule?.rules?.parent_mode || documentDetail?.dataset_process_rule?.rules?.parent_mode || 'paragraph' | ||||
| }, [documentDetail?.document_process_rule?.rules?.parent_mode, documentDetail?.dataset_process_rule?.rules?.parent_mode]) | }, [documentDetail?.document_process_rule?.rules?.parent_mode, documentDetail?.dataset_process_rule?.rules?.parent_mode]) | ||||
| const isFullDocMode = useMemo(() => { | const isFullDocMode = useMemo(() => { | ||||
| return mode === 'hierarchical' && parentMode === 'full-doc' | |||||
| }, [mode, parentMode]) | |||||
| const chunkMode = documentDetail?.doc_form | |||||
| return chunkMode === ChunkingMode.parentChild && parentMode === 'full-doc' | |||||
| }, [documentDetail?.doc_form, parentMode]) | |||||
| return ( | return ( | ||||
| <DocumentContext.Provider value={{ | <DocumentContext.Provider value={{ |
| 'use client' | 'use client' | ||||
| import { useTranslation } from 'react-i18next' | import { useTranslation } from 'react-i18next' | ||||
| import { formatFileSize, formatNumber, formatTime } from '@/utils/format' | import { formatFileSize, formatNumber, formatTime } from '@/utils/format' | ||||
| import { type DocType, ProcessMode } from '@/models/datasets' | |||||
| import { ChunkingMode, type DocType } from '@/models/datasets' | |||||
| import useTimestamp from '@/hooks/use-timestamp' | import useTimestamp from '@/hooks/use-timestamp' | ||||
| export type inputType = 'input' | 'select' | 'textarea' | export type inputType = 'input' | 'select' | 'textarea' | ||||
| text: t('datasetDocuments.metadata.type.technicalParameters'), | text: t('datasetDocuments.metadata.type.technicalParameters'), | ||||
| allowEdit: false, | allowEdit: false, | ||||
| subFieldsMap: { | subFieldsMap: { | ||||
| 'dataset_process_rule.mode': { | |||||
| 'doc_form': { | |||||
| label: t(`${fieldPrefix}.technicalParameters.segmentSpecification`), | label: t(`${fieldPrefix}.technicalParameters.segmentSpecification`), | ||||
| render: value => value === ProcessMode.general ? (t('datasetDocuments.embedding.custom') as string) : (t('datasetDocuments.embedding.hierarchical') as string), | |||||
| render: (value) => { | |||||
| if (value === ChunkingMode.text) | |||||
| return t('dataset.chunkingMode.general') | |||||
| if (value === ChunkingMode.qa) | |||||
| return t('dataset.chunkingMode.qa') | |||||
| if (value === ChunkingMode.parentChild) | |||||
| return t('dataset.chunkingMode.parentChild') | |||||
| return '--' | |||||
| }, | |||||
| }, | }, | ||||
| 'dataset_process_rule.rules.segmentation.max_tokens': { | 'dataset_process_rule.rules.segmentation.max_tokens': { | ||||
| label: t(`${fieldPrefix}.technicalParameters.segmentLength`), | label: t(`${fieldPrefix}.technicalParameters.segmentLength`), |