feat: when Layout recognize is false, hide pages (#144)

* feat: when Layout recognize is false, hide pages

* feat: fix the name column to the leftmost part of the KnowledgeFile table
This commit is contained in:
balibabu 2024-03-22 19:21:20 +08:00 committed by GitHub
parent f6aee7f230
commit da39723f17
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 144 additions and 125 deletions

View File

@ -1,4 +1,8 @@
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 { IChangeParserConfigRequestBody } from '@/interfaces/request/document';
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
import { import {
Button, Button,
Divider, Divider,
@ -9,14 +13,8 @@ import {
Switch, Switch,
Tag, Tag,
} from 'antd'; } from 'antd';
import React, { useEffect, useMemo } from 'react';
import MaxTokenNumber from '@/components/max-token-number';
import { IKnowledgeFileParserConfig } from '@/interfaces/database/knowledge';
import { IChangeParserConfigRequestBody } from '@/interfaces/request/document';
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
import omit from 'lodash/omit'; import omit from 'lodash/omit';
import {} from 'module'; import React, { useEffect, useMemo } from 'react';
import { useFetchParserListOnMount } from './hooks'; import { useFetchParserListOnMount } from './hooks';
import styles from './index.less'; import styles from './index.less';
@ -51,12 +49,10 @@ const ChunkMethodModal: React.FC<IProps> = ({
const handleOk = async () => { const handleOk = async () => {
const values = await form.validateFields(); const values = await form.validateFields();
console.info(values);
const parser_config = { const parser_config = {
...values.parser_config, ...values.parser_config,
pages: values.pages?.map((x: any) => [x.from, x.to]) ?? [], pages: values.pages?.map((x: any) => [x.from, x.to]) ?? [],
}; };
console.info(parser_config);
onOk(selectedTag, parser_config); onOk(selectedTag, parser_config);
}; };
@ -110,9 +106,29 @@ const ChunkMethodModal: React.FC<IProps> = ({
</div> </div>
</Space> </Space>
<Divider></Divider> <Divider></Divider>
{ {
<Form name="dynamic_form_nest_item" autoComplete="off" form={form}> <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.'
}
>
<Switch />
</Form.Item>
)}
{showPages && ( {showPages && (
<Form.Item
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 }) => (
@ -139,8 +155,11 @@ const ChunkMethodModal: React.FC<IProps> = ({
if ( if (
name === 0 || name === 0 ||
!value || !value ||
getFieldValue(['pages', name - 1, 'to']) < getFieldValue([
value 'pages',
name - 1,
'to',
]) < value
) { ) {
return Promise.resolve(); return Promise.resolve();
} }
@ -167,13 +186,15 @@ const ChunkMethodModal: React.FC<IProps> = ({
rules={[ rules={[
{ {
required: true, required: true,
message: 'Missing end page number(excluding)', message:
'Missing end page number(excluding)',
}, },
({ getFieldValue }) => ({ ({ getFieldValue }) => ({
validator(_, value) { validator(_, value) {
if ( if (
!value || !value ||
getFieldValue(['pages', name, 'from']) < value getFieldValue(['pages', name, 'from']) <
value
) { ) {
return Promise.resolve(); return Promise.resolve();
} }
@ -194,7 +215,9 @@ const ChunkMethodModal: React.FC<IProps> = ({
/> />
</Form.Item> </Form.Item>
{name > 0 && ( {name > 0 && (
<MinusCircleOutlined onClick={() => remove(name)} /> <MinusCircleOutlined
onClick={() => remove(name)}
/>
)} )}
</Space> </Space>
))} ))}
@ -211,10 +234,12 @@ const ChunkMethodModal: React.FC<IProps> = ({
</> </>
)} )}
</Form.List> </Form.List>
<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={'coming soon'} 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={2}
rules={[ rules={[
{ {
@ -226,18 +251,11 @@ const ChunkMethodModal: React.FC<IProps> = ({
<InputNumber min={1} max={128} /> <InputNumber min={1} max={128} />
</Form.Item> </Form.Item>
</> </>
)} )
{showOne && ( }
<Form.Item
name={['parser_config', 'layout_recognize']}
label="Layout recognize"
initialValue={true}
valuePropName="checked"
tooltip={'coming soon'}
>
<Switch />
</Form.Item> </Form.Item>
)} )}
{selectedTag === 'naive' && <MaxTokenNumber></MaxTokenNumber>} {selectedTag === 'naive' && <MaxTokenNumber></MaxTokenNumber>}
</Form> </Form>
} }

View File

@ -112,6 +112,7 @@ const KnowledgeFile = () => {
title: 'Name', title: 'Name',
dataIndex: 'name', dataIndex: 'name',
key: 'name', key: 'name',
fixed: 'left',
render: (text: any, { id, thumbnail }) => ( render: (text: any, { id, thumbnail }) => (
<div className={styles.tochunks} onClick={() => toChunk(id)}> <div className={styles.tochunks} onClick={() => toChunk(id)}>
<img className={styles.img} src={thumbnail} alt="" /> <img className={styles.img} src={thumbnail} alt="" />