From 3f9acc702964aaf94dc42139936acd45491922ff Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 16 Dec 2024 15:51:47 +0800 Subject: [PATCH 1/3] feat: hit testing support external --- .../datasets/hit-testing/components/result-item.tsx | 7 +++++-- web/app/components/datasets/hit-testing/index.tsx | 8 ++++---- web/models/datasets.ts | 1 + 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/web/app/components/datasets/hit-testing/components/result-item.tsx b/web/app/components/datasets/hit-testing/components/result-item.tsx index 5376e095d9..c18becd825 100644 --- a/web/app/components/datasets/hit-testing/components/result-item.tsx +++ b/web/app/components/datasets/hit-testing/components/result-item.tsx @@ -17,15 +17,18 @@ import Tag from '@/app/components/datasets/documents/detail/completed/common/tag const i18nPrefix = 'datasetHitTesting' type Props = { + isExternal: boolean payload: HitTesting } const ResultItem: FC = ({ + isExternal, payload, }) => { const { t } = useTranslation() - const { segment, score, child_chunks } = payload - const { position, word_count, content, keywords, document } = segment + const { segment, content: externalContent, score, child_chunks } = payload + const data = isExternal ? externalContent : segment + const { position, word_count, content, keywords, document } = data const isParentChildRetrieval = !!(child_chunks && child_chunks.length > 0) const extension = document.name.split('.').slice(-1)[0] as FileAppearanceTypeEnum const [isFold, { diff --git a/web/app/components/datasets/hit-testing/index.tsx b/web/app/components/datasets/hit-testing/index.tsx index 2a0a4aeb8a..969768f2c0 100644 --- a/web/app/components/datasets/hit-testing/index.tsx +++ b/web/app/components/datasets/hit-testing/index.tsx @@ -9,13 +9,12 @@ import { useContext } from 'use-context-selector' import SegmentCard from '../documents/detail/completed/SegmentCard' import Textarea from './textarea' import s from './style.module.css' -import HitDetail from './hit-detail' +// import HitDetail from './hit-detail' import ModifyRetrievalModal from './modify-retrieval-modal' import ResultItem from './components/result-item' import cn from '@/utils/classnames' import type { ExternalKnowledgeBaseHitTestingResponse, ExternalKnowledgeBaseHitTesting as ExternalKnowledgeBaseHitTestingType, HitTestingResponse, HitTesting as HitTestingType } from '@/models/datasets' import Loading from '@/app/components/base/loading' -import Modal from '@/app/components/base/modal' import Drawer from '@/app/components/base/drawer' import Pagination from '@/app/components/base/pagination' import FloatRightContainer from '@/app/components/base/float-right-container' @@ -82,6 +81,7 @@ const HitTesting: FC = ({ datasetId }: Props) => { ))} @@ -194,7 +194,7 @@ const HitTesting: FC = ({ datasetId }: Props) => { } - { @@ -216,7 +216,7 @@ const HitTesting: FC = ({ datasetId }: Props) => { }} /> )} - + */} setIsShowModifyRetrievalModal(false)} footer={null} mask={isMobile} panelClassname='mt-16 mx-2 sm:mr-2 mb-3 !p-0 !max-w-[640px] rounded-xl'> Date: Mon, 16 Dec 2024 15:56:16 +0800 Subject: [PATCH 2/3] chore: retrieval test text --- web/app/components/datasets/hit-testing/index.tsx | 2 +- web/i18n/en-US/dataset-hit-testing.ts | 8 ++++---- web/i18n/zh-Hans/dataset-hit-testing.ts | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/web/app/components/datasets/hit-testing/index.tsx b/web/app/components/datasets/hit-testing/index.tsx index 969768f2c0..9596b4394f 100644 --- a/web/app/components/datasets/hit-testing/index.tsx +++ b/web/app/components/datasets/hit-testing/index.tsx @@ -123,7 +123,7 @@ const HitTesting: FC = ({ datasetId }: Props) => { retrievalConfig={retrievalConfig} isEconomy={currentDataset?.indexing_technique === 'economy'} /> -
{t('datasetHitTesting.recents')}
+
{t('datasetHitTesting.records')}
{(!recordsRes && !error) ? (
diff --git a/web/i18n/en-US/dataset-hit-testing.ts b/web/i18n/en-US/dataset-hit-testing.ts index 8b8629e90a..1e68306a9d 100644 --- a/web/i18n/en-US/dataset-hit-testing.ts +++ b/web/i18n/en-US/dataset-hit-testing.ts @@ -1,9 +1,9 @@ const translation = { - title: 'Retrieval Testing', + title: 'Retrieval Test', settingTitle: 'Retrieval Setting', - desc: 'Test the hitting effect of the Knowledge based on the given query text', + desc: 'Test the hitting effect of the Knowledge based on the given query text.', dateTimeFormat: 'MM/DD/YYYY hh:mm A', - recents: 'Recents', + records: 'Records', table: { header: { source: 'Source', @@ -16,7 +16,7 @@ const translation = { placeholder: 'Please enter a text, a short declarative sentence is recommended.', countWarning: 'Up to 200 characters.', indexWarning: 'High quality Knowledge only.', - testing: 'Testing', + testing: 'Test', }, hit: { title: '{{num}} Retrieved Chunks', diff --git a/web/i18n/zh-Hans/dataset-hit-testing.ts b/web/i18n/zh-Hans/dataset-hit-testing.ts index caf88acc76..88924edc82 100644 --- a/web/i18n/zh-Hans/dataset-hit-testing.ts +++ b/web/i18n/zh-Hans/dataset-hit-testing.ts @@ -1,9 +1,9 @@ const translation = { title: '召回测试', settingTitle: '召回设置', - desc: '基于给定的查询文本测试知识库的召回效果', + desc: '根据给定的查询文本测试知识的召回效果。', dateTimeFormat: 'YYYY-MM-DD HH:mm', - recents: '最近查询', + records: '记录', table: { header: { source: '数据源', From 782845f1a7c521c92303ca2914e01f5fed813567 Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 16 Dec 2024 16:51:12 +0800 Subject: [PATCH 3/3] fix: header text --- .../datasets/hit-testing/hit-detail.tsx | 68 ------------------- .../components/datasets/hit-testing/index.tsx | 43 +++--------- .../datasets/hit-testing/style.module.css | 30 +++----- 3 files changed, 18 insertions(+), 123 deletions(-) delete mode 100644 web/app/components/datasets/hit-testing/hit-detail.tsx diff --git a/web/app/components/datasets/hit-testing/hit-detail.tsx b/web/app/components/datasets/hit-testing/hit-detail.tsx deleted file mode 100644 index d2129ef1ae..0000000000 --- a/web/app/components/datasets/hit-testing/hit-detail.tsx +++ /dev/null @@ -1,68 +0,0 @@ -import type { FC } from 'react' -import React from 'react' -import { useTranslation } from 'react-i18next' -import { SegmentIndexTag } from '../documents/detail/completed/common/segment-index-tag' -import s from '../documents/detail/completed/style.module.css' -import cn from '@/utils/classnames' -import type { SegmentDetailModel } from '@/models/datasets' -import Divider from '@/app/components/base/divider' - -type IHitDetailProps = { - segInfo?: Partial & { id: string } -} - -const HitDetail: FC = ({ segInfo }) => { - const { t } = useTranslation() - - const renderContent = () => { - if (segInfo?.answer) { - return ( - <> -
QUESTION
-
{segInfo.content}
-
ANSWER
-
{segInfo.answer}
- - ) - } - - return
{segInfo?.content}
- } - - return ( - segInfo?.id === 'external' - ?
-
{renderContent()}
-
- :
-
- -
- - {segInfo?.word_count} {t('datasetDocuments.segment.characters', { count: segInfo?.word_count || 0 })} - -
- - {segInfo?.hit_count} {t('datasetDocuments.segment.hitCount')} - -
- -
{renderContent()}
-
- {t('datasetDocuments.segment.keywords')} -
-
- {!segInfo?.keywords?.length - ? '-' - : segInfo?.keywords?.map((word, index) => { - return
{word}
- })} -
-
- ) -} - -export default HitDetail diff --git a/web/app/components/datasets/hit-testing/index.tsx b/web/app/components/datasets/hit-testing/index.tsx index 9596b4394f..99f031c0ea 100644 --- a/web/app/components/datasets/hit-testing/index.tsx +++ b/web/app/components/datasets/hit-testing/index.tsx @@ -9,11 +9,10 @@ import { useContext } from 'use-context-selector' import SegmentCard from '../documents/detail/completed/SegmentCard' import Textarea from './textarea' import s from './style.module.css' -// import HitDetail from './hit-detail' import ModifyRetrievalModal from './modify-retrieval-modal' import ResultItem from './components/result-item' import cn from '@/utils/classnames' -import type { ExternalKnowledgeBaseHitTestingResponse, ExternalKnowledgeBaseHitTesting as ExternalKnowledgeBaseHitTestingType, HitTestingResponse, HitTesting as HitTestingType } from '@/models/datasets' +import type { ExternalKnowledgeBaseHitTestingResponse, HitTestingResponse } from '@/models/datasets' import Loading from '@/app/components/base/loading' import Drawer from '@/app/components/base/drawer' import Pagination from '@/app/components/base/pagination' @@ -49,11 +48,8 @@ const HitTesting: FC = ({ datasetId }: Props) => { const isMobile = media === MediaType.mobile const [hitResult, setHitResult] = useState() // 初始化记录为空数组 - // console.log(hitResult?.records) const [externalHitResult, setExternalHitResult] = useState() const [submitLoading, setSubmitLoading] = useState(false) - const [currParagraph, setCurrParagraph] = useState<{ paraInfo?: HitTestingType; showModal: boolean }>({ showModal: false }) - const [externalCurrParagraph, setExternalCurrParagraph] = useState<{ paraInfo?: ExternalKnowledgeBaseHitTestingType; showModal: boolean }>({ showModal: false }) const [text, setText] = useState('') const [currPage, setCurrPage] = React.useState(0) @@ -103,10 +99,10 @@ const HitTesting: FC = ({ datasetId }: Props) => { return (
-
-
-

{t('datasetHitTesting.title')}

-

{t('datasetHitTesting.desc')}

+
+
+

{t('datasetHitTesting.title')}

+

{t('datasetHitTesting.desc')}