balibabu
commited on
Commit
·
92890f8
1
Parent(s):
de35307
feat: Add EntityTypesForm #162 (#1777)
Browse files### What problem does this PR solve?
feat: Add EntityTypesForm #162
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
- web/src/components/chunk-method-modal/index.tsx +13 -2
- web/src/{pages/add-knowledge/components/knowledge-chunk/components → components}/edit-tag/index.less +0 -0
- web/src/{pages/add-knowledge/components/knowledge-chunk/components → components}/edit-tag/index.tsx +7 -8
- web/src/components/entity-types-form.tsx +29 -0
- web/src/components/parse-configuration/index.tsx +7 -1
- web/src/locales/en.ts +1 -0
- web/src/locales/zh-traditional.ts +1 -0
- web/src/locales/zh.ts +1 -0
- web/src/pages/add-knowledge/components/knowledge-chunk/components/chunk-creating-modal/index.tsx +1 -1
- web/src/pages/add-knowledge/components/knowledge-setting/configuration.tsx +2 -0
web/src/components/chunk-method-modal/index.tsx
CHANGED
|
@@ -22,6 +22,7 @@ import React, { useEffect, useMemo } from 'react';
|
|
| 22 |
import { useFetchParserListOnMount } from './hooks';
|
| 23 |
|
| 24 |
import { useTranslate } from '@/hooks/common-hooks';
|
|
|
|
| 25 |
import LayoutRecognize from '../layout-recognize';
|
| 26 |
import ParseConfiguration, {
|
| 27 |
showRaptorParseConfiguration,
|
|
@@ -41,7 +42,14 @@ interface IProps extends Omit<IModalManagerChildrenProps, 'showModal'> {
|
|
| 41 |
documentId: string;
|
| 42 |
}
|
| 43 |
|
| 44 |
-
const hidePagesChunkMethods = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
const ChunkMethodModal: React.FC<IProps> = ({
|
| 47 |
documentId,
|
|
@@ -80,7 +88,7 @@ const ChunkMethodModal: React.FC<IProps> = ({
|
|
| 80 |
return (
|
| 81 |
isPdf &&
|
| 82 |
hidePagesChunkMethods
|
| 83 |
-
.filter((x) => x !== 'one')
|
| 84 |
.every((x) => x !== selectedTag)
|
| 85 |
);
|
| 86 |
}, [selectedTag, isPdf]);
|
|
@@ -91,6 +99,8 @@ const ChunkMethodModal: React.FC<IProps> = ({
|
|
| 91 |
(x) => x === false,
|
| 92 |
);
|
| 93 |
|
|
|
|
|
|
|
| 94 |
const afterClose = () => {
|
| 95 |
form.resetFields();
|
| 96 |
};
|
|
@@ -262,6 +272,7 @@ const ChunkMethodModal: React.FC<IProps> = ({
|
|
| 262 |
{showRaptorParseConfiguration(selectedTag) && (
|
| 263 |
<ParseConfiguration></ParseConfiguration>
|
| 264 |
)}
|
|
|
|
| 265 |
</Form>
|
| 266 |
</Modal>
|
| 267 |
);
|
|
|
|
| 22 |
import { useFetchParserListOnMount } from './hooks';
|
| 23 |
|
| 24 |
import { useTranslate } from '@/hooks/common-hooks';
|
| 25 |
+
import EntityTypesForm from '../entity-types-form';
|
| 26 |
import LayoutRecognize from '../layout-recognize';
|
| 27 |
import ParseConfiguration, {
|
| 28 |
showRaptorParseConfiguration,
|
|
|
|
| 42 |
documentId: string;
|
| 43 |
}
|
| 44 |
|
| 45 |
+
const hidePagesChunkMethods = [
|
| 46 |
+
'qa',
|
| 47 |
+
'table',
|
| 48 |
+
'picture',
|
| 49 |
+
'resume',
|
| 50 |
+
'one',
|
| 51 |
+
'knowledge_graph',
|
| 52 |
+
];
|
| 53 |
|
| 54 |
const ChunkMethodModal: React.FC<IProps> = ({
|
| 55 |
documentId,
|
|
|
|
| 88 |
return (
|
| 89 |
isPdf &&
|
| 90 |
hidePagesChunkMethods
|
| 91 |
+
.filter((x) => x !== 'one' && x !== 'knowledge_graph')
|
| 92 |
.every((x) => x !== selectedTag)
|
| 93 |
);
|
| 94 |
}, [selectedTag, isPdf]);
|
|
|
|
| 99 |
(x) => x === false,
|
| 100 |
);
|
| 101 |
|
| 102 |
+
const showEntityTypes = selectedTag === 'knowledge_graph';
|
| 103 |
+
|
| 104 |
const afterClose = () => {
|
| 105 |
form.resetFields();
|
| 106 |
};
|
|
|
|
| 272 |
{showRaptorParseConfiguration(selectedTag) && (
|
| 273 |
<ParseConfiguration></ParseConfiguration>
|
| 274 |
)}
|
| 275 |
+
{showEntityTypes && <EntityTypesForm></EntityTypesForm>}
|
| 276 |
</Form>
|
| 277 |
</Modal>
|
| 278 |
);
|
web/src/{pages/add-knowledge/components/knowledge-chunk/components → components}/edit-tag/index.less
RENAMED
|
File without changes
|
web/src/{pages/add-knowledge/components/knowledge-chunk/components → components}/edit-tag/index.tsx
RENAMED
|
@@ -7,8 +7,8 @@ import React, { useEffect, useRef, useState } from 'react';
|
|
| 7 |
import styles from './index.less';
|
| 8 |
|
| 9 |
interface EditTagsProps {
|
| 10 |
-
tags
|
| 11 |
-
setTags
|
| 12 |
}
|
| 13 |
|
| 14 |
const EditTag = ({ tags, setTags }: EditTagsProps) => {
|
|
@@ -24,9 +24,8 @@ const EditTag = ({ tags, setTags }: EditTagsProps) => {
|
|
| 24 |
}, [inputVisible]);
|
| 25 |
|
| 26 |
const handleClose = (removedTag: string) => {
|
| 27 |
-
const newTags = tags
|
| 28 |
-
|
| 29 |
-
setTags(newTags);
|
| 30 |
};
|
| 31 |
|
| 32 |
const showInput = () => {
|
|
@@ -38,8 +37,8 @@ const EditTag = ({ tags, setTags }: EditTagsProps) => {
|
|
| 38 |
};
|
| 39 |
|
| 40 |
const handleInputConfirm = () => {
|
| 41 |
-
if (inputValue && tags
|
| 42 |
-
setTags([...tags, inputValue]);
|
| 43 |
}
|
| 44 |
setInputVisible(false);
|
| 45 |
setInputValue('');
|
|
@@ -64,7 +63,7 @@ const EditTag = ({ tags, setTags }: EditTagsProps) => {
|
|
| 64 |
);
|
| 65 |
};
|
| 66 |
|
| 67 |
-
const tagChild = tags
|
| 68 |
|
| 69 |
const tagPlusStyle: React.CSSProperties = {
|
| 70 |
background: token.colorBgContainer,
|
|
|
|
| 7 |
import styles from './index.less';
|
| 8 |
|
| 9 |
interface EditTagsProps {
|
| 10 |
+
tags?: string[];
|
| 11 |
+
setTags?: (tags: string[]) => void;
|
| 12 |
}
|
| 13 |
|
| 14 |
const EditTag = ({ tags, setTags }: EditTagsProps) => {
|
|
|
|
| 24 |
}, [inputVisible]);
|
| 25 |
|
| 26 |
const handleClose = (removedTag: string) => {
|
| 27 |
+
const newTags = tags?.filter((tag) => tag !== removedTag);
|
| 28 |
+
setTags?.(newTags ?? []);
|
|
|
|
| 29 |
};
|
| 30 |
|
| 31 |
const showInput = () => {
|
|
|
|
| 37 |
};
|
| 38 |
|
| 39 |
const handleInputConfirm = () => {
|
| 40 |
+
if (inputValue && tags?.indexOf(inputValue) === -1) {
|
| 41 |
+
setTags?.([...tags, inputValue]);
|
| 42 |
}
|
| 43 |
setInputVisible(false);
|
| 44 |
setInputValue('');
|
|
|
|
| 63 |
);
|
| 64 |
};
|
| 65 |
|
| 66 |
+
const tagChild = tags?.map(forMap);
|
| 67 |
|
| 68 |
const tagPlusStyle: React.CSSProperties = {
|
| 69 |
background: token.colorBgContainer,
|
web/src/components/entity-types-form.tsx
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useTranslate } from '@/hooks/common-hooks';
|
| 2 |
+
import { Form } from 'antd';
|
| 3 |
+
import EditTag from './edit-tag';
|
| 4 |
+
|
| 5 |
+
const initialEntityTypes = [
|
| 6 |
+
'organization',
|
| 7 |
+
'person',
|
| 8 |
+
'location',
|
| 9 |
+
'event',
|
| 10 |
+
'time',
|
| 11 |
+
];
|
| 12 |
+
|
| 13 |
+
const EntityTypesForm = () => {
|
| 14 |
+
const { t } = useTranslate('knowledgeConfiguration');
|
| 15 |
+
return (
|
| 16 |
+
<Form.Item
|
| 17 |
+
name={['parser_config', 'entity_types']}
|
| 18 |
+
label={t('entityTypes')}
|
| 19 |
+
rules={[{ required: true }]}
|
| 20 |
+
initialValue={initialEntityTypes}
|
| 21 |
+
valuePropName="tags"
|
| 22 |
+
trigger="setTags"
|
| 23 |
+
>
|
| 24 |
+
<EditTag></EditTag>
|
| 25 |
+
</Form.Item>
|
| 26 |
+
);
|
| 27 |
+
};
|
| 28 |
+
|
| 29 |
+
export default EntityTypesForm;
|
web/src/components/parse-configuration/index.tsx
CHANGED
|
@@ -12,7 +12,13 @@ import {
|
|
| 12 |
} from 'antd';
|
| 13 |
import random from 'lodash/random';
|
| 14 |
|
| 15 |
-
export const excludedParseMethods = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
export const showRaptorParseConfiguration = (parserId: string) => {
|
| 18 |
return !excludedParseMethods.includes(parserId);
|
|
|
|
| 12 |
} from 'antd';
|
| 13 |
import random from 'lodash/random';
|
| 14 |
|
| 15 |
+
export const excludedParseMethods = [
|
| 16 |
+
'table',
|
| 17 |
+
'resume',
|
| 18 |
+
'one',
|
| 19 |
+
'picture',
|
| 20 |
+
'knowledge_graph',
|
| 21 |
+
];
|
| 22 |
|
| 23 |
export const showRaptorParseConfiguration = (parserId: string) => {
|
| 24 |
return !excludedParseMethods.includes(parserId);
|
web/src/locales/en.ts
CHANGED
|
@@ -289,6 +289,7 @@ The above is the content you need to summarize.`,
|
|
| 289 |
maxClusterMessage: 'Max cluster is required',
|
| 290 |
randomSeed: 'Random seed',
|
| 291 |
randomSeedMessage: 'Random seed is required',
|
|
|
|
| 292 |
},
|
| 293 |
chunk: {
|
| 294 |
chunk: 'Chunk',
|
|
|
|
| 289 |
maxClusterMessage: 'Max cluster is required',
|
| 290 |
randomSeed: 'Random seed',
|
| 291 |
randomSeedMessage: 'Random seed is required',
|
| 292 |
+
entityTypes: 'Entity types',
|
| 293 |
},
|
| 294 |
chunk: {
|
| 295 |
chunk: 'Chunk',
|
web/src/locales/zh-traditional.ts
CHANGED
|
@@ -261,6 +261,7 @@ export default {
|
|
| 261 |
maxTokenTip: '用於匯總的最大token數。',
|
| 262 |
thresholdTip: '閾值越大,聚類越少。',
|
| 263 |
maxClusterTip: '最大聚類數。',
|
|
|
|
| 264 |
},
|
| 265 |
chunk: {
|
| 266 |
chunk: '解析塊',
|
|
|
|
| 261 |
maxTokenTip: '用於匯總的最大token數。',
|
| 262 |
thresholdTip: '閾值越大,聚類越少。',
|
| 263 |
maxClusterTip: '最大聚類數。',
|
| 264 |
+
entityTypes: '實體類型',
|
| 265 |
},
|
| 266 |
chunk: {
|
| 267 |
chunk: '解析塊',
|
web/src/locales/zh.ts
CHANGED
|
@@ -278,6 +278,7 @@ export default {
|
|
| 278 |
maxTokenTip: '用于汇总的最大token数。',
|
| 279 |
thresholdTip: '阈值越大,聚类越少。',
|
| 280 |
maxClusterTip: '最大聚类数。',
|
|
|
|
| 281 |
},
|
| 282 |
chunk: {
|
| 283 |
chunk: '解析块',
|
|
|
|
| 278 |
maxTokenTip: '用于汇总的最大token数。',
|
| 279 |
thresholdTip: '阈值越大,聚类越少。',
|
| 280 |
maxClusterTip: '最大聚类数。',
|
| 281 |
+
entityTypes: '实体类型',
|
| 282 |
},
|
| 283 |
chunk: {
|
| 284 |
chunk: '解析块',
|
web/src/pages/add-knowledge/components/knowledge-chunk/components/chunk-creating-modal/index.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import { useFetchChunk } from '@/hooks/chunk-hooks';
|
| 2 |
import { IModalProps } from '@/interfaces/common';
|
| 3 |
import { DeleteOutlined } from '@ant-design/icons';
|
|
@@ -5,7 +6,6 @@ import { Checkbox, Divider, Form, Input, Modal, Space } from 'antd';
|
|
| 5 |
import React, { useEffect, useState } from 'react';
|
| 6 |
import { useTranslation } from 'react-i18next';
|
| 7 |
import { useDeleteChunkByIds } from '../../hooks';
|
| 8 |
-
import EditTag from '../edit-tag';
|
| 9 |
|
| 10 |
type FieldType = {
|
| 11 |
content?: string;
|
|
|
|
| 1 |
+
import EditTag from '@/components/edit-tag';
|
| 2 |
import { useFetchChunk } from '@/hooks/chunk-hooks';
|
| 3 |
import { IModalProps } from '@/interfaces/common';
|
| 4 |
import { DeleteOutlined } from '@ant-design/icons';
|
|
|
|
| 6 |
import React, { useEffect, useState } from 'react';
|
| 7 |
import { useTranslation } from 'react-i18next';
|
| 8 |
import { useDeleteChunkByIds } from '../../hooks';
|
|
|
|
| 9 |
|
| 10 |
type FieldType = {
|
| 11 |
content?: string;
|
web/src/pages/add-knowledge/components/knowledge-setting/configuration.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
| 6 |
useSubmitKnowledgeConfiguration,
|
| 7 |
} from './hooks';
|
| 8 |
|
|
|
|
| 9 |
import LayoutRecognize from '@/components/layout-recognize';
|
| 10 |
import MaxTokenNumber from '@/components/max-token-number';
|
| 11 |
import ParseConfiguration, {
|
|
@@ -98,6 +99,7 @@ const ConfigurationForm = ({ form }: { form: FormInstance }) => {
|
|
| 98 |
))}
|
| 99 |
</Select>
|
| 100 |
</Form.Item>
|
|
|
|
| 101 |
<Form.Item noStyle dependencies={['parser_id']}>
|
| 102 |
{({ getFieldValue }) => {
|
| 103 |
const parserId = getFieldValue('parser_id');
|
|
|
|
| 6 |
useSubmitKnowledgeConfiguration,
|
| 7 |
} from './hooks';
|
| 8 |
|
| 9 |
+
import EntityTypesForm from '@/components/entity-types-form';
|
| 10 |
import LayoutRecognize from '@/components/layout-recognize';
|
| 11 |
import MaxTokenNumber from '@/components/max-token-number';
|
| 12 |
import ParseConfiguration, {
|
|
|
|
| 99 |
))}
|
| 100 |
</Select>
|
| 101 |
</Form.Item>
|
| 102 |
+
<EntityTypesForm></EntityTypesForm>
|
| 103 |
<Form.Item noStyle dependencies={['parser_id']}>
|
| 104 |
{({ getFieldValue }) => {
|
| 105 |
const parserId = getFieldValue('parser_id');
|