diff --git a/client/src/components/ChatBox/SelectDataset.tsx b/client/src/components/ChatBox/SelectDataset.tsx index 331d4e8a4..46e693295 100644 --- a/client/src/components/ChatBox/SelectDataset.tsx +++ b/client/src/components/ChatBox/SelectDataset.tsx @@ -32,7 +32,7 @@ const SelectDataset = ({ const { myKbList, loadKbList } = useUserStore(); const [selectedId, setSelectedId] = useState(); - useQuery(['loadKbList'], loadKbList); + useQuery(['loadKbList'], () => loadKbList()); return ( diff --git a/client/src/pages/api/admin/initv44.ts b/client/src/pages/api/admin/initv44.ts index 67516745c..f6db795f6 100644 --- a/client/src/pages/api/admin/initv44.ts +++ b/client/src/pages/api/admin/initv44.ts @@ -3,17 +3,24 @@ import type { NextApiRequest, NextApiResponse } from 'next'; import { jsonRes } from '@/service/response'; import { authUser } from '@/service/utils/auth'; import { connectToDatabase, KB } from '@/service/mongo'; -import { KbTypeMap } from '@/constants/kb'; - -const limit = 50; -let success = 0; +import { KbTypeEnum, KbTypeMap } from '@/constants/kb'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { await connectToDatabase(); await authUser({ req, authRoot: true }); - await initKb(); + await KB.updateMany( + { + type: { $exists: false } + }, + { + $set: { + type: KbTypeEnum.dataset, + parentId: null + } + } + ); jsonRes(res, {}); } catch (error) { @@ -23,40 +30,3 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) }); } } - -async function initKb(): Promise { - try { - // 找到所有 type 不存在的 kb - const kbList = await KB.find({ type: { $exists: false } }).limit(limit); - - if (kbList.length === 0) return; - - await Promise.allSettled( - kbList.map(async (kb) => { - let id = ''; - try { - // 创建一组以 kb 的 name,userId 相同文件夹类型的数据 - const result = await KB.create({ - parentId: null, - userId: kb.userId, - avatar: KbTypeMap.folder.avatar, - name: kb.name, - type: 'folder' - }); - id = result._id; - // 将现有的 kb 挂载到这个文件夹下 - await KB.findByIdAndUpdate(kb._id, { - parentId: result._id, - type: 'manualData' - }); - console.log(++success); - } catch (error) { - await KB.findByIdAndDelete(id); - } - }) - ); - return initKb(); - } catch (error) { - return initKb(); - } -} diff --git a/client/src/pages/api/openapi/plugin/vector.ts b/client/src/pages/api/openapi/plugin/vector.ts index 39f2f0dd0..72181e889 100644 --- a/client/src/pages/api/openapi/plugin/vector.ts +++ b/client/src/pages/api/openapi/plugin/vector.ts @@ -68,9 +68,8 @@ export async function getVector({ ) .then(async (res) => { if (!res.data?.data?.[0]?.embedding) { - console.log(res.data); // @ts-ignore - return Promise.reject(res.data?.error?.message || 'Embedding API Error'); + return Promise.reject(res.data?.err?.message || 'Embedding API Error'); } return { tokenLen: res.data.usage.total_tokens || 0, diff --git a/client/src/pages/app/detail/components/AdEdit/components/Nodes/NodeKbSearch.tsx b/client/src/pages/app/detail/components/AdEdit/components/Nodes/NodeKbSearch.tsx index 3606f52c3..ff534e2a9 100644 --- a/client/src/pages/app/detail/components/AdEdit/components/Nodes/NodeKbSearch.tsx +++ b/client/src/pages/app/detail/components/AdEdit/components/Nodes/NodeKbSearch.tsx @@ -1,4 +1,4 @@ -import React, { useMemo, useState } from 'react'; +import React, { useMemo } from 'react'; import { NodeProps } from 'reactflow'; import { FlowModuleItemType } from '@/types/flow'; import { Flex, Box, Button, useTheme, useDisclosure, Grid } from '@chakra-ui/react'; @@ -33,7 +33,7 @@ const KBSelect = ({ [myKbList, activeKbs] ); - useQuery(['initkb'], loadKbList); + useQuery(['initkb'], () => loadKbList()); return ( <> diff --git a/client/src/service/models/bill.ts b/client/src/service/models/bill.ts index a7d953319..2f0731bbc 100644 --- a/client/src/service/models/bill.ts +++ b/client/src/service/models/bill.ts @@ -55,7 +55,6 @@ const BillSchema = new Schema({ try { BillSchema.index({ userId: 1 }); - // BillSchema.index({ time: -1 }); BillSchema.index({ time: 1 }, { expireAfterSeconds: 90 * 24 * 60 }); } catch (error) { console.log(error); diff --git a/client/src/service/pg.ts b/client/src/service/pg.ts index e2d91b9e8..1540268a8 100644 --- a/client/src/service/pg.ts +++ b/client/src/service/pg.ts @@ -13,6 +13,7 @@ export const connectPg = async (): Promise => { connectionString: process.env.PG_URL, max: Number(process.env.DB_MAX_LINK || 5), keepAlive: true, + idleTimeoutMillis: 30000, connectionTimeoutMillis: 5000 }); diff --git a/client/src/store/user.ts b/client/src/store/user.ts index b92b9c68b..c822736ec 100644 --- a/client/src/store/user.ts +++ b/client/src/store/user.ts @@ -26,7 +26,7 @@ type State = { clearAppModules(): void; // kb myKbList: KbListItemType[]; - loadKbList: (parentId: string) => Promise; + loadKbList: (parentId?: string) => Promise; setKbList(val: KbListItemType[]): void; kbDetail: KbItemType; getKbDetail: (id: string, init?: boolean) => Promise;