Skip to content
Open
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions backend/modules/evaluation/application/evaluation_set_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ func (e *EvaluationSetApplicationImpl) CreateEvaluationSet(ctx context.Context,
if req == nil {
return nil, errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg("req is nil"))
}
if req.Name == nil {
return nil, errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg("name is nil"))
}
if req.EvaluationSetSchema == nil {
return nil, errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg("schema is nil"))

if err = req.IsValid(); err != nil {
return nil, errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg(err.Error()))
}

// 鉴权
err = e.auth.Authorization(ctx, &rpc.AuthorizationParam{
ObjectID: strconv.FormatInt(req.WorkspaceID, 10),
Expand Down
42 changes: 14 additions & 28 deletions backend/modules/evaluation/application/evaluator_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,23 +219,12 @@ func (e *EvaluatorHandlerImpl) CreateEvaluator(ctx context.Context, request *eva

func (e *EvaluatorHandlerImpl) checkCreateEvaluatorRequest(ctx context.Context, request *evaluatorservice.CreateEvaluatorRequest) (err error) {
if request == nil {
return errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg("req is nil"))
}
if request.Evaluator == nil {
return errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg("evaluator_version is nil"))
}
if request.Evaluator.Name == nil {
return errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg("name is nil"))
}
if request.Evaluator.WorkspaceID == nil {
return errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg("workspace id is nil"))
return errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg("request is nil"))
}
if request.Evaluator.EvaluatorType == nil {
return errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg("evaluator_version type is nil"))
}
if request.Evaluator.CurrentVersion == nil {
return errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg("current version is nil"))
if err = request.IsValid(); err != nil {
return errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg(err.Error()))
}

if request.Evaluator.CurrentVersion.EvaluatorContent == nil {
return errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg("evaluator_version content is nil"))
}
Expand Down Expand Up @@ -324,11 +313,10 @@ func validateUpdateEvaluatorRequest(ctx context.Context, request *evaluatorservi
if request == nil {
return errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg("req is nil"))
}
if request.GetEvaluatorID() == 0 {
return errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg("id is 0"))
}
if request.WorkspaceID == 0 {
return errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg("space id is 0"))

err := request.IsValid()
if err != nil {
return errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg(err.Error()))
}
if utf8.RuneCountInString(request.GetName()) > consts.MaxEvaluatorNameLength {
return errorx.NewByCode(errno.EvaluatorNameExceedMaxLengthCode)
Expand Down Expand Up @@ -566,20 +554,18 @@ func (e *EvaluatorHandlerImpl) SubmitEvaluatorVersion(ctx context.Context, reque
}

func (e *EvaluatorHandlerImpl) validateSubmitEvaluatorVersionRequest(ctx context.Context, request *evaluatorservice.SubmitEvaluatorVersionRequest) error {
if request.GetEvaluatorID() == 0 {
return errorx.NewByCode(errno.InvalidEvaluatorIDCode, errorx.WithExtraMsg("[validateSubmitEvaluatorVersionRequest] evaluator_version id is empty"))
}
if len(request.GetVersion()) == 0 {
return errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg("[validateSubmitEvaluatorVersionRequest] evaluator_version version is empty"))
if err := request.IsValid(); err != nil {
return errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg(err.Error()))
}

if len(request.GetVersion()) > consts.MaxEvaluatorVersionLength {
return errorx.NewByCode(errno.EvaluatorVersionExceedMaxLengthCode)
}
_, err := semver.StrictNewVersion(request.GetVersion())
if err != nil {
if _, err := semver.StrictNewVersion(request.GetVersion()); err != nil {
return errorx.NewByCode(errno.CommonInvalidParamCode, errorx.WithExtraMsg("[validateSubmitEvaluatorVersionRequest] evaluator_version version does not follow SemVer specification"))
}
if len(request.GetDescription()) > consts.MaxEvaluatorVersionDescLength {

if utf8.RuneCountInString(request.GetDescription()) > consts.MaxEvaluatorVersionDescLength {
return errorx.NewByCode(errno.EvaluatorVersionDescriptionExceedMaxLengthCode)
}
// 机审
Expand Down
2 changes: 1 addition & 1 deletion backend/modules/evaluation/application/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 9 additions & 27 deletions backend/modules/llm/application/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import (
"strconv"
"time"



"github.com/coze-dev/cozeloop-go/spec/tracespec"
"github.com/pkg/errors"


"github.com/coze-dev/coze-loop/backend/infra/limiter"
"github.com/coze-dev/coze-loop/backend/infra/looptracer"
"github.com/coze-dev/coze-loop/backend/infra/redis"
Expand All @@ -30,6 +33,8 @@ import (
"github.com/coze-dev/coze-loop/backend/pkg/json"
"github.com/coze-dev/coze-loop/backend/pkg/lang/ptr"
"github.com/coze-dev/coze-loop/backend/pkg/logs"
"github.com/coze-dev/cozeloop-go"
"github.com/coze-dev/cozeloop-go/spec/tracespec"
)

type runtimeApp struct {
Expand All @@ -55,9 +60,10 @@ func NewRuntimeApplication(

func (r *runtimeApp) Chat(ctx context.Context, req *runtime.ChatRequest) (resp *runtime.ChatResponse, err error) {
resp = runtime.NewChatResponse()
if err = r.validateChatReq(ctx, req); err != nil {
if err := req.IsValid(); err != nil {
return resp, errorx.NewByCode(llm_errorx.RequestNotValidCode, errorx.WithExtraMsg(err.Error()))
}

// 1. 模型信息获取
model, err := r.manageSrv.GetModelByID(ctx, req.GetModelConfig().GetModelID())
if err != nil {
Expand Down Expand Up @@ -115,9 +121,10 @@ func (r *runtimeApp) Chat(ctx context.Context, req *runtime.ChatRequest) (resp *

func (r *runtimeApp) ChatStream(ctx context.Context, req *runtime.ChatRequest, stream runtime.LLMRuntimeService_ChatStreamServer) (err error) {
// 参数校验
if err = r.validateChatReq(ctx, req); err != nil {
if err := req.IsValid(); err != nil {
return errorx.NewByCode(llm_errorx.RequestNotValidCode, errorx.WithExtraMsg(err.Error()))
}

// 1. 模型信息获取
model, err := r.manageSrv.GetModelByID(ctx, req.GetModelConfig().GetModelID())
if err != nil {
Expand Down Expand Up @@ -344,28 +351,3 @@ func (r *runtimeApp) setAndFinishSpan(ctx context.Context, span looptracer.Span,
span.SetTags(ctx, tags)
span.Finish(ctx)
}

func (r *runtimeApp) validateChatReq(ctx context.Context, req *runtime.ChatRequest) (err error) {
if req.GetModelConfig() == nil {
return errors.Errorf("model config is required")
}
if len(req.GetMessages()) == 0 {
return errors.Errorf("messages is required")
}
if req.GetBizParam() == nil {
return errors.Errorf("bizParam is required")
}
if !req.GetBizParam().IsSetScenario() {
return errors.Errorf("bizParam.scenario is required")
}
if !req.GetBizParam().IsSetScenarioEntityID() {
return errors.Errorf("bizParam.scenario_entity_id is required")
}
// if !req.GetBizParam().IsSetUserID() {
// return errors.Errorf("bizParam.user_id is required")
// }
if !req.GetBizParam().IsSetWorkspaceID() {
return errors.Errorf("bizParam.workspace_id is required")
}
return nil
}
2 changes: 1 addition & 1 deletion backend/modules/llm/application/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading