mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 21:13:50 +00:00
fix: kb un refresh
This commit is contained in:
@@ -167,6 +167,8 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
|
||||
return res.json({
|
||||
id: chatId || '',
|
||||
model: model.chat.chatModel,
|
||||
object: 'chat.completion',
|
||||
created: 1688608930,
|
||||
usage: { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 },
|
||||
choices: [
|
||||
{ message: { role: 'assistant', content: response }, finish_reason: 'stop', index: 0 }
|
||||
@@ -296,6 +298,8 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
|
||||
: {}),
|
||||
newChatId,
|
||||
id: chatId || '',
|
||||
object: 'chat.completion',
|
||||
created: 1688608930,
|
||||
model: model.chat.chatModel,
|
||||
usage: { prompt_tokens: 0, completion_tokens: 0, total_tokens: tokens },
|
||||
choices: [
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import React, { useCallback, useState, useRef } from 'react';
|
||||
import React, { useCallback, useState, useRef, useEffect } from 'react';
|
||||
import {
|
||||
Box,
|
||||
Card,
|
||||
@@ -50,11 +50,11 @@ const DataCard = ({ kbId }: { kbId: string }) => {
|
||||
} = usePagination<KbDataItemType>({
|
||||
api: getKbDataList,
|
||||
pageSize: 24,
|
||||
defaultRequest: false,
|
||||
params: {
|
||||
kbId,
|
||||
searchText
|
||||
},
|
||||
defaultRequest: false
|
||||
}
|
||||
});
|
||||
|
||||
const [editInputData, setEditInputData] = useState<InputDataType>();
|
||||
@@ -133,11 +133,11 @@ const DataCard = ({ kbId }: { kbId: string }) => {
|
||||
refetchInterval: 5000,
|
||||
enabled: qaListLen > 0 || vectorListLen > 0
|
||||
});
|
||||
useQuery(['getKbData', kbId], () => {
|
||||
|
||||
useEffect(() => {
|
||||
setSearchText('');
|
||||
getData(1);
|
||||
return null;
|
||||
});
|
||||
}, [kbId]);
|
||||
|
||||
return (
|
||||
<Box position={'relative'} px={5} pb={[1, 5]}>
|
||||
@@ -314,4 +314,4 @@ const DataCard = ({ kbId }: { kbId: string }) => {
|
||||
);
|
||||
};
|
||||
|
||||
export default DataCard;
|
||||
export default React.memo(DataCard);
|
||||
|
@@ -8,7 +8,7 @@ import { useUserStore } from '@/store/user';
|
||||
import { KbItemType } from '@/types/plugin';
|
||||
import { useScreen } from '@/hooks/useScreen';
|
||||
import { getErrText } from '@/utils/tools';
|
||||
import Info, { type ComponentRef } from './Info';
|
||||
import { type ComponentRef } from './Info';
|
||||
import Tabs from '@/components/Tabs';
|
||||
import dynamic from 'next/dynamic';
|
||||
import DataCard from './DataCard';
|
||||
@@ -16,6 +16,9 @@ import DataCard from './DataCard';
|
||||
const Test = dynamic(() => import('./Test'), {
|
||||
ssr: false
|
||||
});
|
||||
const Info = dynamic(() => import('./Info'), {
|
||||
ssr: false
|
||||
});
|
||||
|
||||
enum TabEnum {
|
||||
data = 'data',
|
||||
@@ -28,7 +31,7 @@ const Detail = ({ kbId }: { kbId: string }) => {
|
||||
const router = useRouter();
|
||||
const { isPc } = useScreen();
|
||||
const BasicInfo = useRef<ComponentRef>(null);
|
||||
const { setLastKbId, kbDetail, getKbDetail, loadKbList, myKbList } = useUserStore();
|
||||
const { setLastKbId, kbDetail, getKbDetail, loadKbList } = useUserStore();
|
||||
const [currentTab, setCurrentTab] = useState(TabEnum.data);
|
||||
|
||||
const form = useForm<KbItemType>({
|
||||
@@ -36,25 +39,30 @@ const Detail = ({ kbId }: { kbId: string }) => {
|
||||
});
|
||||
const { reset } = form;
|
||||
|
||||
useQuery([kbId], () => getKbDetail(kbId), {
|
||||
onSuccess(res) {
|
||||
kbId && setLastKbId(kbId);
|
||||
if (res) {
|
||||
setCurrentTab(TabEnum.data);
|
||||
useQuery(
|
||||
[kbId],
|
||||
() => {
|
||||
setCurrentTab(TabEnum.data);
|
||||
return getKbDetail(kbId);
|
||||
},
|
||||
{
|
||||
onSuccess(res) {
|
||||
if (!res) return;
|
||||
kbId && setLastKbId(kbId);
|
||||
reset(res);
|
||||
BasicInfo.current?.initInput?.(res.tags);
|
||||
},
|
||||
onError(err: any) {
|
||||
loadKbList(true);
|
||||
setLastKbId('');
|
||||
router.replace(`/kb`);
|
||||
toast({
|
||||
title: getErrText(err, '获取知识库异常'),
|
||||
status: 'error'
|
||||
});
|
||||
}
|
||||
},
|
||||
onError(err: any) {
|
||||
loadKbList(true);
|
||||
setLastKbId('');
|
||||
router.replace(`/kb`);
|
||||
toast({
|
||||
title: getErrText(err, '获取知识库异常'),
|
||||
status: 'error'
|
||||
});
|
||||
}
|
||||
});
|
||||
);
|
||||
|
||||
return (
|
||||
<Flex
|
||||
@@ -88,4 +96,4 @@ const Detail = ({ kbId }: { kbId: string }) => {
|
||||
);
|
||||
};
|
||||
|
||||
export default Detail;
|
||||
export default React.memo(Detail);
|
||||
|
@@ -28,9 +28,11 @@ const Kb = () => {
|
||||
<KbList kbId={kbId} />
|
||||
</SideBar>
|
||||
)}
|
||||
<Box flex={'1 0 0'} w={0} h={'100%'} position={'relative'}>
|
||||
{kbId && <KbDetail kbId={kbId} />}
|
||||
</Box>
|
||||
{!!kbId && (
|
||||
<Box flex={'1 0 0'} w={0} h={'100%'} position={'relative'}>
|
||||
<KbDetail kbId={kbId} />
|
||||
</Box>
|
||||
)}
|
||||
</Flex>
|
||||
);
|
||||
};
|
||||
|
Reference in New Issue
Block a user