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,28 +120,26 @@ const ChunkMethodModal: React.FC<IProps> = ({
<Divider></Divider>
{
<Form name="dynamic_form_nest_item" autoComplete="off" form={form}>
{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.'
<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.'
}
>
<Switch />
</Form.Item>
)}
{showPages && (
<Form.Item
noStyle
dependencies={[['parser_config', 'layout_recognize']]}
>
{({ getFieldValue }) =>
getFieldValue(['parser_config', 'layout_recognize']) && (
<>
<QuestionCircleOutlined
className={styles.questionIcon}
></QuestionCircleOutlined>
</Tooltip>
</Space>
<Form.List name="pages">
{(fields, { add, remove }) => (
<>
@ -155,11 +165,8 @@ const ChunkMethodModal: React.FC<IProps> = ({
if (
name === 0 ||
!value ||
getFieldValue([
'pages',
name - 1,
'to',
]) < value
getFieldValue(['pages', name - 1, 'to']) <
value
) {
return Promise.resolve();
}
@ -186,15 +193,13 @@ const ChunkMethodModal: React.FC<IProps> = ({
rules={[
{
required: true,
message:
'Missing end page number(excluding)',
message: 'Missing end page number(excluding)',
},
({ getFieldValue }) => ({
validator(_, value) {
if (
!value ||
getFieldValue(['pages', name, 'from']) <
value
getFieldValue(['pages', name, 'from']) < value
) {
return Promise.resolve();
}
@ -215,9 +220,7 @@ const ChunkMethodModal: React.FC<IProps> = ({
/>
</Form.Item>
{name > 0 && (
<MinusCircleOutlined
onClick={() => remove(name)}
/>
<MinusCircleOutlined onClick={() => remove(name)} />
)}
</Space>
))}
@ -234,13 +237,34 @@ const ChunkMethodModal: React.FC<IProps> = ({
</>
)}
</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
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}
initialValue={12}
rules={[
{
required: true,
@ -250,7 +274,6 @@ const ChunkMethodModal: React.FC<IProps> = ({
>
<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