feat: move layout_recognize to the bottom (#146)

* feat: add Page Ranges label

* feat: move layout_recognize to the bottom
This commit is contained in:
balibabu 2024-03-25 12:54:10 +08:00 committed by GitHub
parent da39723f17
commit 1d9a50b090
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 155 additions and 124 deletions

View File

@ -2,7 +2,11 @@ import MaxTokenNumber from '@/components/max-token-number';
import { IModalManagerChildrenProps } from '@/components/modal-manager'; import { IModalManagerChildrenProps } from '@/components/modal-manager';
import { IKnowledgeFileParserConfig } from '@/interfaces/database/knowledge'; import { IKnowledgeFileParserConfig } from '@/interfaces/database/knowledge';
import { IChangeParserConfigRequestBody } from '@/interfaces/request/document'; import { IChangeParserConfigRequestBody } from '@/interfaces/request/document';
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'; import {
MinusCircleOutlined,
PlusOutlined,
QuestionCircleOutlined,
} from '@ant-design/icons';
import { import {
Button, Button,
Divider, Divider,
@ -12,6 +16,7 @@ import {
Space, Space,
Switch, Switch,
Tag, Tag,
Tooltip,
} from 'antd'; } from 'antd';
import omit from 'lodash/omit'; import omit from 'lodash/omit';
import React, { useEffect, useMemo } from 'react'; import React, { useEffect, useMemo } from 'react';
@ -31,6 +36,7 @@ interface IProps extends Omit<IModalManagerChildrenProps, 'showModal'> {
parserId: string; parserId: string;
parserConfig: IKnowledgeFileParserConfig; parserConfig: IKnowledgeFileParserConfig;
documentType: string; documentType: string;
disabled: boolean;
} }
const hidePagesChunkMethods = ['qa', 'table', 'picture', 'resume', 'one']; const hidePagesChunkMethods = ['qa', 'table', 'picture', 'resume', 'one'];
@ -40,6 +46,7 @@ const ChunkMethodModal: React.FC<IProps> = ({
onOk, onOk,
hideModal, hideModal,
visible, visible,
disabled,
documentType, documentType,
parserConfig, parserConfig,
}) => { }) => {
@ -89,6 +96,7 @@ const ChunkMethodModal: React.FC<IProps> = ({
onOk={handleOk} onOk={handleOk}
onCancel={hideModal} onCancel={hideModal}
afterClose={afterClose} afterClose={afterClose}
okButtonProps={{ disabled }}
> >
<Space size={[0, 8]} wrap> <Space size={[0, 8]} wrap>
<div className={styles.tags}> <div className={styles.tags}>
@ -97,7 +105,11 @@ const ChunkMethodModal: React.FC<IProps> = ({
<CheckableTag <CheckableTag
key={x.value} key={x.value}
checked={selectedTag === x.value} checked={selectedTag === x.value}
onChange={(checked) => handleChange(x.value, checked)} onChange={(checked) => {
if (!disabled) {
handleChange(x.value, checked);
}
}}
> >
{x.label} {x.label}
</CheckableTag> </CheckableTag>
@ -108,28 +120,26 @@ const ChunkMethodModal: React.FC<IProps> = ({
<Divider></Divider> <Divider></Divider>
{ {
<Form name="dynamic_form_nest_item" autoComplete="off" form={form}> <Form
{showOne && ( name="dynamic_form_nest_item"
<Form.Item autoComplete="off"
name={['parser_config', 'layout_recognize']} form={form}
label="Layout recognize" disabled={disabled}
initialValue={true} >
valuePropName="checked" {showPages && (
tooltip={ <>
'Use visual models for layout analysis to better identify document structure, find where the titles, text blocks, images, and tables are. Without this feature, only the plain text of the PDF can be obtained.' <Space>
<p>Page Ranges:</p>
<Tooltip
title={
'page ranges: Define the page ranges that need to be parsed. The pages that not included in these ranges will be ignored.'
} }
> >
<Switch /> <QuestionCircleOutlined
</Form.Item> className={styles.questionIcon}
)} ></QuestionCircleOutlined>
{showPages && ( </Tooltip>
<Form.Item </Space>
noStyle
dependencies={[['parser_config', 'layout_recognize']]}
>
{({ getFieldValue }) =>
getFieldValue(['parser_config', 'layout_recognize']) && (
<>
<Form.List name="pages"> <Form.List name="pages">
{(fields, { add, remove }) => ( {(fields, { add, remove }) => (
<> <>
@ -155,11 +165,8 @@ const ChunkMethodModal: React.FC<IProps> = ({
if ( if (
name === 0 || name === 0 ||
!value || !value ||
getFieldValue([ getFieldValue(['pages', name - 1, 'to']) <
'pages', value
name - 1,
'to',
]) < value
) { ) {
return Promise.resolve(); return Promise.resolve();
} }
@ -186,15 +193,13 @@ const ChunkMethodModal: React.FC<IProps> = ({
rules={[ rules={[
{ {
required: true, required: true,
message: message: 'Missing end page number(excluding)',
'Missing end page number(excluding)',
}, },
({ getFieldValue }) => ({ ({ getFieldValue }) => ({
validator(_, value) { validator(_, value) {
if ( if (
!value || !value ||
getFieldValue(['pages', name, 'from']) < getFieldValue(['pages', name, 'from']) < value
value
) { ) {
return Promise.resolve(); return Promise.resolve();
} }
@ -215,9 +220,7 @@ const ChunkMethodModal: React.FC<IProps> = ({
/> />
</Form.Item> </Form.Item>
{name > 0 && ( {name > 0 && (
<MinusCircleOutlined <MinusCircleOutlined onClick={() => remove(name)} />
onClick={() => remove(name)}
/>
)} )}
</Space> </Space>
))} ))}
@ -234,13 +237,34 @@ const ChunkMethodModal: React.FC<IProps> = ({
</> </>
)} )}
</Form.List> </Form.List>
</>
)}
{showOne && (
<Form.Item
name={['parser_config', 'layout_recognize']}
label="Layout recognize"
initialValue={true}
valuePropName="checked"
tooltip={
'Use visual models for layout analysis to better identify document structure, find where the titles, text blocks, images, and tables are. Without this feature, only the plain text of the PDF can be obtained.'
}
>
<Switch />
</Form.Item>
)}
{showPages && (
<Form.Item
noStyle
dependencies={[['parser_config', 'layout_recognize']]}
>
{({ getFieldValue }) =>
getFieldValue(['parser_config', 'layout_recognize']) && (
<Form.Item <Form.Item
name={['parser_config', 'task_page_size']} name={['parser_config', 'task_page_size']}
label="Task page size" label="Task page size"
tooltip={`If using layout recognize, the PDF file will be split into groups of successive. Layout analysis will be performed parallelly between groups to increase the processing speed. tooltip={`If using layout recognize, the PDF file will be split into groups of successive. Layout analysis will be performed parallelly between groups to increase the processing speed.
The 'Task page size' determines the size of groups. The larger the page size is, the lower the chance of splitting continuous text between pages into different chunks.`} The 'Task page size' determines the size of groups. The larger the page size is, the lower the chance of splitting continuous text between pages into different chunks.`}
initialValue={2} initialValue={12}
rules={[ rules={[
{ {
required: true, required: true,
@ -250,7 +274,6 @@ const ChunkMethodModal: React.FC<IProps> = ({
> >
<InputNumber min={1} max={128} /> <InputNumber min={1} max={128} />
</Form.Item> </Form.Item>
</>
) )
} }
</Form.Item> </Form.Item>

View File

@ -38,3 +38,10 @@
.pageInputNumber { .pageInputNumber {
width: 220px; width: 220px;
} }
.questionIcon {
margin-inline-start: 4px;
color: rgba(0, 0, 0, 0.45);
cursor: help;
writing-mode: horizontal-tb;
}

View File

@ -231,6 +231,7 @@ const KnowledgeFile = () => {
onOk={onChangeParserOk} onOk={onChangeParserOk}
visible={changeParserVisible} visible={changeParserVisible}
hideModal={hideChangeParserModal} hideModal={hideChangeParserModal}
disabled={currentRecord.chunk_num > 0}
loading={changeParserLoading} loading={changeParserLoading}
/> />
<RenameModal <RenameModal