feat: 摘要拆分

This commit is contained in:
archer
2023-03-26 22:09:59 +08:00
parent 888642f154
commit 3e4487ad9a
20 changed files with 397 additions and 83 deletions

View File

@@ -2,11 +2,12 @@ import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@/service/response';
import { connectToDatabase, Data } from '@/service/mongo';
import { authToken } from '@/service/utils/tools';
import type { DataType } from '@/types/data';
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
let { name } = req.query as { name: string };
if (!name) {
let { name, type } = req.body as { name: string; type: DataType };
if (!name || !type) {
throw new Error('参数错误');
}
await connectToDatabase();
@@ -18,7 +19,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
// 生成 data 集合
const data = await Data.create({
userId,
name
name,
type
});
jsonRes(res, {

View File

@@ -1,9 +1,11 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@/service/response';
import { connectToDatabase, Data, DataItem } from '@/service/mongo';
import { connectToDatabase, DataItem, Data } from '@/service/mongo';
import { authToken } from '@/service/utils/tools';
import { generateQA } from '@/service/events/generateQA';
import { generateAbstract } from '@/service/events/generateAbstract';
/* 拆分数据成QA */
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
let { text, dataId } = req.body as { text: string; dataId: string };
@@ -17,14 +19,20 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const userId = await authToken(authorization);
const DataRecord = await Data.findById(dataId);
if (!DataRecord) {
throw new Error('找不到数据集');
}
const dataItems: any[] = [];
// 格式化文本长度
// 每 1000 字符一组
for (let i = 0; i <= text.length / 1000; i++) {
dataItems.push({
temperature: 0,
userId,
dataId,
type: DataRecord.type,
text: text.slice(i * 1000, (i + 1) * 1000),
status: 1
});
@@ -33,10 +41,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
// 批量插入数据
await DataItem.insertMany(dataItems);
generateQA();
try {
generateQA();
generateAbstract();
} catch (error) {
error;
}
jsonRes(res, {
data: dataItems.length
data: ''
});
} catch (err) {
jsonRes(res, {

View File

@@ -13,14 +13,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
// await DataItem.updateMany(
// {},
// {
// times: 2
// type: 'QA'
// // times: 2
// }
// );
await Data.updateMany(
{},
{
isDeleted: false
type: 'QA'
}
);