Skip to content

Commit 7fa48aa

Browse files
tpfztpfz
authored andcommitted
[feat][evaluation]fix aggr (#388)
* fix annotation aggr * fix 乐观锁 * fix trajectory --------- Co-authored-by: tpfz <tpfz@bytedance.com>
1 parent 7b55b9c commit 7fa48aa

13 files changed

Lines changed: 1034 additions & 9 deletions

File tree

backend/kitex_gen/coze/loop/evaluation/expt/coze.loop.evaluation.expt.go

Lines changed: 79 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/kitex_gen/coze/loop/evaluation/expt/k-coze.loop.evaluation.expt.go

Lines changed: 53 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/modules/evaluation/application/experiment_app.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ func (e *experimentApplication) BatchGetExperimentResult_(ctx context.Context, r
742742
BaseExptID: req.BaselineExperimentID,
743743
Page: page,
744744
UseAccelerator: req.GetUseAccelerator(),
745+
FullTrajectory: req.GetFullTrajectory(),
745746
}
746747
if err = buildExptTurnResultFilter(req, param); err != nil {
747748
return nil, err

backend/modules/evaluation/domain/entity/expt_result.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ type MGetExperimentResultParam struct {
330330
FilterAccelerators map[int64]*ExptTurnResultFilterAccelerator
331331
UseAccelerator bool
332332
Page Page
333+
// FullTrajectory 表示在构建 eval_target_result 时是否需要包含轨迹(trajectory)相关信息
334+
FullTrajectory bool
333335
}
334336

335337
type MGetExperimentReportResult struct {

backend/modules/evaluation/domain/service/expt_result_aggr_impl.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,30 @@ func (e *ExptAggrResultServiceImpl) CreateAnnotationAggrResult(ctx context.Conte
563563
return errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg("invalid field type"))
564564
}
565565

566+
// 检查 ExptAggrResult 记录是否已存在,如果存在则走 Update 逻辑
567+
exptAggrRes, err := e.exptAggrResultRepo.GetExptAggrResult(ctx, param.ExperimentID, int32(entity.FieldType_Annotation), param.FieldKey)
568+
if err == nil && exptAggrRes != nil {
569+
// 记录已存在,转换为 UpdateExptAggrResultParam 并调用 UpdateAnnotationAggrResult
570+
logs.CtxInfo(ctx, "create annotation aggr result already exists, updating, experiment_id: %d, field_type: %s, field_key: %s", param.ExperimentID, param.FieldType, param.FieldKey)
571+
updateParam := &entity.UpdateExptAggrResultParam{
572+
SpaceID: param.SpaceID,
573+
ExperimentID: param.ExperimentID,
574+
FieldType: param.FieldType,
575+
FieldKey: param.FieldKey,
576+
}
577+
return e.UpdateAnnotationAggrResult(ctx, updateParam)
578+
}
579+
580+
// 如果错误不是 ResourceNotFound,则返回错误
581+
statusErr, ok := errorx.FromStatusError(err)
582+
if ok && statusErr.Code() == errno.ResourceNotFoundCode {
583+
// 记录不存在,继续原有的 create 逻辑
584+
logs.CtxInfo(ctx, "create annotation aggr result doesn't exist, experiment_id: %d, field_type: %s, field_key: %s", param.ExperimentID, param.FieldType, param.FieldKey)
585+
} else {
586+
// 其他错误,直接返回
587+
return err
588+
}
589+
566590
tagKeyID, err := strconv.ParseInt(param.FieldKey, 10, 64)
567591
if err != nil {
568592
return err

0 commit comments

Comments
 (0)