mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-27 00:17:31 +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({
|
return res.json({
|
||||||
id: chatId || '',
|
id: chatId || '',
|
||||||
model: model.chat.chatModel,
|
model: model.chat.chatModel,
|
||||||
|
object: 'chat.completion',
|
||||||
|
created: 1688608930,
|
||||||
usage: { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 },
|
usage: { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 },
|
||||||
choices: [
|
choices: [
|
||||||
{ message: { role: 'assistant', content: response }, finish_reason: 'stop', index: 0 }
|
{ 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,
|
newChatId,
|
||||||
id: chatId || '',
|
id: chatId || '',
|
||||||
|
object: 'chat.completion',
|
||||||
|
created: 1688608930,
|
||||||
model: model.chat.chatModel,
|
model: model.chat.chatModel,
|
||||||
usage: { prompt_tokens: 0, completion_tokens: 0, total_tokens: tokens },
|
usage: { prompt_tokens: 0, completion_tokens: 0, total_tokens: tokens },
|
||||||
choices: [
|
choices: [
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import React, { useCallback, useState, useRef } from 'react';
|
import React, { useCallback, useState, useRef, useEffect } from 'react';
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
Card,
|
Card,
|
||||||
@@ -50,11 +50,11 @@ const DataCard = ({ kbId }: { kbId: string }) => {
|
|||||||
} = usePagination<KbDataItemType>({
|
} = usePagination<KbDataItemType>({
|
||||||
api: getKbDataList,
|
api: getKbDataList,
|
||||||
pageSize: 24,
|
pageSize: 24,
|
||||||
|
defaultRequest: false,
|
||||||
params: {
|
params: {
|
||||||
kbId,
|
kbId,
|
||||||
searchText
|
searchText
|
||||||
},
|
}
|
||||||
defaultRequest: false
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const [editInputData, setEditInputData] = useState<InputDataType>();
|
const [editInputData, setEditInputData] = useState<InputDataType>();
|
||||||
@@ -133,11 +133,11 @@ const DataCard = ({ kbId }: { kbId: string }) => {
|
|||||||
refetchInterval: 5000,
|
refetchInterval: 5000,
|
||||||
enabled: qaListLen > 0 || vectorListLen > 0
|
enabled: qaListLen > 0 || vectorListLen > 0
|
||||||
});
|
});
|
||||||
useQuery(['getKbData', kbId], () => {
|
|
||||||
|
useEffect(() => {
|
||||||
setSearchText('');
|
setSearchText('');
|
||||||
getData(1);
|
getData(1);
|
||||||
return null;
|
}, [kbId]);
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box position={'relative'} px={5} pb={[1, 5]}>
|
<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 { KbItemType } from '@/types/plugin';
|
||||||
import { useScreen } from '@/hooks/useScreen';
|
import { useScreen } from '@/hooks/useScreen';
|
||||||
import { getErrText } from '@/utils/tools';
|
import { getErrText } from '@/utils/tools';
|
||||||
import Info, { type ComponentRef } from './Info';
|
import { type ComponentRef } from './Info';
|
||||||
import Tabs from '@/components/Tabs';
|
import Tabs from '@/components/Tabs';
|
||||||
import dynamic from 'next/dynamic';
|
import dynamic from 'next/dynamic';
|
||||||
import DataCard from './DataCard';
|
import DataCard from './DataCard';
|
||||||
@@ -16,6 +16,9 @@ import DataCard from './DataCard';
|
|||||||
const Test = dynamic(() => import('./Test'), {
|
const Test = dynamic(() => import('./Test'), {
|
||||||
ssr: false
|
ssr: false
|
||||||
});
|
});
|
||||||
|
const Info = dynamic(() => import('./Info'), {
|
||||||
|
ssr: false
|
||||||
|
});
|
||||||
|
|
||||||
enum TabEnum {
|
enum TabEnum {
|
||||||
data = 'data',
|
data = 'data',
|
||||||
@@ -28,7 +31,7 @@ const Detail = ({ kbId }: { kbId: string }) => {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { isPc } = useScreen();
|
const { isPc } = useScreen();
|
||||||
const BasicInfo = useRef<ComponentRef>(null);
|
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 [currentTab, setCurrentTab] = useState(TabEnum.data);
|
||||||
|
|
||||||
const form = useForm<KbItemType>({
|
const form = useForm<KbItemType>({
|
||||||
@@ -36,25 +39,30 @@ const Detail = ({ kbId }: { kbId: string }) => {
|
|||||||
});
|
});
|
||||||
const { reset } = form;
|
const { reset } = form;
|
||||||
|
|
||||||
useQuery([kbId], () => getKbDetail(kbId), {
|
useQuery(
|
||||||
onSuccess(res) {
|
[kbId],
|
||||||
kbId && setLastKbId(kbId);
|
() => {
|
||||||
if (res) {
|
setCurrentTab(TabEnum.data);
|
||||||
setCurrentTab(TabEnum.data);
|
return getKbDetail(kbId);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSuccess(res) {
|
||||||
|
if (!res) return;
|
||||||
|
kbId && setLastKbId(kbId);
|
||||||
reset(res);
|
reset(res);
|
||||||
BasicInfo.current?.initInput?.(res.tags);
|
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 (
|
return (
|
||||||
<Flex
|
<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} />
|
<KbList kbId={kbId} />
|
||||||
</SideBar>
|
</SideBar>
|
||||||
)}
|
)}
|
||||||
<Box flex={'1 0 0'} w={0} h={'100%'} position={'relative'}>
|
{!!kbId && (
|
||||||
{kbId && <KbDetail kbId={kbId} />}
|
<Box flex={'1 0 0'} w={0} h={'100%'} position={'relative'}>
|
||||||
</Box>
|
<KbDetail kbId={kbId} />
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user