diff --git a/client/public/locales/en/common.json b/client/public/locales/en/common.json index fe0e2a4f0..a2d382ae7 100644 --- a/client/public/locales/en/common.json +++ b/client/public/locales/en/common.json @@ -38,7 +38,9 @@ "Output": "Output" }, "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": { "Click to download CSV template": "Click to download CSV template", diff --git a/client/public/locales/zh/common.json b/client/public/locales/zh/common.json index c8c8653b7..3750fbd08 100644 --- a/client/public/locales/zh/common.json +++ b/client/public/locales/zh/common.json @@ -38,7 +38,9 @@ "Output": "输出" }, "dataset": { - "Confirm to delete the data": "确认删除该数据?" + "Confirm to delete the data": "确认删除该数据?", + "Queue Desc": "该数据是指整个系统当前待训练的数量。FastGPT 采用排队训练的方式,如果待训练的数据过多,可能需要等待一段时间", + "System Data Queue": "排队长度" }, "file": { "Click to download CSV template": "点击下载 CSV 模板", diff --git a/client/src/api/plugins/kb.ts b/client/src/api/plugins/kb.ts index 71315a10e..137a578f1 100644 --- a/client/src/api/plugins/kb.ts +++ b/client/src/api/plugins/kb.ts @@ -60,6 +60,9 @@ export const getTrainingData = (data: { kbId: string; init: boolean }) => vectorListLen: number; }>(`/plugins/kb/data/getTrainingData`, data); +/* get length of system training queue */ +export const getTrainingQueueLen = () => GET(`/plugins/kb/data/getQueueLen`); + export const getKbDataItemById = (dataId: string) => GET(`/plugins/kb/data/getDataById`, { dataId }); diff --git a/client/src/pages/api/plugins/kb/data/getQueueLen.ts b/client/src/pages/api/plugins/kb/data/getQueueLen.ts new file mode 100644 index 000000000..eadadbd8d --- /dev/null +++ b/client/src/pages/api/plugins/kb/data/getQueueLen.ts @@ -0,0 +1,25 @@ +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 + }); + } +} diff --git a/client/src/pages/kb/detail/components/DataCard.tsx b/client/src/pages/kb/detail/components/DataCard.tsx index 9540a0516..4ef1c26ad 100644 --- a/client/src/pages/kb/detail/components/DataCard.tsx +++ b/client/src/pages/kb/detail/components/DataCard.tsx @@ -1,4 +1,4 @@ -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 type { KbDataItemType } from '@/types/plugin'; import { usePagination } from '@/hooks/usePagination'; diff --git a/client/src/pages/kb/detail/index.tsx b/client/src/pages/kb/detail/index.tsx index 22c3997b3..a516bb80c 100644 --- a/client/src/pages/kb/detail/index.tsx +++ b/client/src/pages/kb/detail/index.tsx @@ -18,6 +18,10 @@ import PageContainer from '@/components/PageContainer'; import Avatar from '@/components/Avatar'; import Info from './components/Info'; 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'), { ssr: false @@ -36,6 +40,7 @@ enum TabEnum { const Detail = ({ kbId, currentTab }: { kbId: string; currentTab: `${TabEnum}` }) => { const InfoRef = useRef(null); const theme = useTheme(); + const { t } = useTranslation(); const { toast } = useToast(); const router = useRouter(); const { isPc } = useGlobalStore(); @@ -78,6 +83,10 @@ const Detail = ({ kbId, currentTab }: { kbId: string; currentTab: `${TabEnum}` } } }); + const { data: trainingQueueLen = 0 } = useQuery(['getTrainingQueueLen'], getTrainingQueueLen, { + refetchInterval: 5000 + }); + return ( @@ -106,6 +115,18 @@ const Detail = ({ kbId, currentTab }: { kbId: string; currentTab: `${TabEnum}` } setCurrentTab(e); }} /> + + + + {t('dataset.System Data Queue')} + + + + + + {trainingQueueLen} + + { const data = await TrainingData.findOneAndUpdate( { mode: TrainingModeEnum.index, - lockTime: { $lte: new Date(Date.now() - 2 * 60 * 1000) } + lockTime: { $lte: new Date(Date.now() - 1 * 60 * 1000) } }, { lockTime: new Date()