balibabu
commited on
Commit
·
e76f8aa
1
Parent(s):
1260a60
Feat: Display tag word cloud on recall test page #4368 (#4438)
Browse files### What problem does this PR solve?
Feat: Display tag word cloud on recall test page #4368
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
- web/src/hooks/knowledge-hooks.ts +1 -2
- web/src/interfaces/database/knowledge.ts +1 -0
- web/src/pages/add-knowledge/components/knowledge-setting/tag-word-cloud.tsx +1 -1
- web/src/pages/add-knowledge/components/knowledge-testing/testing-control/index.tsx +3 -1
- web/src/pages/add-knowledge/components/knowledge-testing/testing-control/label-word-cloud.tsx +59 -0
web/src/hooks/knowledge-hooks.ts
CHANGED
|
@@ -218,9 +218,8 @@ export const useTestChunkRetrieval = (): ResponsePostType<ITestingResult> & {
|
|
| 218 |
if (data.code === 0) {
|
| 219 |
const res = data.data;
|
| 220 |
return {
|
| 221 |
-
|
| 222 |
documents: res.doc_aggs,
|
| 223 |
-
total: res.total,
|
| 224 |
};
|
| 225 |
}
|
| 226 |
return (
|
|
|
|
| 218 |
if (data.code === 0) {
|
| 219 |
const res = data.data;
|
| 220 |
return {
|
| 221 |
+
...res,
|
| 222 |
documents: res.doc_aggs,
|
|
|
|
| 223 |
};
|
| 224 |
}
|
| 225 |
return (
|
web/src/interfaces/database/knowledge.ts
CHANGED
|
@@ -132,6 +132,7 @@ export interface ITestingResult {
|
|
| 132 |
chunks: ITestingChunk[];
|
| 133 |
documents: ITestingDocument[];
|
| 134 |
total: number;
|
|
|
|
| 135 |
}
|
| 136 |
|
| 137 |
export type IRenameTag = { fromTag: string; toTag: string };
|
|
|
|
| 132 |
chunks: ITestingChunk[];
|
| 133 |
documents: ITestingDocument[];
|
| 134 |
total: number;
|
| 135 |
+
labels?: Record<string, number>;
|
| 136 |
}
|
| 137 |
|
| 138 |
export type IRenameTag = { fromTag: string; toTag: string };
|
web/src/pages/add-knowledge/components/knowledge-setting/tag-word-cloud.tsx
CHANGED
|
@@ -26,7 +26,7 @@ export function TagWordCloud() {
|
|
| 26 |
type: 'wordCloud',
|
| 27 |
autoFit: true,
|
| 28 |
layout: {
|
| 29 |
-
fontSize: [
|
| 30 |
// fontSize: (d: any) => {
|
| 31 |
// if (d.value) {
|
| 32 |
// return (d.value / sumValue) * 100 * (length / 10);
|
|
|
|
| 26 |
type: 'wordCloud',
|
| 27 |
autoFit: true,
|
| 28 |
layout: {
|
| 29 |
+
fontSize: [10, 50],
|
| 30 |
// fontSize: (d: any) => {
|
| 31 |
// if (d.value) {
|
| 32 |
// return (d.value / sumValue) * 100 * (length / 10);
|
web/src/pages/add-knowledge/components/knowledge-testing/testing-control/index.tsx
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
import Rerank from '@/components/rerank';
|
| 2 |
import SimilaritySlider from '@/components/similarity-slider';
|
| 3 |
import { useTranslate } from '@/hooks/common-hooks';
|
|
|
|
| 4 |
import { Button, Card, Divider, Flex, Form, Input } from 'antd';
|
| 5 |
import { FormInstance } from 'antd/lib';
|
|
|
|
| 6 |
|
| 7 |
-
import { useChunkIsTesting } from '@/hooks/knowledge-hooks';
|
| 8 |
import styles from './index.less';
|
| 9 |
|
| 10 |
type FieldType = {
|
|
@@ -58,6 +59,7 @@ const TestingControl = ({ form, handleTesting }: IProps) => {
|
|
| 58 |
</Card>
|
| 59 |
</Form>
|
| 60 |
</section>
|
|
|
|
| 61 |
{/* <section>
|
| 62 |
<div className={styles.historyTitle}>
|
| 63 |
<Space size={'middle'}>
|
|
|
|
| 1 |
import Rerank from '@/components/rerank';
|
| 2 |
import SimilaritySlider from '@/components/similarity-slider';
|
| 3 |
import { useTranslate } from '@/hooks/common-hooks';
|
| 4 |
+
import { useChunkIsTesting } from '@/hooks/knowledge-hooks';
|
| 5 |
import { Button, Card, Divider, Flex, Form, Input } from 'antd';
|
| 6 |
import { FormInstance } from 'antd/lib';
|
| 7 |
+
import { LabelWordCloud } from './label-word-cloud';
|
| 8 |
|
|
|
|
| 9 |
import styles from './index.less';
|
| 10 |
|
| 11 |
type FieldType = {
|
|
|
|
| 59 |
</Card>
|
| 60 |
</Form>
|
| 61 |
</section>
|
| 62 |
+
<LabelWordCloud></LabelWordCloud>
|
| 63 |
{/* <section>
|
| 64 |
<div className={styles.historyTitle}>
|
| 65 |
<Space size={'middle'}>
|
web/src/pages/add-knowledge/components/knowledge-testing/testing-control/label-word-cloud.tsx
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useSelectTestingResult } from '@/hooks/knowledge-hooks';
|
| 2 |
+
import { Chart } from '@antv/g2';
|
| 3 |
+
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
| 4 |
+
|
| 5 |
+
export function LabelWordCloud() {
|
| 6 |
+
const domRef = useRef<HTMLDivElement>(null);
|
| 7 |
+
let chartRef = useRef<Chart>();
|
| 8 |
+
const { labels } = useSelectTestingResult();
|
| 9 |
+
|
| 10 |
+
const list = useMemo(() => {
|
| 11 |
+
if (!labels) {
|
| 12 |
+
return [];
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
return Object.keys(labels).reduce<
|
| 16 |
+
Array<{ text: string; name: string; value: number }>
|
| 17 |
+
>((pre, cur) => {
|
| 18 |
+
pre.push({ name: cur, text: cur, value: labels[cur] });
|
| 19 |
+
|
| 20 |
+
return pre;
|
| 21 |
+
}, []);
|
| 22 |
+
}, [labels]);
|
| 23 |
+
|
| 24 |
+
const renderWordCloud = useCallback(() => {
|
| 25 |
+
if (domRef.current && list.length) {
|
| 26 |
+
chartRef.current = new Chart({ container: domRef.current });
|
| 27 |
+
|
| 28 |
+
chartRef.current.options({
|
| 29 |
+
type: 'wordCloud',
|
| 30 |
+
autoFit: true,
|
| 31 |
+
layout: {
|
| 32 |
+
fontSize: [6, 15],
|
| 33 |
+
},
|
| 34 |
+
data: {
|
| 35 |
+
type: 'inline',
|
| 36 |
+
value: list,
|
| 37 |
+
},
|
| 38 |
+
encode: { color: 'text' },
|
| 39 |
+
legend: false,
|
| 40 |
+
tooltip: {
|
| 41 |
+
title: 'name', // title
|
| 42 |
+
items: ['value'], // data item
|
| 43 |
+
},
|
| 44 |
+
});
|
| 45 |
+
|
| 46 |
+
chartRef.current.render();
|
| 47 |
+
}
|
| 48 |
+
}, [list]);
|
| 49 |
+
|
| 50 |
+
useEffect(() => {
|
| 51 |
+
renderWordCloud();
|
| 52 |
+
|
| 53 |
+
return () => {
|
| 54 |
+
chartRef.current?.destroy();
|
| 55 |
+
};
|
| 56 |
+
}, [renderWordCloud]);
|
| 57 |
+
|
| 58 |
+
return <div ref={domRef} className="w-full h-[13vh]"></div>;
|
| 59 |
+
}
|