Skip to content
Open

fix #426

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions backend/modules/evaluation/application/evaluator_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,11 @@ func (e *EvaluatorHandlerImpl) DebugEvaluator(ctx context.Context, request *eval
return nil, errorx.NewByCode(errno.EvaluatorBenefitDenyCode)
}

// 检查uri是否正确
err = e.checkURIs(ctx, request.InputData.InputFields)
if err != nil {
return nil, err
}
// URI转换处理
if request.InputData != nil {
err = e.transformURIsToURLs(ctx, request.InputData.InputFields)
Expand Down Expand Up @@ -1238,6 +1243,40 @@ func (e *EvaluatorHandlerImpl) CheckEvaluatorName(ctx context.Context, request *
}, nil
}

func (e *EvaluatorHandlerImpl) checkURIs(ctx context.Context, inputFields map[string]*evaluatorcommon.Content) error {
for _, field := range inputFields {
switch gptr.Indirect(field.ContentType) {
case evaluatorcommon.ContentTypeMultiPart:
return e.checkURIEmpty(ctx, field.MultiPart)
default:
continue
}
}
return nil
}

func (e *EvaluatorHandlerImpl) checkURIEmpty(ctx context.Context, inputFields []*evaluatorcommon.Content) error {
for _, field := range inputFields {
switch gptr.Indirect(field.ContentType) {
case evaluatorcommon.ContentTypeImage:
if field.GetImage() != nil && field.GetImage().GetURI() == "" {
return errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg("image URI is empty"))
}
case evaluatorcommon.ContentTypeAudio:
if field.GetAudio() != nil && field.GetAudio().GetURI() == "" {
return errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg("audio URI is empty"))
}
case evaluatorcommon.ContentTypeVideo:
if field.GetVideo() != nil && field.GetVideo().GetURI() == "" {
return errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg("video URI is empty"))
}
default:
continue
}
}
return nil
}

// transformURIsToURLs 将InputFields中的URI转换为URL
func (e *EvaluatorHandlerImpl) transformURIsToURLs(ctx context.Context, inputFields map[string]*evaluatorcommon.Content) error {
if len(inputFields) == 0 {
Expand Down
14 changes: 14 additions & 0 deletions backend/modules/evaluation/application/evaluator_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5718,3 +5718,17 @@ func TestEvaluatorHandlerImpl_BatchGetEvaluators(t *testing.T) {
})
}
}

//
// func TestName(t *testing.T) {
// inputFields := make(map[string]*evaluatorcommon.Content)
// err := json.Unmarshal([]byte(`{"image":{"content_type":"MultiPart","multi_part":[{"content_type":"Image","image":{"name":"test.jpg","url":"https://gjlv5sbrfw-psl.cn.oast-cn.bytedance.net/realtime_p/ssrf/fuceaabbcc.jpg","uri":"","storage_provider":4}}]}}`), &inputFields)
// if err != nil {
// return
// }
// e := EvaluatorHandlerImpl{}
// err = e.checkURIs(context.Background(), inputFields)
// if err != nil {
// panic(err)
// }
// }
Loading