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 { IKnowledgeFileParserConfig } from '@/interfaces/database/knowledge';
import { IChangeParserConfigRequestBody } from '@/interfaces/request/document';
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
import {
MinusCircleOutlined,
PlusOutlined,
QuestionCircleOutlined,
} from '@ant-design/icons';
import {
Button,
Divider,
@ -12,6 +16,7 @@ import {
Space,
Switch,
Tag,
Tooltip,
} from 'antd';
import omit from 'lodash/omit';
import React, { useEffect, useMemo } from 'react';
@ -31,6 +36,7 @@ interface IProps extends Omit<IModalManagerChildrenProps, 'showModal'> {
parserId: string;
parserConfig: IKnowledgeFileParserConfig;
documentType: string;
disabled: boolean;
}
const hidePagesChunkMethods = ['qa', 'table', 'picture', 'resume', 'one'];
@ -40,6 +46,7 @@ const ChunkMethodModal: React.FC<IProps> = ({
onOk,
hideModal,
visible,
disabled,
documentType,
parserConfig,
}) => {
@ -89,6 +96,7 @@ const ChunkMethodModal: React.FC<IProps> = ({
onOk={handleOk}
onCancel={hideModal}
afterClose={afterClose}
okButtonProps={{ disabled }}
>
<Space size={[0, 8]} wrap>
<div className={styles.tags}>
@ -97,7 +105,11 @@ const ChunkMethodModal: React.FC<IProps> = ({
<CheckableTag
key={x.value}
checked={selectedTag === x.value}
onChange={(checked) => handleChange(x.value, checked)}
onChange={(checked) => {
if (!disabled) {
handleChange(x.value, checked);
}
}}
>
{x.label}
</CheckableTag>
@ -108,7 +120,125 @@ const ChunkMethodModal: React.FC<IProps> = ({
<Divider></Divider>
{
<Form name="dynamic_form_nest_item" autoComplete="off" form={form}>
<Form
name="dynamic_form_nest_item"
autoComplete="off"
form={form}
disabled={disabled}
>
{showPages && (
<>
<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.'
}
>
<QuestionCircleOutlined
className={styles.questionIcon}
></QuestionCircleOutlined>
</Tooltip>
</Space>
<Form.List name="pages">
{(fields, { add, remove }) => (
<>
{fields.map(({ key, name, ...restField }) => (
<Space
key={key}
style={{
display: 'flex',
}}
align="baseline"
>
<Form.Item
{...restField}
name={[name, 'from']}
dependencies={name > 0 ? [name - 1, 'to'] : []}
rules={[
{
required: true,
message: 'Missing start page number',
},
({ getFieldValue }) => ({
validator(_, value) {
if (
name === 0 ||
!value ||
getFieldValue(['pages', name - 1, 'to']) <
value
) {
return Promise.resolve();
}
return Promise.reject(
new Error(
'The current value must be greater than the previous to!',
),
);
},
}),
]}
>
<InputNumber
placeholder="from"
min={0}
precision={0}
className={styles.pageInputNumber}
/>
</Form.Item>
<Form.Item
{...restField}
name={[name, 'to']}
dependencies={[name, 'from']}
rules={[
{
required: true,
message: 'Missing end page number(excluding)',
},
({ getFieldValue }) => ({
validator(_, value) {
if (
!value ||
getFieldValue(['pages', name, 'from']) < value
) {
return Promise.resolve();
}
return Promise.reject(
new Error(
'The current value must be greater than to!',
),
);
},
}),
]}
>
<InputNumber
placeholder="to"
min={0}
precision={0}
className={styles.pageInputNumber}
/>
</Form.Item>
{name > 0 && (
<MinusCircleOutlined onClick={() => remove(name)} />
)}
</Space>
))}
<Form.Item>
<Button
type="dashed"
onClick={() => add()}
block
icon={<PlusOutlined />}
>
Add page
</Button>
</Form.Item>
</>
)}
</Form.List>
</>
)}
{showOne && (
<Form.Item
name={['parser_config', 'layout_recognize']}
@ -129,128 +259,21 @@ const ChunkMethodModal: React.FC<IProps> = ({
>
{({ getFieldValue }) =>
getFieldValue(['parser_config', 'layout_recognize']) && (
<>
<Form.List name="pages">
{(fields, { add, remove }) => (
<>
{fields.map(({ key, name, ...restField }) => (
<Space
key={key}
style={{
display: 'flex',
}}
align="baseline"
>
<Form.Item
{...restField}
name={[name, 'from']}
dependencies={name > 0 ? [name - 1, 'to'] : []}
rules={[
{
required: true,
message: 'Missing start page number',
},
({ getFieldValue }) => ({
validator(_, value) {
if (
name === 0 ||
!value ||
getFieldValue([
'pages',
name - 1,
'to',
]) < value
) {
return Promise.resolve();
}
return Promise.reject(
new Error(
'The current value must be greater than the previous to!',
),
);
},
}),
]}
>
<InputNumber
placeholder="from"
min={0}
precision={0}
className={styles.pageInputNumber}
/>
</Form.Item>
<Form.Item
{...restField}
name={[name, 'to']}
dependencies={[name, 'from']}
rules={[
{
required: true,
message:
'Missing end page number(excluding)',
},
({ getFieldValue }) => ({
validator(_, value) {
if (
!value ||
getFieldValue(['pages', name, 'from']) <
value
) {
return Promise.resolve();
}
return Promise.reject(
new Error(
'The current value must be greater than to!',
),
);
},
}),
]}
>
<InputNumber
placeholder="to"
min={0}
precision={0}
className={styles.pageInputNumber}
/>
</Form.Item>
{name > 0 && (
<MinusCircleOutlined
onClick={() => remove(name)}
/>
)}
</Space>
))}
<Form.Item>
<Button
type="dashed"
onClick={() => add()}
block
icon={<PlusOutlined />}
>
Add page
</Button>
</Form.Item>
</>
)}
</Form.List>
<Form.Item
name={['parser_config', '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.
<Form.Item
name={['parser_config', '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.
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}
rules={[
{
required: true,
message: 'Please input your task page size!',
},
]}
>
<InputNumber min={1} max={128} />
</Form.Item>
</>
initialValue={12}
rules={[
{
required: true,
message: 'Please input your task page size!',
},
]}
>
<InputNumber min={1} max={128} />
</Form.Item>
)
}
</Form.Item>

View File

@ -38,3 +38,10 @@
.pageInputNumber {
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}
visible={changeParserVisible}
hideModal={hideChangeParserModal}
disabled={currentRecord.chunk_num > 0}
loading={changeParserLoading}
/>
<RenameModal