Skip to content

Commit

Permalink
feat: Add EntityTypesForm infiniflow#162 (infiniflow#1777)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?
feat: Add EntityTypesForm infiniflow#162

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
  • Loading branch information
cike8899 authored Aug 2, 2024
1 parent 4ba1ba9 commit 3a739e3
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 12 deletions.
15 changes: 13 additions & 2 deletions web/src/components/chunk-method-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import React, { useEffect, useMemo } from 'react';
import { useFetchParserListOnMount } from './hooks';

import { useTranslate } from '@/hooks/common-hooks';
import EntityTypesForm from '../entity-types-form';
import LayoutRecognize from '../layout-recognize';
import ParseConfiguration, {
showRaptorParseConfiguration,
Expand All @@ -41,7 +42,14 @@ interface IProps extends Omit<IModalManagerChildrenProps, 'showModal'> {
documentId: string;
}

const hidePagesChunkMethods = ['qa', 'table', 'picture', 'resume', 'one'];
const hidePagesChunkMethods = [
'qa',
'table',
'picture',
'resume',
'one',
'knowledge_graph',
];

const ChunkMethodModal: React.FC<IProps> = ({
documentId,
Expand Down Expand Up @@ -80,7 +88,7 @@ const ChunkMethodModal: React.FC<IProps> = ({
return (
isPdf &&
hidePagesChunkMethods
.filter((x) => x !== 'one')
.filter((x) => x !== 'one' && x !== 'knowledge_graph')
.every((x) => x !== selectedTag)
);
}, [selectedTag, isPdf]);
Expand All @@ -91,6 +99,8 @@ const ChunkMethodModal: React.FC<IProps> = ({
(x) => x === false,
);

const showEntityTypes = selectedTag === 'knowledge_graph';

const afterClose = () => {
form.resetFields();
};
Expand Down Expand Up @@ -262,6 +272,7 @@ const ChunkMethodModal: React.FC<IProps> = ({
{showRaptorParseConfiguration(selectedTag) && (
<ParseConfiguration></ParseConfiguration>
)}
{showEntityTypes && <EntityTypesForm></EntityTypesForm>}
</Form>
</Modal>
);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import React, { useEffect, useRef, useState } from 'react';
import styles from './index.less';

interface EditTagsProps {
tags: string[];
setTags: (tags: string[]) => void;
tags?: string[];
setTags?: (tags: string[]) => void;
}

const EditTag = ({ tags, setTags }: EditTagsProps) => {
Expand All @@ -24,9 +24,8 @@ const EditTag = ({ tags, setTags }: EditTagsProps) => {
}, [inputVisible]);

const handleClose = (removedTag: string) => {
const newTags = tags.filter((tag) => tag !== removedTag);
console.log(newTags);
setTags(newTags);
const newTags = tags?.filter((tag) => tag !== removedTag);
setTags?.(newTags ?? []);
};

const showInput = () => {
Expand All @@ -38,8 +37,8 @@ const EditTag = ({ tags, setTags }: EditTagsProps) => {
};

const handleInputConfirm = () => {
if (inputValue && tags.indexOf(inputValue) === -1) {
setTags([...tags, inputValue]);
if (inputValue && tags?.indexOf(inputValue) === -1) {
setTags?.([...tags, inputValue]);
}
setInputVisible(false);
setInputValue('');
Expand All @@ -64,7 +63,7 @@ const EditTag = ({ tags, setTags }: EditTagsProps) => {
);
};

const tagChild = tags.map(forMap);
const tagChild = tags?.map(forMap);

const tagPlusStyle: React.CSSProperties = {
background: token.colorBgContainer,
Expand Down
29 changes: 29 additions & 0 deletions web/src/components/entity-types-form.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useTranslate } from '@/hooks/common-hooks';
import { Form } from 'antd';
import EditTag from './edit-tag';

const initialEntityTypes = [
'organization',
'person',
'location',
'event',
'time',
];

const EntityTypesForm = () => {
const { t } = useTranslate('knowledgeConfiguration');
return (
<Form.Item
name={['parser_config', 'entity_types']}
label={t('entityTypes')}
rules={[{ required: true }]}
initialValue={initialEntityTypes}
valuePropName="tags"
trigger="setTags"
>
<EditTag></EditTag>
</Form.Item>
);
};

export default EntityTypesForm;
8 changes: 7 additions & 1 deletion web/src/components/parse-configuration/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import {
} from 'antd';
import random from 'lodash/random';

export const excludedParseMethods = ['table', 'resume', 'one', 'picture'];
export const excludedParseMethods = [
'table',
'resume',
'one',
'picture',
'knowledge_graph',
];

export const showRaptorParseConfiguration = (parserId: string) => {
return !excludedParseMethods.includes(parserId);
Expand Down
1 change: 1 addition & 0 deletions web/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ The above is the content you need to summarize.`,
maxClusterMessage: 'Max cluster is required',
randomSeed: 'Random seed',
randomSeedMessage: 'Random seed is required',
entityTypes: 'Entity types',
},
chunk: {
chunk: 'Chunk',
Expand Down
1 change: 1 addition & 0 deletions web/src/locales/zh-traditional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ export default {
maxTokenTip: '用於匯總的最大token數。',
thresholdTip: '閾值越大,聚類越少。',
maxClusterTip: '最大聚類數。',
entityTypes: '實體類型',
},
chunk: {
chunk: '解析塊',
Expand Down
1 change: 1 addition & 0 deletions web/src/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ export default {
maxTokenTip: '用于汇总的最大token数。',
thresholdTip: '阈值越大,聚类越少。',
maxClusterTip: '最大聚类数。',
entityTypes: '实体类型',
},
chunk: {
chunk: '解析块',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import EditTag from '@/components/edit-tag';
import { useFetchChunk } from '@/hooks/chunk-hooks';
import { IModalProps } from '@/interfaces/common';
import { DeleteOutlined } from '@ant-design/icons';
import { Checkbox, Divider, Form, Input, Modal, Space } from 'antd';
import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useDeleteChunkByIds } from '../../hooks';
import EditTag from '../edit-tag';

type FieldType = {
content?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
useSubmitKnowledgeConfiguration,
} from './hooks';

import EntityTypesForm from '@/components/entity-types-form';
import LayoutRecognize from '@/components/layout-recognize';
import MaxTokenNumber from '@/components/max-token-number';
import ParseConfiguration, {
Expand Down Expand Up @@ -98,6 +99,7 @@ const ConfigurationForm = ({ form }: { form: FormInstance }) => {
))}
</Select>
</Form.Item>
<EntityTypesForm></EntityTypesForm>
<Form.Item noStyle dependencies={['parser_id']}>
{({ getFieldValue }) => {
const parserId = getFieldValue('parser_id');
Expand Down

0 comments on commit 3a739e3

Please sign in to comment.