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
17 changes: 14 additions & 3 deletions backend/modules/evaluation/application/eval_target_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ package application

import (
"context"
"fmt"
"strconv"
"sync"
"time"

"github.com/pkg/errors"

"github.com/bytedance/gg/gmap"
"github.com/bytedance/gg/gptr"

Expand All @@ -27,6 +30,7 @@ import (
"github.com/coze-dev/coze-loop/backend/modules/evaluation/pkg/errno"
"github.com/coze-dev/coze-loop/backend/pkg/errorx"
"github.com/coze-dev/coze-loop/backend/pkg/json"
"github.com/coze-dev/coze-loop/backend/pkg/logs"
)

var _ evaluation.EvalTargetService = &EvalTargetApplicationImpl{}
Expand Down Expand Up @@ -547,9 +551,11 @@ func (e EvalTargetApplicationImpl) DebugEvalTarget(ctx context.Context, request
// return nil, err
// }

logID := logs.GetLogID(ctx)

inputFields := make(map[string]*spi.Content)
if err := json.Unmarshal([]byte(request.GetParam()), &inputFields); err != nil {
return nil, errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg("param json unmarshal fail"))
return nil, errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg(fmt.Sprintf("logid: %s, param json unmarshal fail", logID)))
}

switch request.GetEvalTargetType() {
Expand All @@ -575,14 +581,19 @@ func (e EvalTargetApplicationImpl) DebugEvalTarget(ctx context.Context, request
},
})
if err != nil {
return nil, err
return nil, errors.Wrap(err, fmt.Sprintf("logid: %s", logID))
}
if record != nil && record.Status != nil && *record.Status == entity.EvalTargetRunStatusFail {
if record.EvalTargetOutputData != nil && record.EvalTargetOutputData.EvalTargetRunError != nil {
record.EvalTargetOutputData.EvalTargetRunError.Message = fmt.Sprintf("logid: %s, %s", logID, record.EvalTargetOutputData.EvalTargetRunError.Message)
}
}
return &eval_target.DebugEvalTargetResponse{
EvalTargetRecord: target.EvalTargetRecordDO2DTO(record),
BaseResp: base.NewBaseResp(),
}, err
default:
return nil, errorx.New("unsupported eval target type %v", request.GetEvalTargetType())
return nil, errorx.New("logid: %s, unsupported eval target type %v", logID, request.GetEvalTargetType())
}
}

Expand Down
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 @@ -1043,6 +1043,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 @@ -1241,6 +1246,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
Loading