balibabu commited on
Commit
53be70c
·
1 Parent(s): 1a156e6

feat: transform the parser's data structure and add Image to TestingResult (#63)

Browse files

* feat: add Image to TestingResult

* feat: transform the parser's data structure

web/src/components/image.tsx ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { api_host } from '@/utils/api';
2
+
3
+ interface IImage {
4
+ id: string;
5
+ className: string;
6
+ }
7
+
8
+ const Image = ({ id, className, ...props }: IImage) => {
9
+ return (
10
+ <img
11
+ {...props}
12
+ src={`${api_host}/document/image/${id}`}
13
+ alt=""
14
+ className={className}
15
+ />
16
+ );
17
+ };
18
+
19
+ export default Image;
web/src/pages/add-knowledge/components/knowledge-chunk/components/chunk-card/index.tsx CHANGED
@@ -1,7 +1,7 @@
 
1
  import { IChunk } from '@/interfaces/database/knowledge';
2
  import { api_host } from '@/utils/api';
3
  import { Card, Checkbox, CheckboxProps, Flex, Popover, Switch } from 'antd';
4
-
5
  import { useState } from 'react';
6
  import styles from './index.less';
7
 
@@ -13,22 +13,6 @@ interface IProps {
13
  handleCheckboxClick: (chunkId: string, checked: boolean) => void;
14
  }
15
 
16
- interface IImage {
17
- id: string;
18
- className: string;
19
- }
20
- // Pass onMouseEnter and onMouseLeave to img tag using props
21
- const Image = ({ id, className, ...props }: IImage) => {
22
- return (
23
- <img
24
- {...props}
25
- src={`${api_host}/document/image/${id}`}
26
- alt=""
27
- className={className}
28
- />
29
- );
30
- };
31
-
32
  const ChunkCard = ({
33
  item,
34
  checked,
 
1
+ import Image from '@/components/image';
2
  import { IChunk } from '@/interfaces/database/knowledge';
3
  import { api_host } from '@/utils/api';
4
  import { Card, Checkbox, CheckboxProps, Flex, Popover, Switch } from 'antd';
 
5
  import { useState } from 'react';
6
  import styles from './index.less';
7
 
 
13
  handleCheckboxClick: (chunkId: string, checked: boolean) => void;
14
  }
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  const ChunkCard = ({
17
  item,
18
  checked,
web/src/pages/add-knowledge/components/knowledge-dataset/knowledge-upload-file/index.tsx CHANGED
@@ -28,7 +28,7 @@ import {
28
  UploadProps,
29
  } from 'antd';
30
  import classNames from 'classnames';
31
- import { ReactElement, useEffect, useRef, useState } from 'react';
32
  import { Nullable } from 'typings';
33
  import { Link, useDispatch, useNavigate, useSelector } from 'umi';
34
 
@@ -63,6 +63,24 @@ const UploaderItem = ({
63
 
64
  const documentId = file?.response?.id;
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  const onChange = (e: RadioChangeEvent) => {
67
  const val = e.target.value;
68
  setValue(val);
@@ -72,12 +90,12 @@ const UploaderItem = ({
72
  const content = (
73
  <Radio.Group onChange={onChange} value={value}>
74
  <Space direction="vertical">
75
- {parserArray.map(
76
  (
77
  x, // value is lowercase, key is uppercase
78
  ) => (
79
- <Radio value={x.toLowerCase()} key={x}>
80
- {x}
81
  </Radio>
82
  ),
83
  )}
@@ -92,17 +110,6 @@ const UploaderItem = ({
92
  }
93
  };
94
 
95
- const saveParser = (parserId: string) => {
96
- dispatch({
97
- type: 'kFModel/document_change_parser',
98
- payload: {
99
- parser_id: parserId,
100
- doc_id: documentId,
101
- parser_config: parserConfig,
102
- },
103
- });
104
- };
105
-
106
  useEffect(() => {
107
  setValue(defaultParserId);
108
  }, [defaultParserId]);
 
28
  UploadProps,
29
  } from 'antd';
30
  import classNames from 'classnames';
31
+ import { ReactElement, useEffect, useMemo, useRef, useState } from 'react';
32
  import { Nullable } from 'typings';
33
  import { Link, useDispatch, useNavigate, useSelector } from 'umi';
34
 
 
63
 
64
  const documentId = file?.response?.id;
65
 
66
+ const parserList = useMemo(() => {
67
+ return parserArray.map((x) => {
68
+ const arr = x.split(':');
69
+ return { value: arr[0], label: arr[1] };
70
+ });
71
+ }, [parserArray]);
72
+
73
+ const saveParser = (parserId: string) => {
74
+ dispatch({
75
+ type: 'kFModel/document_change_parser',
76
+ payload: {
77
+ parser_id: parserId,
78
+ doc_id: documentId,
79
+ parser_config: parserConfig,
80
+ },
81
+ });
82
+ };
83
+
84
  const onChange = (e: RadioChangeEvent) => {
85
  const val = e.target.value;
86
  setValue(val);
 
90
  const content = (
91
  <Radio.Group onChange={onChange} value={value}>
92
  <Space direction="vertical">
93
+ {parserList.map(
94
  (
95
  x, // value is lowercase, key is uppercase
96
  ) => (
97
+ <Radio value={x.value} key={x.value}>
98
+ {x.label}
99
  </Radio>
100
  ),
101
  )}
 
110
  }
111
  };
112
 
 
 
 
 
 
 
 
 
 
 
 
113
  useEffect(() => {
114
  setValue(defaultParserId);
115
  }, [defaultParserId]);
web/src/pages/add-knowledge/components/knowledge-testing/testing-result/index.less CHANGED
@@ -33,4 +33,11 @@
33
  font-size: 12px;
34
  font-weight: 500;
35
  }
 
 
 
 
 
 
 
36
  }
 
33
  font-size: 12px;
34
  font-weight: 500;
35
  }
36
+ .image {
37
+ width: 100px;
38
+ }
39
+ .imagePreview {
40
+ display: block;
41
+ width: 260px;
42
+ }
43
  }
web/src/pages/add-knowledge/components/knowledge-testing/testing-result/index.tsx CHANGED
@@ -1,6 +1,15 @@
1
  import { ReactComponent as SelectedFilesCollapseIcon } from '@/assets/svg/selected-files-collapse.svg';
 
2
  import { ITestingChunk } from '@/interfaces/database/knowledge';
3
- import { Card, Collapse, Flex, Pagination, PaginationProps, Space } from 'antd';
 
 
 
 
 
 
 
 
4
  import { useDispatch, useSelector } from 'umi';
5
  import { TestingModelState } from '../model';
6
  import styles from './index.less';
@@ -92,7 +101,22 @@ const TestingResult = ({ handleTesting }: IProps) => {
92
  >
93
  {chunks.map((x) => (
94
  <Card key={x.chunk_id} title={<ChunkTitle item={x}></ChunkTitle>}>
95
- <div>{x.content_with_weight}</div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  </Card>
97
  ))}
98
  </Flex>
 
1
  import { ReactComponent as SelectedFilesCollapseIcon } from '@/assets/svg/selected-files-collapse.svg';
2
+ import Image from '@/components/image';
3
  import { ITestingChunk } from '@/interfaces/database/knowledge';
4
+ import {
5
+ Card,
6
+ Collapse,
7
+ Flex,
8
+ Pagination,
9
+ PaginationProps,
10
+ Popover,
11
+ Space,
12
+ } from 'antd';
13
  import { useDispatch, useSelector } from 'umi';
14
  import { TestingModelState } from '../model';
15
  import styles from './index.less';
 
101
  >
102
  {chunks.map((x) => (
103
  <Card key={x.chunk_id} title={<ChunkTitle item={x}></ChunkTitle>}>
104
+ <Flex gap={'middle'}>
105
+ {x.img_id && (
106
+ <Popover
107
+ placement="topRight"
108
+ content={
109
+ <Image
110
+ id={x.img_id}
111
+ className={styles.imagePreview}
112
+ ></Image>
113
+ }
114
+ >
115
+ <Image id={x.img_id} className={styles.image}></Image>
116
+ </Popover>
117
+ )}
118
+ <div>{x.content_with_weight}</div>
119
+ </Flex>
120
  </Card>
121
  ))}
122
  </Flex>