Commit da31ef28 by archer

perf: 完善拆分数据模式

parent 60f62507
...@@ -23,8 +23,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) ...@@ -23,8 +23,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
await authToken(authorization); await authToken(authorization);
const dataItems = await DataItem.find({ const dataItems = await DataItem.find({
dataId, dataId
status: 0
}) })
.sort({ _id: -1 }) // 按照创建时间倒序排列 .sort({ _id: -1 }) // 按照创建时间倒序排列
.skip((pageNum - 1) * pageSize) .skip((pageNum - 1) * pageSize)
......
...@@ -86,6 +86,7 @@ export async function generateQA(next = false): Promise<any> { ...@@ -86,6 +86,7 @@ export async function generateQA(next = false): Promise<any> {
await DataItem.findByIdAndUpdate(dataItem._id, { await DataItem.findByIdAndUpdate(dataItem._id, {
status: dataItem.temperature >= 90 ? 0 : 1, // 需要生成 4 组内容。0,0.3,0.6,0.9 status: dataItem.temperature >= 90 ? 0 : 1, // 需要生成 4 组内容。0,0.3,0.6,0.9
temperature: dataItem.temperature >= 90 ? dataItem.temperature : dataItem.temperature + 30, temperature: dataItem.temperature >= 90 ? dataItem.temperature : dataItem.temperature + 30,
rawResponse: content,
$push: { $push: {
result: { result: {
$each: splitResponse $each: splitResponse
...@@ -94,11 +95,17 @@ export async function generateQA(next = false): Promise<any> { ...@@ -94,11 +95,17 @@ export async function generateQA(next = false): Promise<any> {
}); });
// 计费 // 计费
!userApiKey && !userApiKey &&
splitResponse.length > 0 &&
pushSplitDataBill({ pushSplitDataBill({
userId: dataItem.userId, userId: dataItem.userId,
text: systemPrompt.content + dataItem.text + content text: systemPrompt.content + dataItem.text + content
}); });
console.log('生成QA成功,time:', `${(Date.now() - startTime) / 1000}s`); console.log(
'生成QA成功,time:',
`${(Date.now() - startTime) / 1000}s`,
'QA数量:',
splitResponse.length
);
} catch (error: any) { } catch (error: any) {
console.log('error: 生成QA错误', dataItem?._id); console.log('error: 生成QA错误', dataItem?._id);
console.log('response:', error?.response); console.log('response:', error?.response);
......
...@@ -24,6 +24,10 @@ const DataItemSchema = new Schema({ ...@@ -24,6 +24,10 @@ const DataItemSchema = new Schema({
type: Number, type: Number,
required: true required: true
}, },
rawResponse: {
type: [String],
default: ''
},
result: { result: {
type: [ type: [
{ {
......
...@@ -111,6 +111,7 @@ export interface DataItemSchema { ...@@ -111,6 +111,7 @@ export interface DataItemSchema {
times: number; times: number;
temperature: number; temperature: number;
text: string; text: string;
rawResponse: string[];
result: { result: {
q: string; q: string;
a: string; a: string;
......
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