Add unit tests for updateTrainingData API handler and modify dataId to be optional for retrying all error data. (#5194)

Co-authored-by: gru-agent[bot] <185149714+gru-agent[bot]@users.noreply.github.com>
This commit is contained in:
gru-agent[bot]
2025-07-10 18:28:39 +08:00
committed by GitHub
parent 7a6a396f2a
commit 2865419952
2 changed files with 165 additions and 1 deletions

View File

@@ -8,7 +8,7 @@ import { TrainingModeEnum } from '@fastgpt/global/core/dataset/constants';
export type updateTrainingDataBody = {
datasetId: string;
collectionId: string;
dataId: string;
dataId?: string; // 改为可选,不传则重试所有错误数据
q?: string;
a?: string;
chunkIndex?: number;
@@ -31,6 +31,25 @@ async function handler(
per: WritePermissionVal
});
// 如果没有传 dataId则重试该集合下的所有错误数据
if (!dataId) {
await MongoDatasetTraining.updateMany(
{
teamId,
datasetId,
collectionId,
errorMsg: { $exists: true, $ne: null }
},
{
$unset: { errorMsg: '' },
retryCount: 3,
lockTime: new Date('2000')
}
);
return {};
}
// 单个数据重试逻辑
const data = await MongoDatasetTraining.findOne({ teamId, datasetId, _id: dataId });
if (!data) {
@@ -77,3 +96,5 @@ async function handler(
}
export default NextAPI(handler);
export { handler };