Skip to content

Commit 6733cf7

Browse files
author
zhuxinliang
committed
fix: external dataset hit test display issue(langgenius#12564)
1 parent 989fb11 commit 6733cf7

File tree

3 files changed

+87
-17
lines changed

3 files changed

+87
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"use client";
2+
import type { FC } from "react"
3+
import React from "react"
4+
import { useBoolean } from "ahooks"
5+
import SegmentCard from "@/app/components/datasets/documents/detail/completed/SegmentCard"
6+
import type { ExternalKnowledgeBaseHitTesting } from "@/models/datasets"
7+
import cn from "@/utils/classnames"
8+
import Modal from "@/app/components/base/modal"
9+
import s from "@/app/components/datasets/documents/detail/completed/style.module.css"
10+
11+
type Props = {
12+
payload: ExternalKnowledgeBaseHitTesting;
13+
};
14+
15+
const ResultItemExternal: FC<Props> = ({ payload }) => {
16+
const record = payload;
17+
const [
18+
isShowDetailModal,
19+
{ setTrue: showDetailModal, setFalse: hideDetailModal },
20+
] = useBoolean(false);
21+
22+
return (
23+
<div
24+
className={cn(
25+
"pt-3 bg-chat-bubble-bg rounded-xl hover:shadow-lg cursor-pointer"
26+
)}
27+
onClick={showDetailModal}
28+
>
29+
<SegmentCard
30+
loading={false}
31+
refSource={{
32+
title: record.title,
33+
uri: record.metadata
34+
? record.metadata["x-amz-bedrock-kb-source-uri"]
35+
: "",
36+
}}
37+
isExternal
38+
contentExternal={record.content}
39+
score={record.score}
40+
scene="hitTesting"
41+
className="h-[216px] mb-4"
42+
/>
43+
44+
{isShowDetailModal && (
45+
<Modal
46+
className={"py-10 px-8"}
47+
closable
48+
onClose={hideDetailModal}
49+
isShow={isShowDetailModal}
50+
>
51+
<div className="w-full overflow-x-auto px-2">
52+
<div className={s.segModalContent}>
53+
<div className="mb-4 text-md text-gray-800 h-full">
54+
{record.content}
55+
</div>
56+
</div>
57+
</div>
58+
</Modal>
59+
)}
60+
</div>
61+
);
62+
};
63+
64+
65+
export default React.memo(ResultItemExternal);

web/app/components/datasets/hit-testing/components/result-item.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@ import { extensionToFileType } from '@/app/components/datasets/hit-testing/utils
1818

1919
const i18nPrefix = 'datasetHitTesting'
2020
type Props = {
21-
isExternal: boolean
2221
payload: HitTesting
2322
}
2423

2524
const ResultItem: FC<Props> = ({
26-
isExternal,
2725
payload,
2826
}) => {
2927
const { t } = useTranslation()
30-
const { segment, content: externalContent, score, child_chunks } = payload
31-
const data = isExternal ? externalContent : segment
28+
const { segment, score, child_chunks } = payload
29+
const data = segment
3230
const { position, word_count, content, keywords, document } = data
3331
const isParentChildRetrieval = !!(child_chunks && child_chunks.length > 0)
3432
const extension = document.name.split('.').slice(-1)[0] as FileAppearanceTypeEnum

web/app/components/datasets/hit-testing/index.tsx

+20-13
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Textarea from './textarea'
1212
import s from './style.module.css'
1313
import ModifyRetrievalModal from './modify-retrieval-modal'
1414
import ResultItem from './components/result-item'
15+
import ResultItemExternal from "./components/result-item-external"
1516
import cn from '@/utils/classnames'
1617
import type { ExternalKnowledgeBaseHitTestingResponse, HitTestingResponse } from '@/models/datasets'
1718
import Loading from '@/app/components/base/loading'
@@ -24,6 +25,7 @@ import type { RetrievalConfig } from '@/types/app'
2425
import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
2526
import useTimestamp from '@/hooks/use-timestamp'
2627
import docStyle from '@/app/components/datasets/documents/detail/completed/style.module.css'
28+
import type { HitTesting, ExternalKnowledgeBaseHitTesting } from "@/models/datasets"
2729

2830
const limit = 10
2931

@@ -68,22 +70,27 @@ const HitTesting: FC<Props> = ({ datasetId }: Props) => {
6870
const [retrievalConfig, setRetrievalConfig] = useState(currentDataset?.retrieval_model_dict as RetrievalConfig)
6971
const [isShowModifyRetrievalModal, setIsShowModifyRetrievalModal] = useState(false)
7072
const [isShowRightPanel, { setTrue: showRightPanel, setFalse: hideRightPanel, set: setShowRightPanel }] = useBoolean(!isMobile)
71-
const renderHitResults = (results: any[]) => (
72-
<div className='h-full flex flex-col py-3 px-4 rounded-t-2xl bg-background-body'>
73-
<div className='shrink-0 pl-2 text-text-primary font-semibold leading-6 mb-2'>
74-
{t('datasetHitTesting.hit.title', { num: results.length })}
73+
const renderHitResults = (
74+
results: HitTesting[] | ExternalKnowledgeBaseHitTesting[]
75+
) => (
76+
<div className="h-full flex flex-col py-3 px-4 rounded-t-2xl bg-background-body">
77+
<div className="shrink-0 pl-2 text-text-primary font-semibold leading-6 mb-2">
78+
{t("datasetHitTesting.hit.title", { num: results.length })}
7579
</div>
76-
<div className='grow overflow-y-auto space-y-2'>
77-
{results.map((record, idx) => (
78-
<ResultItem
79-
key={idx}
80-
payload={record}
81-
isExternal={isExternal}
82-
/>
83-
))}
80+
<div className="grow overflow-y-auto space-y-2">
81+
{results.map((record, idx) =>
82+
isExternal ? (
83+
<ResultItemExternal
84+
key={idx}
85+
payload={record as ExternalKnowledgeBaseHitTesting}
86+
/>
87+
) : (
88+
<ResultItem key={idx} payload={record as HitTesting} />
89+
)
90+
)}
8491
</div>
8592
</div>
86-
)
93+
);
8794

8895
const renderEmptyState = () => (
8996
<div className='h-full flex flex-col justify-center items-center py-3 px-4 rounded-t-2xl bg-background-body'>

0 commit comments

Comments
 (0)