wip: qa mode

pull/12097/head
AkaraChen 1 year ago
parent 4048eff3ab
commit 5bf6cd242d

@ -58,6 +58,7 @@ import { getNotionInfo, getWebsiteInfo, useCreateDocument, useCreateFirstDocumen
import Loading from '@/app/components/base/loading' import Loading from '@/app/components/base/loading'
import Badge from '@/app/components/base/badge' import Badge from '@/app/components/base/badge'
import { SkeletonContanier, SkeletonPoint, SkeletonRectangle, SkeletonRow } from '@/app/components/base/skeleton' import { SkeletonContanier, SkeletonPoint, SkeletonRectangle, SkeletonRow } from '@/app/components/base/skeleton'
import Tooltip from '@/app/components/base/tooltip'
const TextLabel: FC<PropsWithChildren> = (props) => { const TextLabel: FC<PropsWithChildren> = (props) => {
return <label className='text-text-secondary text-xs font-semibold leading-none'>{props.children}</label> return <label className='text-text-secondary text-xs font-semibold leading-none'>{props.children}</label>
@ -166,15 +167,17 @@ const StepTwo = ({
? IndexingType.QUALIFIED ? IndexingType.QUALIFIED
: IndexingType.ECONOMICAL, : IndexingType.ECONOMICAL,
) )
// QA Related
const [isLanguageSelectDisabled, setIsLanguageSelectDisabled] = useState(false) const [isLanguageSelectDisabled, setIsLanguageSelectDisabled] = useState(false)
const [docForm, setDocForm] = useState<DocForm | string>( const [docForm, setDocForm] = useState<DocForm | string>(
(datasetId && documentDetail) ? documentDetail.doc_form : DocForm.TEXT, (datasetId && documentDetail) ? documentDetail.doc_form : DocForm.TEXT,
) )
const [docLanguage, setDocLanguage] = useState<string>( const [docLanguage, setDocLanguage] = useState<string>(
(datasetId && documentDetail) ? documentDetail.doc_language : (locale !== LanguagesSupported[1] ? 'English' : 'Chinese'), (datasetId && documentDetail) ? documentDetail.doc_language : (locale !== LanguagesSupported[1] ? 'English' : 'Chinese'),
) )
const [QATipHide, setQATipHide] = useState(false) const [QATipHide, setQATipHide] = useState(false)
const [qaPreviewSwitched, setQAPreviewSwitched] = useState(false)
const [parentChildConfig, setParentChildConfig] = useState<ParentChildConfig>(defaultParentChildConfig) const [parentChildConfig, setParentChildConfig] = useState<ParentChildConfig>(defaultParentChildConfig)
@ -255,22 +258,6 @@ const StepTwo = ({
? notionIndexingEstimateQuery.data ? notionIndexingEstimateQuery.data
: websiteIndexingEstimateQuery.data : websiteIndexingEstimateQuery.data
// const getIsEstimateReady = useCallback(() => {
// if (dataSourceType === DataSourceType.FILE)
// return fileIndexingEstimateQuery.isSuccess
// if (dataSourceType === DataSourceType.NOTION)
// return notionIndexingEstimateQuery.isSuccess
// if (dataSourceType === DataSourceType.WEB)
// return websiteIndexingEstimateQuery.isSuccess
// }, [dataSourceType, fileIndexingEstimateQuery.isSuccess, notionIndexingEstimateQuery.isSuccess, websiteIndexingEstimateQuery.isSuccess])
// const getFileName = (name: string) => {
// const arr = name.split('.')
// return arr.slice(0, -1).join('.')
// }
const getRuleName = (key: string) => { const getRuleName = (key: string) => {
if (key === 'remove_extra_spaces') if (key === 'remove_extra_spaces')
return t('datasetCreation.stepTwo.removeExtraSpaces') return t('datasetCreation.stepTwo.removeExtraSpaces')
@ -309,7 +296,6 @@ const StepTwo = ({
return return
} }
fetchEstimate() fetchEstimate()
setQAPreviewSwitched(false)
} }
const { const {
@ -503,7 +489,6 @@ const StepTwo = ({
} }
const previewSwitch = () => { const previewSwitch = () => {
setQAPreviewSwitched(true)
setIsLanguageSelectDisabled(true) setIsLanguageSelectDisabled(true)
fetchEstimate() fetchEstimate()
} }
@ -511,7 +496,7 @@ const StepTwo = ({
const handleSelect = (language: string) => { const handleSelect = (language: string) => {
setDocLanguage(language) setDocLanguage(language)
// Switch language, re-cutter // Switch language, re-cutter
if (docForm === DocForm.QA && qaPreviewSwitched) if (docForm === DocForm.QA)
previewSwitch() previewSwitch()
} }
@ -618,6 +603,31 @@ const StepTwo = ({
</div> </div>
</div> </div>
</div> </div>
{IS_CE_EDITION && <div className='flex items-center'>
<Checkbox
checked={docForm === DocForm.QA}
onCheck={() => {
if (docForm === DocForm.QA)
setDocForm(DocForm.TEXT)
else
setDocForm(DocForm.QA)
}}
className='mr-2'
/>
<div className='flex items-center gap-1'>
<TextLabel>
Chunk using Q&A format in
</TextLabel>
<div className='z-50 relative'>
<LanguageSelect
currentLanguage={docLanguage || locale}
onSelect={setDocLanguage}
disabled={isLanguageSelectDisabled}
/>
</div>
<Tooltip popupContent={t('datasetCreation.stepTwo.qaTip')} />
</div>
</div>}
</div> </div>
</OptionCard> </OptionCard>
<OptionCard <OptionCard
@ -927,12 +937,12 @@ const StepTwo = ({
</PreviewHeader>} </PreviewHeader>}
className={cn(s.previewWrap, isMobile && s.isMobile, 'relative h-full overflow-y-scroll space-y-4')} className={cn(s.previewWrap, isMobile && s.isMobile, 'relative h-full overflow-y-scroll space-y-4')}
> >
{qaPreviewSwitched && docForm === DocForm.QA && estimate?.qa_preview && ( {docForm === DocForm.QA && estimate?.qa_preview && (
estimate?.qa_preview.map(item => ( estimate?.qa_preview.map(item => (
<QAPreview key={item.question} qa={item} /> <QAPreview key={item.question} qa={item} />
)) ))
)} )}
{(docForm === DocForm.TEXT || !qaPreviewSwitched) && estimate?.preview && ( {docForm === DocForm.TEXT && estimate?.preview && (
estimate?.preview.map((item, index) => ( estimate?.preview.map((item, index) => (
<ChunkContainer <ChunkContainer
key={item} key={item}
@ -943,16 +953,11 @@ const StepTwo = ({
</ChunkContainer> </ChunkContainer>
)) ))
)} )}
{qaPreviewSwitched && docForm === DocForm.QA && !estimate?.qa_preview && ( {docForm === DocForm.QA && !estimate?.qa_preview && (
<div className='flex items-center justify-center h-[200px]'> <div className='flex items-center justify-center h-[200px]'>
<Loading type='area' /> <Loading type='area' />
</div> </div>
)} )}
{/* {!qaPreviewSwitched && !estimate?.preview && (
<div className='flex items-center justify-center h-[200px]'>
<Loading type='area' />
</div>
)} */}
{currentEstimateMutation.isIdle && ( {currentEstimateMutation.isIdle && (
<div className='h-full w-full flex items-center justify-center'> <div className='h-full w-full flex items-center justify-center'>
<div className='flex flex-col items-center justify-center gap-3'> <div className='flex flex-col items-center justify-center gap-3'>

@ -22,6 +22,7 @@ const LanguageSelect: FC<ILanguageSelectProps> = ({
manualClose manualClose
trigger='click' trigger='click'
disabled={disabled} disabled={disabled}
popupClassName='z-20'
htmlContent={ htmlContent={
<div className='w-full py-1'> <div className='w-full py-1'>
{languages.filter(language => language.supported).map(({ prompt_name }) => ( {languages.filter(language => language.supported).map(({ prompt_name }) => (

Loading…
Cancel
Save