Skip to content

Commit

Permalink
fix: external dataset hit test display issue(langgenius#12564)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxinliang committed Jan 10, 2025
1 parent 989fb11 commit 6733cf7
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"use client";
import type { FC } from "react"
import React from "react"
import { useBoolean } from "ahooks"
import SegmentCard from "@/app/components/datasets/documents/detail/completed/SegmentCard"
import type { ExternalKnowledgeBaseHitTesting } from "@/models/datasets"
import cn from "@/utils/classnames"
import Modal from "@/app/components/base/modal"
import s from "@/app/components/datasets/documents/detail/completed/style.module.css"

type Props = {
payload: ExternalKnowledgeBaseHitTesting;
};

const ResultItemExternal: FC<Props> = ({ payload }) => {
const record = payload;
const [
isShowDetailModal,
{ setTrue: showDetailModal, setFalse: hideDetailModal },
] = useBoolean(false);

return (
<div
className={cn(
"pt-3 bg-chat-bubble-bg rounded-xl hover:shadow-lg cursor-pointer"
)}
onClick={showDetailModal}
>
<SegmentCard
loading={false}
refSource={{
title: record.title,
uri: record.metadata
? record.metadata["x-amz-bedrock-kb-source-uri"]
: "",
}}
isExternal
contentExternal={record.content}
score={record.score}
scene="hitTesting"
className="h-[216px] mb-4"
/>

{isShowDetailModal && (
<Modal
className={"py-10 px-8"}
closable
onClose={hideDetailModal}
isShow={isShowDetailModal}
>
<div className="w-full overflow-x-auto px-2">
<div className={s.segModalContent}>
<div className="mb-4 text-md text-gray-800 h-full">
{record.content}
</div>
</div>
</div>
</Modal>
)}
</div>
);
};


export default React.memo(ResultItemExternal);
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@ import { extensionToFileType } from '@/app/components/datasets/hit-testing/utils

const i18nPrefix = 'datasetHitTesting'
type Props = {
isExternal: boolean
payload: HitTesting
}

const ResultItem: FC<Props> = ({
isExternal,
payload,
}) => {
const { t } = useTranslation()
const { segment, content: externalContent, score, child_chunks } = payload
const data = isExternal ? externalContent : segment
const { segment, score, child_chunks } = payload
const data = 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
Expand Down
33 changes: 20 additions & 13 deletions web/app/components/datasets/hit-testing/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Textarea from './textarea'
import s from './style.module.css'
import ModifyRetrievalModal from './modify-retrieval-modal'
import ResultItem from './components/result-item'
import ResultItemExternal from "./components/result-item-external"
import cn from '@/utils/classnames'
import type { ExternalKnowledgeBaseHitTestingResponse, HitTestingResponse } from '@/models/datasets'
import Loading from '@/app/components/base/loading'
Expand All @@ -24,6 +25,7 @@ import type { RetrievalConfig } from '@/types/app'
import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
import useTimestamp from '@/hooks/use-timestamp'
import docStyle from '@/app/components/datasets/documents/detail/completed/style.module.css'
import type { HitTesting, ExternalKnowledgeBaseHitTesting } from "@/models/datasets"

const limit = 10

Expand Down Expand Up @@ -68,22 +70,27 @@ const HitTesting: FC<Props> = ({ datasetId }: Props) => {
const [retrievalConfig, setRetrievalConfig] = useState(currentDataset?.retrieval_model_dict as RetrievalConfig)
const [isShowModifyRetrievalModal, setIsShowModifyRetrievalModal] = useState(false)
const [isShowRightPanel, { setTrue: showRightPanel, setFalse: hideRightPanel, set: setShowRightPanel }] = useBoolean(!isMobile)
const renderHitResults = (results: any[]) => (
<div className='h-full flex flex-col py-3 px-4 rounded-t-2xl bg-background-body'>
<div className='shrink-0 pl-2 text-text-primary font-semibold leading-6 mb-2'>
{t('datasetHitTesting.hit.title', { num: results.length })}
const renderHitResults = (
results: HitTesting[] | ExternalKnowledgeBaseHitTesting[]
) => (
<div className="h-full flex flex-col py-3 px-4 rounded-t-2xl bg-background-body">
<div className="shrink-0 pl-2 text-text-primary font-semibold leading-6 mb-2">
{t("datasetHitTesting.hit.title", { num: results.length })}
</div>
<div className='grow overflow-y-auto space-y-2'>
{results.map((record, idx) => (
<ResultItem
key={idx}
payload={record}
isExternal={isExternal}
/>
))}
<div className="grow overflow-y-auto space-y-2">
{results.map((record, idx) =>
isExternal ? (
<ResultItemExternal
key={idx}
payload={record as ExternalKnowledgeBaseHitTesting}
/>
) : (
<ResultItem key={idx} payload={record as HitTesting} />
)
)}
</div>
</div>
)
);

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

0 comments on commit 6733cf7

Please sign in to comment.