feat(task): 添加构建模型名称字段支持动态校验

- 在ModelGatewayTask实体中新增BuildModelName字段
- 修改ParseAndValidate函数参数,支持传入requiredFields
- 在异步工作器中实现构建模型的动态字段校验逻辑
- 添加prompt构建服务中传递构建模型名称的功能
- 实现构建模型不存在时的兜底机制
This commit is contained in:
2026-06-23 14:55:50 +08:00
parent 39b61f1867
commit 525b391f09
4 changed files with 26 additions and 4 deletions

View File

@@ -211,6 +211,24 @@ func (w *asyncWorker) callModel(ctx context.Context, task *entity.ModelGatewayTa
// parseAndRetry 解析模型返回结果,并重试
func (w *asyncWorker) parseAndRetry(ctx context.Context, body map[string]any, task *entity.ModelGatewayTask, model *entity.ModelGatewayModel, req *dto.CreateTaskReq, maxRetry int, startTime time.Time) (map[string]any, error) {
// 0) 如果指定了构建模型,查出校验字段
var requiredFields []string
if task.BuildModelName != "" {
buildModel, _ := dao.ModelGatewayModels.Get(ctx, &entity.ModelGatewayModel{
SQLBaseDO: beans.SQLBaseDO{
TenantId: model.TenantId,
Creator: model.Creator,
},
ModelName: req.ModelName,
})
if buildModel != nil {
requiredFields = buildModel.RequiredFields
}
}
if len(requiredFields) == 0 {
requiredFields = model.RequiredFields // 兜底用当前模型的
}
var lastErr error
for attempt := 0; attempt <= maxRetry; attempt++ {
if attempt > 0 {
@@ -236,11 +254,11 @@ func (w *asyncWorker) parseAndRetry(ctx context.Context, body map[string]any, ta
})
}
// 3) 解析 + 校验
// 3) 解析 + 校验(用 buildModel 的 RequiredFields
var parsed map[string]any
switch req.BuildType {
case public.BuildTypePrompt, public.BuildTypeNode:
parsed, err = util.ParseAndValidate(mapped, model)
parsed, err = util.ParseAndValidate(mapped, requiredFields)
if err == nil {
return parsed, nil
}