fix: ts
This commit is contained in:
parent
79e642ebfd
commit
5e6848ce82
@ -32,7 +32,7 @@ const SelectDataset = ({
|
||||
const { myKbList, loadKbList } = useUserStore();
|
||||
const [selectedId, setSelectedId] = useState<string>();
|
||||
|
||||
useQuery(['loadKbList'], loadKbList);
|
||||
useQuery(['loadKbList'], () => loadKbList());
|
||||
|
||||
return (
|
||||
<MyModal isOpen={true} onClose={onClose} w={'100%'} maxW={['90vw', '900px']} isCentered={!isPc}>
|
||||
|
||||
@ -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<any> {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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 (
|
||||
<>
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -13,6 +13,7 @@ export const connectPg = async (): Promise<Pool> => {
|
||||
connectionString: process.env.PG_URL,
|
||||
max: Number(process.env.DB_MAX_LINK || 5),
|
||||
keepAlive: true,
|
||||
idleTimeoutMillis: 30000,
|
||||
connectionTimeoutMillis: 5000
|
||||
});
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ type State = {
|
||||
clearAppModules(): void;
|
||||
// kb
|
||||
myKbList: KbListItemType[];
|
||||
loadKbList: (parentId: string) => Promise<any>;
|
||||
loadKbList: (parentId?: string) => Promise<any>;
|
||||
setKbList(val: KbListItemType[]): void;
|
||||
kbDetail: KbItemType;
|
||||
getKbDetail: (id: string, init?: boolean) => Promise<KbItemType>;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user