Commit bb7596c3 by archer

feat: queue len show

parent 4952a48c
...@@ -38,7 +38,9 @@ ...@@ -38,7 +38,9 @@
"Output": "Output" "Output": "Output"
}, },
"dataset": { "dataset": {
"Confirm to delete the data": "Confirm to delete the data?" "Confirm to delete the data": "Confirm to delete the data?",
"Queue Desc": "This data refers to the current amount of training for the entire system. FastGPT uses queued training, and if you have too much data to train, you may need to wait for a while",
"System Data Queue": "Data Queue"
}, },
"file": { "file": {
"Click to download CSV template": "Click to download CSV template", "Click to download CSV template": "Click to download CSV template",
......
...@@ -38,7 +38,9 @@ ...@@ -38,7 +38,9 @@
"Output": "输出" "Output": "输出"
}, },
"dataset": { "dataset": {
"Confirm to delete the data": "确认删除该数据?" "Confirm to delete the data": "确认删除该数据?",
"Queue Desc": "该数据是指整个系统当前待训练的数量。FastGPT 采用排队训练的方式,如果待训练的数据过多,可能需要等待一段时间",
"System Data Queue": "排队长度"
}, },
"file": { "file": {
"Click to download CSV template": "点击下载 CSV 模板", "Click to download CSV template": "点击下载 CSV 模板",
......
...@@ -60,6 +60,9 @@ export const getTrainingData = (data: { kbId: string; init: boolean }) => ...@@ -60,6 +60,9 @@ export const getTrainingData = (data: { kbId: string; init: boolean }) =>
vectorListLen: number; vectorListLen: number;
}>(`/plugins/kb/data/getTrainingData`, data); }>(`/plugins/kb/data/getTrainingData`, data);
/* get length of system training queue */
export const getTrainingQueueLen = () => GET<number>(`/plugins/kb/data/getQueueLen`);
export const getKbDataItemById = (dataId: string) => export const getKbDataItemById = (dataId: string) =>
GET<KbDataItemType>(`/plugins/kb/data/getDataById`, { dataId }); GET<KbDataItemType>(`/plugins/kb/data/getDataById`, { dataId });
......
import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@/service/response';
import { TrainingData } from '@/service/mongo';
import { authUser } from '@/service/utils/auth';
/* 拆分数据成QA */
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
await authUser({ req, authToken: true });
// split queue data
const result = await TrainingData.countDocuments({
lockTime: { $lt: new Date('2040/1/1') }
});
jsonRes(res, {
data: result
});
} catch (err) {
jsonRes(res, {
code: 500,
error: err
});
}
}
import React, { useCallback, useState, useRef, useEffect } from 'react'; import React, { useCallback, useState, useRef } from 'react';
import { Box, Card, IconButton, Flex, Button, Input, Grid } from '@chakra-ui/react'; import { Box, Card, IconButton, Flex, Button, Input, Grid } from '@chakra-ui/react';
import type { KbDataItemType } from '@/types/plugin'; import type { KbDataItemType } from '@/types/plugin';
import { usePagination } from '@/hooks/usePagination'; import { usePagination } from '@/hooks/usePagination';
......
...@@ -18,6 +18,10 @@ import PageContainer from '@/components/PageContainer'; ...@@ -18,6 +18,10 @@ import PageContainer from '@/components/PageContainer';
import Avatar from '@/components/Avatar'; import Avatar from '@/components/Avatar';
import Info from './components/Info'; import Info from './components/Info';
import { serviceSideProps } from '@/utils/i18n'; import { serviceSideProps } from '@/utils/i18n';
import { useTranslation } from 'react-i18next';
import { getTrainingQueueLen } from '@/api/plugins/kb';
import MyTooltip from '@/components/MyTooltip';
import { QuestionOutlineIcon } from '@chakra-ui/icons';
const ImportData = dynamic(() => import('./components/Import'), { const ImportData = dynamic(() => import('./components/Import'), {
ssr: false ssr: false
...@@ -36,6 +40,7 @@ enum TabEnum { ...@@ -36,6 +40,7 @@ enum TabEnum {
const Detail = ({ kbId, currentTab }: { kbId: string; currentTab: `${TabEnum}` }) => { const Detail = ({ kbId, currentTab }: { kbId: string; currentTab: `${TabEnum}` }) => {
const InfoRef = useRef<ComponentRef>(null); const InfoRef = useRef<ComponentRef>(null);
const theme = useTheme(); const theme = useTheme();
const { t } = useTranslation();
const { toast } = useToast(); const { toast } = useToast();
const router = useRouter(); const router = useRouter();
const { isPc } = useGlobalStore(); const { isPc } = useGlobalStore();
...@@ -78,6 +83,10 @@ const Detail = ({ kbId, currentTab }: { kbId: string; currentTab: `${TabEnum}` } ...@@ -78,6 +83,10 @@ const Detail = ({ kbId, currentTab }: { kbId: string; currentTab: `${TabEnum}` }
} }
}); });
const { data: trainingQueueLen = 0 } = useQuery(['getTrainingQueueLen'], getTrainingQueueLen, {
refetchInterval: 5000
});
return ( return (
<PageContainer> <PageContainer>
<Box display={['block', 'flex']} h={'100%'} pt={[4, 0]}> <Box display={['block', 'flex']} h={'100%'} pt={[4, 0]}>
...@@ -106,6 +115,18 @@ const Detail = ({ kbId, currentTab }: { kbId: string; currentTab: `${TabEnum}` } ...@@ -106,6 +115,18 @@ const Detail = ({ kbId, currentTab }: { kbId: string; currentTab: `${TabEnum}` }
setCurrentTab(e); setCurrentTab(e);
}} }}
/> />
<Box textAlign={'center'}>
<Flex justifyContent={'center'} alignItems={'center'}>
<MyIcon mr={1} name="overviewLight" w={'16px'} color={'green.500'} />
<Box>{t('dataset.System Data Queue')}</Box>
<MyTooltip label={t('dataset.Queue Desc')} placement={'top'}>
<QuestionOutlineIcon ml={1} w={'16px'} cursor={'pointer'} />
</MyTooltip>
</Flex>
<Box mt={1} fontWeight={'bold'}>
{trainingQueueLen}
</Box>
</Box>
<Flex <Flex
alignItems={'center'} alignItems={'center'}
cursor={'pointer'} cursor={'pointer'}
......
...@@ -26,7 +26,7 @@ export async function generateVector(): Promise<any> { ...@@ -26,7 +26,7 @@ export async function generateVector(): Promise<any> {
const data = await TrainingData.findOneAndUpdate( const data = await TrainingData.findOneAndUpdate(
{ {
mode: TrainingModeEnum.index, mode: TrainingModeEnum.index,
lockTime: { $lte: new Date(Date.now() - 2 * 60 * 1000) } lockTime: { $lte: new Date(Date.now() - 1 * 60 * 1000) }
}, },
{ {
lockTime: new Date() lockTime: new Date()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment