balibabu
commited on
Commit
·
69fc4f3
1
Parent(s):
431cdbc
feat: move layout_recognize to the bottom (#146)
Browse files* feat: add Page Ranges label
* feat: move layout_recognize to the bottom
web/src/pages/add-knowledge/components/knowledge-file/chunk-method-modal.tsx
CHANGED
|
@@ -2,7 +2,11 @@ import MaxTokenNumber from '@/components/max-token-number';
|
|
| 2 |
import { IModalManagerChildrenProps } from '@/components/modal-manager';
|
| 3 |
import { IKnowledgeFileParserConfig } from '@/interfaces/database/knowledge';
|
| 4 |
import { IChangeParserConfigRequestBody } from '@/interfaces/request/document';
|
| 5 |
-
import {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
import {
|
| 7 |
Button,
|
| 8 |
Divider,
|
|
@@ -12,6 +16,7 @@ import {
|
|
| 12 |
Space,
|
| 13 |
Switch,
|
| 14 |
Tag,
|
|
|
|
| 15 |
} from 'antd';
|
| 16 |
import omit from 'lodash/omit';
|
| 17 |
import React, { useEffect, useMemo } from 'react';
|
|
@@ -31,6 +36,7 @@ interface IProps extends Omit<IModalManagerChildrenProps, 'showModal'> {
|
|
| 31 |
parserId: string;
|
| 32 |
parserConfig: IKnowledgeFileParserConfig;
|
| 33 |
documentType: string;
|
|
|
|
| 34 |
}
|
| 35 |
|
| 36 |
const hidePagesChunkMethods = ['qa', 'table', 'picture', 'resume', 'one'];
|
|
@@ -40,6 +46,7 @@ const ChunkMethodModal: React.FC<IProps> = ({
|
|
| 40 |
onOk,
|
| 41 |
hideModal,
|
| 42 |
visible,
|
|
|
|
| 43 |
documentType,
|
| 44 |
parserConfig,
|
| 45 |
}) => {
|
|
@@ -89,6 +96,7 @@ const ChunkMethodModal: React.FC<IProps> = ({
|
|
| 89 |
onOk={handleOk}
|
| 90 |
onCancel={hideModal}
|
| 91 |
afterClose={afterClose}
|
|
|
|
| 92 |
>
|
| 93 |
<Space size={[0, 8]} wrap>
|
| 94 |
<div className={styles.tags}>
|
|
@@ -97,7 +105,11 @@ const ChunkMethodModal: React.FC<IProps> = ({
|
|
| 97 |
<CheckableTag
|
| 98 |
key={x.value}
|
| 99 |
checked={selectedTag === x.value}
|
| 100 |
-
onChange={(checked) =>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
>
|
| 102 |
{x.label}
|
| 103 |
</CheckableTag>
|
|
@@ -108,7 +120,125 @@ const ChunkMethodModal: React.FC<IProps> = ({
|
|
| 108 |
<Divider></Divider>
|
| 109 |
|
| 110 |
{
|
| 111 |
-
<Form
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
{showOne && (
|
| 113 |
<Form.Item
|
| 114 |
name={['parser_config', 'layout_recognize']}
|
|
@@ -129,128 +259,21 @@ const ChunkMethodModal: React.FC<IProps> = ({
|
|
| 129 |
>
|
| 130 |
{({ getFieldValue }) =>
|
| 131 |
getFieldValue(['parser_config', 'layout_recognize']) && (
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
{fields.map(({ key, name, ...restField }) => (
|
| 137 |
-
<Space
|
| 138 |
-
key={key}
|
| 139 |
-
style={{
|
| 140 |
-
display: 'flex',
|
| 141 |
-
}}
|
| 142 |
-
align="baseline"
|
| 143 |
-
>
|
| 144 |
-
<Form.Item
|
| 145 |
-
{...restField}
|
| 146 |
-
name={[name, 'from']}
|
| 147 |
-
dependencies={name > 0 ? [name - 1, 'to'] : []}
|
| 148 |
-
rules={[
|
| 149 |
-
{
|
| 150 |
-
required: true,
|
| 151 |
-
message: 'Missing start page number',
|
| 152 |
-
},
|
| 153 |
-
({ getFieldValue }) => ({
|
| 154 |
-
validator(_, value) {
|
| 155 |
-
if (
|
| 156 |
-
name === 0 ||
|
| 157 |
-
!value ||
|
| 158 |
-
getFieldValue([
|
| 159 |
-
'pages',
|
| 160 |
-
name - 1,
|
| 161 |
-
'to',
|
| 162 |
-
]) < value
|
| 163 |
-
) {
|
| 164 |
-
return Promise.resolve();
|
| 165 |
-
}
|
| 166 |
-
return Promise.reject(
|
| 167 |
-
new Error(
|
| 168 |
-
'The current value must be greater than the previous to!',
|
| 169 |
-
),
|
| 170 |
-
);
|
| 171 |
-
},
|
| 172 |
-
}),
|
| 173 |
-
]}
|
| 174 |
-
>
|
| 175 |
-
<InputNumber
|
| 176 |
-
placeholder="from"
|
| 177 |
-
min={0}
|
| 178 |
-
precision={0}
|
| 179 |
-
className={styles.pageInputNumber}
|
| 180 |
-
/>
|
| 181 |
-
</Form.Item>
|
| 182 |
-
<Form.Item
|
| 183 |
-
{...restField}
|
| 184 |
-
name={[name, 'to']}
|
| 185 |
-
dependencies={[name, 'from']}
|
| 186 |
-
rules={[
|
| 187 |
-
{
|
| 188 |
-
required: true,
|
| 189 |
-
message:
|
| 190 |
-
'Missing end page number(excluding)',
|
| 191 |
-
},
|
| 192 |
-
({ getFieldValue }) => ({
|
| 193 |
-
validator(_, value) {
|
| 194 |
-
if (
|
| 195 |
-
!value ||
|
| 196 |
-
getFieldValue(['pages', name, 'from']) <
|
| 197 |
-
value
|
| 198 |
-
) {
|
| 199 |
-
return Promise.resolve();
|
| 200 |
-
}
|
| 201 |
-
return Promise.reject(
|
| 202 |
-
new Error(
|
| 203 |
-
'The current value must be greater than to!',
|
| 204 |
-
),
|
| 205 |
-
);
|
| 206 |
-
},
|
| 207 |
-
}),
|
| 208 |
-
]}
|
| 209 |
-
>
|
| 210 |
-
<InputNumber
|
| 211 |
-
placeholder="to"
|
| 212 |
-
min={0}
|
| 213 |
-
precision={0}
|
| 214 |
-
className={styles.pageInputNumber}
|
| 215 |
-
/>
|
| 216 |
-
</Form.Item>
|
| 217 |
-
{name > 0 && (
|
| 218 |
-
<MinusCircleOutlined
|
| 219 |
-
onClick={() => remove(name)}
|
| 220 |
-
/>
|
| 221 |
-
)}
|
| 222 |
-
</Space>
|
| 223 |
-
))}
|
| 224 |
-
<Form.Item>
|
| 225 |
-
<Button
|
| 226 |
-
type="dashed"
|
| 227 |
-
onClick={() => add()}
|
| 228 |
-
block
|
| 229 |
-
icon={<PlusOutlined />}
|
| 230 |
-
>
|
| 231 |
-
Add page
|
| 232 |
-
</Button>
|
| 233 |
-
</Form.Item>
|
| 234 |
-
</>
|
| 235 |
-
)}
|
| 236 |
-
</Form.List>
|
| 237 |
-
|
| 238 |
-
<Form.Item
|
| 239 |
-
name={['parser_config', 'task_page_size']}
|
| 240 |
-
label="Task page size"
|
| 241 |
-
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.
|
| 242 |
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.`}
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
</>
|
| 254 |
)
|
| 255 |
}
|
| 256 |
</Form.Item>
|
|
|
|
| 2 |
import { IModalManagerChildrenProps } from '@/components/modal-manager';
|
| 3 |
import { IKnowledgeFileParserConfig } from '@/interfaces/database/knowledge';
|
| 4 |
import { IChangeParserConfigRequestBody } from '@/interfaces/request/document';
|
| 5 |
+
import {
|
| 6 |
+
MinusCircleOutlined,
|
| 7 |
+
PlusOutlined,
|
| 8 |
+
QuestionCircleOutlined,
|
| 9 |
+
} from '@ant-design/icons';
|
| 10 |
import {
|
| 11 |
Button,
|
| 12 |
Divider,
|
|
|
|
| 16 |
Space,
|
| 17 |
Switch,
|
| 18 |
Tag,
|
| 19 |
+
Tooltip,
|
| 20 |
} from 'antd';
|
| 21 |
import omit from 'lodash/omit';
|
| 22 |
import React, { useEffect, useMemo } from 'react';
|
|
|
|
| 36 |
parserId: string;
|
| 37 |
parserConfig: IKnowledgeFileParserConfig;
|
| 38 |
documentType: string;
|
| 39 |
+
disabled: boolean;
|
| 40 |
}
|
| 41 |
|
| 42 |
const hidePagesChunkMethods = ['qa', 'table', 'picture', 'resume', 'one'];
|
|
|
|
| 46 |
onOk,
|
| 47 |
hideModal,
|
| 48 |
visible,
|
| 49 |
+
disabled,
|
| 50 |
documentType,
|
| 51 |
parserConfig,
|
| 52 |
}) => {
|
|
|
|
| 96 |
onOk={handleOk}
|
| 97 |
onCancel={hideModal}
|
| 98 |
afterClose={afterClose}
|
| 99 |
+
okButtonProps={{ disabled }}
|
| 100 |
>
|
| 101 |
<Space size={[0, 8]} wrap>
|
| 102 |
<div className={styles.tags}>
|
|
|
|
| 105 |
<CheckableTag
|
| 106 |
key={x.value}
|
| 107 |
checked={selectedTag === x.value}
|
| 108 |
+
onChange={(checked) => {
|
| 109 |
+
if (!disabled) {
|
| 110 |
+
handleChange(x.value, checked);
|
| 111 |
+
}
|
| 112 |
+
}}
|
| 113 |
>
|
| 114 |
{x.label}
|
| 115 |
</CheckableTag>
|
|
|
|
| 120 |
<Divider></Divider>
|
| 121 |
|
| 122 |
{
|
| 123 |
+
<Form
|
| 124 |
+
name="dynamic_form_nest_item"
|
| 125 |
+
autoComplete="off"
|
| 126 |
+
form={form}
|
| 127 |
+
disabled={disabled}
|
| 128 |
+
>
|
| 129 |
+
{showPages && (
|
| 130 |
+
<>
|
| 131 |
+
<Space>
|
| 132 |
+
<p>Page Ranges:</p>
|
| 133 |
+
<Tooltip
|
| 134 |
+
title={
|
| 135 |
+
'page ranges: Define the page ranges that need to be parsed. The pages that not included in these ranges will be ignored.'
|
| 136 |
+
}
|
| 137 |
+
>
|
| 138 |
+
<QuestionCircleOutlined
|
| 139 |
+
className={styles.questionIcon}
|
| 140 |
+
></QuestionCircleOutlined>
|
| 141 |
+
</Tooltip>
|
| 142 |
+
</Space>
|
| 143 |
+
<Form.List name="pages">
|
| 144 |
+
{(fields, { add, remove }) => (
|
| 145 |
+
<>
|
| 146 |
+
{fields.map(({ key, name, ...restField }) => (
|
| 147 |
+
<Space
|
| 148 |
+
key={key}
|
| 149 |
+
style={{
|
| 150 |
+
display: 'flex',
|
| 151 |
+
}}
|
| 152 |
+
align="baseline"
|
| 153 |
+
>
|
| 154 |
+
<Form.Item
|
| 155 |
+
{...restField}
|
| 156 |
+
name={[name, 'from']}
|
| 157 |
+
dependencies={name > 0 ? [name - 1, 'to'] : []}
|
| 158 |
+
rules={[
|
| 159 |
+
{
|
| 160 |
+
required: true,
|
| 161 |
+
message: 'Missing start page number',
|
| 162 |
+
},
|
| 163 |
+
({ getFieldValue }) => ({
|
| 164 |
+
validator(_, value) {
|
| 165 |
+
if (
|
| 166 |
+
name === 0 ||
|
| 167 |
+
!value ||
|
| 168 |
+
getFieldValue(['pages', name - 1, 'to']) <
|
| 169 |
+
value
|
| 170 |
+
) {
|
| 171 |
+
return Promise.resolve();
|
| 172 |
+
}
|
| 173 |
+
return Promise.reject(
|
| 174 |
+
new Error(
|
| 175 |
+
'The current value must be greater than the previous to!',
|
| 176 |
+
),
|
| 177 |
+
);
|
| 178 |
+
},
|
| 179 |
+
}),
|
| 180 |
+
]}
|
| 181 |
+
>
|
| 182 |
+
<InputNumber
|
| 183 |
+
placeholder="from"
|
| 184 |
+
min={0}
|
| 185 |
+
precision={0}
|
| 186 |
+
className={styles.pageInputNumber}
|
| 187 |
+
/>
|
| 188 |
+
</Form.Item>
|
| 189 |
+
<Form.Item
|
| 190 |
+
{...restField}
|
| 191 |
+
name={[name, 'to']}
|
| 192 |
+
dependencies={[name, 'from']}
|
| 193 |
+
rules={[
|
| 194 |
+
{
|
| 195 |
+
required: true,
|
| 196 |
+
message: 'Missing end page number(excluding)',
|
| 197 |
+
},
|
| 198 |
+
({ getFieldValue }) => ({
|
| 199 |
+
validator(_, value) {
|
| 200 |
+
if (
|
| 201 |
+
!value ||
|
| 202 |
+
getFieldValue(['pages', name, 'from']) < value
|
| 203 |
+
) {
|
| 204 |
+
return Promise.resolve();
|
| 205 |
+
}
|
| 206 |
+
return Promise.reject(
|
| 207 |
+
new Error(
|
| 208 |
+
'The current value must be greater than to!',
|
| 209 |
+
),
|
| 210 |
+
);
|
| 211 |
+
},
|
| 212 |
+
}),
|
| 213 |
+
]}
|
| 214 |
+
>
|
| 215 |
+
<InputNumber
|
| 216 |
+
placeholder="to"
|
| 217 |
+
min={0}
|
| 218 |
+
precision={0}
|
| 219 |
+
className={styles.pageInputNumber}
|
| 220 |
+
/>
|
| 221 |
+
</Form.Item>
|
| 222 |
+
{name > 0 && (
|
| 223 |
+
<MinusCircleOutlined onClick={() => remove(name)} />
|
| 224 |
+
)}
|
| 225 |
+
</Space>
|
| 226 |
+
))}
|
| 227 |
+
<Form.Item>
|
| 228 |
+
<Button
|
| 229 |
+
type="dashed"
|
| 230 |
+
onClick={() => add()}
|
| 231 |
+
block
|
| 232 |
+
icon={<PlusOutlined />}
|
| 233 |
+
>
|
| 234 |
+
Add page
|
| 235 |
+
</Button>
|
| 236 |
+
</Form.Item>
|
| 237 |
+
</>
|
| 238 |
+
)}
|
| 239 |
+
</Form.List>
|
| 240 |
+
</>
|
| 241 |
+
)}
|
| 242 |
{showOne && (
|
| 243 |
<Form.Item
|
| 244 |
name={['parser_config', 'layout_recognize']}
|
|
|
|
| 259 |
>
|
| 260 |
{({ getFieldValue }) =>
|
| 261 |
getFieldValue(['parser_config', 'layout_recognize']) && (
|
| 262 |
+
<Form.Item
|
| 263 |
+
name={['parser_config', 'task_page_size']}
|
| 264 |
+
label="Task page size"
|
| 265 |
+
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
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.`}
|
| 267 |
+
initialValue={12}
|
| 268 |
+
rules={[
|
| 269 |
+
{
|
| 270 |
+
required: true,
|
| 271 |
+
message: 'Please input your task page size!',
|
| 272 |
+
},
|
| 273 |
+
]}
|
| 274 |
+
>
|
| 275 |
+
<InputNumber min={1} max={128} />
|
| 276 |
+
</Form.Item>
|
|
|
|
| 277 |
)
|
| 278 |
}
|
| 279 |
</Form.Item>
|
web/src/pages/add-knowledge/components/knowledge-file/index.less
CHANGED
|
@@ -38,3 +38,10 @@
|
|
| 38 |
.pageInputNumber {
|
| 39 |
width: 220px;
|
| 40 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
.pageInputNumber {
|
| 39 |
width: 220px;
|
| 40 |
}
|
| 41 |
+
|
| 42 |
+
.questionIcon {
|
| 43 |
+
margin-inline-start: 4px;
|
| 44 |
+
color: rgba(0, 0, 0, 0.45);
|
| 45 |
+
cursor: help;
|
| 46 |
+
writing-mode: horizontal-tb;
|
| 47 |
+
}
|
web/src/pages/add-knowledge/components/knowledge-file/index.tsx
CHANGED
|
@@ -231,6 +231,7 @@ const KnowledgeFile = () => {
|
|
| 231 |
onOk={onChangeParserOk}
|
| 232 |
visible={changeParserVisible}
|
| 233 |
hideModal={hideChangeParserModal}
|
|
|
|
| 234 |
loading={changeParserLoading}
|
| 235 |
/>
|
| 236 |
<RenameModal
|
|
|
|
| 231 |
onOk={onChangeParserOk}
|
| 232 |
visible={changeParserVisible}
|
| 233 |
hideModal={hideChangeParserModal}
|
| 234 |
+
disabled={currentRecord.chunk_num > 0}
|
| 235 |
loading={changeParserLoading}
|
| 236 |
/>
|
| 237 |
<RenameModal
|