Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docSite/content/zh-cn/docs/development/upgrading/491.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ weight: 799

1. 商业版支持单团队模式,更好的管理内部成员。
2. 知识库分块阅读器。
3. API 知识库支持 PDF 增强解析。

## ⚙️ 优化

Expand Down
7 changes: 5 additions & 2 deletions packages/service/core/dataset/apiDataset/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,13 @@ export const useApiDatasetRequest = ({ apiServer }: { apiServer: APIFileServer }
const getFileContent = async ({
teamId,
tmbId,
apiFileId
apiFileId,
customPdfParse
}: {
teamId: string;
tmbId: string;
apiFileId: string;
customPdfParse?: boolean;
}) => {
const data = await request<APIFileContentResponse>(
`/v1/file/content`,
Expand All @@ -133,7 +135,8 @@ export const useApiDatasetRequest = ({ apiServer }: { apiServer: APIFileServer }
teamId,
tmbId,
url: previewUrl,
relatedId: apiFileId
relatedId: apiFileId,
customPdfParse
});
return rawText;
}
Expand Down
11 changes: 9 additions & 2 deletions packages/service/core/dataset/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,24 @@ export const readApiServerFileContent = async ({
yuqueServer,
apiFileId,
teamId,
tmbId
tmbId,
customPdfParse
}: {
apiServer?: APIFileServer;
feishuServer?: FeishuServer;
yuqueServer?: YuqueServer;
apiFileId: string;
teamId: string;
tmbId: string;
customPdfParse?: boolean;
}) => {
if (apiServer) {
return useApiDatasetRequest({ apiServer }).getFileContent({ teamId, tmbId, apiFileId });
return useApiDatasetRequest({ apiServer }).getFileContent({
teamId,
tmbId,
apiFileId,
customPdfParse
});
}

if (feishuServer || yuqueServer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@ import { useChatStore } from '@/web/core/chat/context/useChatStore';
import { getQuoteDataList } from '@/web/core/chat/api';

const QuoteList = React.memo(function QuoteList({
chatItemId,
rawSearch = [],
chatTime
chatItemDataId = '',
rawSearch = []
}: {
chatItemId?: string;
chatItemDataId?: string;
rawSearch: SearchDataResponseItemType[];
chatTime: Date;
}) {
const theme = useTheme();
const { chatId, appId, outLinkAuthData } = useChatStore();

const RawSourceBoxProps = useContextSelector(ChatBoxContext, (v) => ({
chatItemId,
chatItemDataId,
appId: v.appId,
chatId: v.chatId,
...(v.outLinkAuthData || {})
Expand All @@ -34,13 +32,12 @@ const QuoteList = React.memo(function QuoteList({
(v) => v.showRouteToDatasetDetail
);

const { data } = useRequest2(
const { data: quoteList } = useRequest2(
async () =>
await getQuoteDataList({
datasetDataIdList: rawSearch.map((item) => item.id),
chatTime,
collectionIdList: [...new Set(rawSearch.map((item) => item.collectionId))],
chatItemId: chatItemId || '',
chatItemDataId,
appId,
chatId,
...outLinkAuthData
Expand All @@ -53,7 +50,7 @@ const QuoteList = React.memo(function QuoteList({
const formatedDataList = useMemo(() => {
return rawSearch
.map((item) => {
const currentFilterItem = data?.quoteList.find((res) => res._id === item.id);
const currentFilterItem = quoteList?.find((res) => res._id === item.id);

return {
...item,
Expand All @@ -66,7 +63,7 @@ const QuoteList = React.memo(function QuoteList({
const bScore = formatScore(b.score);
return (bScore.primaryScore?.value || 0) - (aScore.primaryScore?.value || 0);
});
}, [data?.quoteList, rawSearch]);
}, [quoteList, rawSearch]);

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const ResponseTags = ({
const [quoteFolded, setQuoteFolded] = useState<boolean>(true);

const chatType = useContextSelector(ChatBoxContext, (v) => v.chatType);
const appId = useContextSelector(ChatBoxContext, (v) => v.appId);
const chatId = useContextSelector(ChatBoxContext, (v) => v.chatId);

const setQuoteData = useContextSelector(ChatItemContext, (v) => v.setQuoteData);

Expand Down Expand Up @@ -156,17 +158,15 @@ const ResponseTags = ({
e.stopPropagation();

setQuoteData({
chatTime,
rawSearch: quoteList,
metadata: {
appId,
chatId,
chatItemDataId: dataId,
collectionId: item.collectionId,
collectionIdList: [
...new Set(quoteList.map((item) => item.collectionId))
],
sourceId: item.sourceId || '',
sourceName: item.sourceName,
datasetId: item.datasetId,
chatItemId: historyItem.dataId
datasetId: item.datasetId
}
});
}}
Expand Down Expand Up @@ -225,15 +225,12 @@ const ResponseTags = ({
e.stopPropagation();

setQuoteData({
chatTime,
rawSearch: quoteList,
metadata: {
collectionId: '',
collectionIdList: [...new Set(quoteList.map((item) => item.collectionId))],
chatItemId: historyItem.dataId,
sourceId: '',
sourceName: '',
datasetId: ''
appId,
chatId,
chatItemDataId: dataId,
collectionIdList: [...new Set(quoteList.map((item) => item.collectionId))]
}
});
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,7 @@ export const WholeResponseContent = ({
{activeModule.quoteList && activeModule.quoteList.length > 0 && (
<Row
label={t('common:core.chat.response.module quoteList')}
rawDom={
<QuoteList
chatItemId={dataId}
chatTime={chatTime || new Date()}
rawSearch={activeModule.quoteList}
/>
}
rawDom={<QuoteList chatItemDataId={dataId} rawSearch={activeModule.quoteList} />}
/>
)}
</>
Expand Down
2 changes: 1 addition & 1 deletion projects/app/src/components/core/dataset/QuoteItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ const QuoteItem = ({
color={'primary.500'}
href={`/dataset/detail?datasetId=${quoteItem.datasetId}&currentTab=dataCard&collectionId=${quoteItem.collectionId}`}
>
{t('common:core.dataset.Go Dataset')}
{t('chat:to_dataset')}
<MyIcon name={'common/rightArrowLight'} w={'10px'} />
</Link>
)}
Expand Down
4 changes: 2 additions & 2 deletions projects/app/src/components/core/dataset/RawSourceBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const RawSourceBox = ({
collectionId,
appId,
chatId,
chatItemId,
chatItemDataId,
shareId,
outLinkUid,
teamId,
Expand All @@ -40,7 +40,7 @@ const RawSourceBox = ({
collectionId,
appId,
chatId,
chatItemId,
chatItemDataId,
shareId,
outLinkUid,
teamId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ const DetailLogsModal = ({ appId, chatId, onClose }: Props) => {
borderRadius={'md'}
>
<ChatQuoteList
chatTime={quoteData.chatTime}
rawSearch={quoteData.rawSearch}
metadata={quoteData.metadata}
onClose={() => setQuoteData(undefined)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ const ChatTest = ({ appForm, setRenderEdit }: Props) => {
{quoteData && (
<Box flex={'1 0 0'} w={0} maxW={'560px'} {...cardStyles} boxShadow={'3'}>
<ChatQuoteList
chatTime={quoteData.chatTime}
rawSearch={quoteData.rawSearch}
metadata={quoteData.metadata}
onClose={() => setQuoteData(undefined)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ const ChatTest = ({ isOpen, nodes = [], edges = [], onClose }: Props) => {
borderRadius={'md'}
>
<ChatQuoteList
chatTime={quoteData.chatTime}
rawSearch={quoteData.rawSearch}
metadata={quoteData.metadata}
onClose={() => setQuoteData(undefined)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, Button, Flex, HStack } from '@chakra-ui/react';
import { Box, Flex, HStack } from '@chakra-ui/react';
import { SearchDataResponseItemType } from '@fastgpt/global/core/dataset/type';
import { getSourceNameIcon } from '@fastgpt/global/core/dataset/utils';
import MyIcon from '@fastgpt/web/components/common/Icon';
Expand All @@ -8,41 +8,34 @@ import DownloadButton from './DownloadButton';
import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
import { downloadFetch } from '@/web/common/system/utils';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { getCollectionSource, getDatasetDataPermission } from '@/web/core/dataset/api';
import { useChatStore } from '@/web/core/chat/context/useChatStore';
import { useToast } from '@fastgpt/web/hooks/useToast';
import { getErrText } from '@fastgpt/global/common/error/utils';
import { getDatasetDataPermission } from '@/web/core/dataset/api';
import ScoreTag from './ScoreTag';
import { formatScore } from '@/components/core/dataset/QuoteItem';
import NavButton from './NavButton';
import { useLinkedScroll } from '@fastgpt/web/hooks/useLinkedScroll';
import CollectionQuoteItem from './CollectionQuoteItem';
import { DatasetDataListItemType } from '@/global/core/dataset/type';
import { metadataType } from '@/web/core/chat/context/chatItemContext';
import { GetCollectionQuoteDataProps } from '@/web/core/chat/context/chatItemContext';
import { useUserStore } from '@/web/support/user/useUserStore';
import { getCollectionQuote } from '@/web/core/chat/api';
import MyIconButton from '@fastgpt/web/components/common/Icon/button';
import MyTooltip from '@fastgpt/web/components/common/MyTooltip';
import MyBox from '@fastgpt/web/components/common/MyBox';
import { getCollectionSourceAndOpen } from '@/web/core/dataset/hooks/readCollectionSource';
import { QuoteDataItemType } from '@/service/core/chat/constants';

const CollectionReader = ({
rawSearch,
metadata,
chatTime,
onClose
}: {
rawSearch: SearchDataResponseItemType[];
metadata: metadataType;
chatTime: Date;
metadata: GetCollectionQuoteDataProps;
onClose: () => void;
}) => {
const { t } = useTranslation();
const router = useRouter();
const { toast } = useToast();
const { chatId, appId, outLinkAuthData } = useChatStore();
const { userInfo } = useUserStore();
const { collectionId, datasetId, chatItemId, sourceId, sourceName } = metadata;
const { collectionId, datasetId, chatItemDataId, sourceId, sourceName } = metadata;
const [quoteIndex, setQuoteIndex] = useState(0);

const { data: permissionData, loading: isPermissionLoading } = useRequest2(
Expand Down Expand Up @@ -75,23 +68,25 @@ const CollectionReader = ({
refreshDeps: [collectionId],
params: {
collectionId,
chatTime,
chatItemId,
chatId,
appId,
...outLinkAuthData
chatItemDataId,
chatId: metadata.chatId,
appId: metadata.appId,
...metadata.outLinkAuthData
},
initialId: currentQuoteItem?.id,
initialIndex: currentQuoteItem?.chunkIndex,
canLoadData: !!currentQuoteItem?.id && !isPermissionLoading
});

const loading = isLoading || isPermissionLoading;
const isDeleted = !datasetDataList.find((item) => item._id === currentQuoteItem?.id);
const isDeleted = useMemo(
() => !datasetDataList.find((item) => item._id === currentQuoteItem?.id),
[datasetDataList, currentQuoteItem?.id]
);

const formatedDataList = useMemo(
() =>
datasetDataList.map((item: DatasetDataListItemType) => {
datasetDataList.map((item: QuoteDataItemType) => {
const isCurrentSelected = currentQuoteItem?.id === item._id;
const quoteIndex = filterResults.findIndex((res) => res.id === item._id);

Expand All @@ -115,17 +110,12 @@ const CollectionReader = ({
filename: 'data.csv',
body: {
collectionId: collectionId,
chatTime: chatTime,
chatItemId: chatItemId
chatItemDataId
}
});
});

const handleRead = getCollectionSourceAndOpen({
appId,
chatId,
...metadata
});
const handleRead = getCollectionSourceAndOpen(metadata);

const handleNavigate = useCallback(
async (targetIndex: number) => {
Expand Down
Loading
Loading