feat(model): Improve error message when model is not configured.

This commit is contained in:
fanlv 2025-07-25 13:18:52 +08:00
parent f3934ccf62
commit 2e2018af7a
6 changed files with 46 additions and 3 deletions

View File

@ -54,6 +54,7 @@ import (
searchEntity "github.com/coze-dev/coze-studio/backend/domain/search/entity"
search "github.com/coze-dev/coze-studio/backend/domain/search/service"
user "github.com/coze-dev/coze-studio/backend/domain/user/service"
"github.com/coze-dev/coze-studio/backend/infra/contract/modelmgr"
"github.com/coze-dev/coze-studio/backend/infra/contract/storage"
"github.com/coze-dev/coze-studio/backend/pkg/errorx"
"github.com/coze-dev/coze-studio/backend/pkg/lang/conv"
@ -72,6 +73,7 @@ type APPApplicationService struct {
oss storage.Storage
projectEventBus search.ProjectEventBus
modelMgr modelmgr.Manager
userSVC user.User
@ -85,6 +87,15 @@ func (a *APPApplicationService) DraftProjectCreate(ctx context.Context, req *pro
return nil, errorx.New(errno.ErrAppPermissionCode, errorx.KV(errno.APPMsgKey, "session is required"))
}
respModel, err := a.modelMgr.ListInUseModel(ctx, 1, nil)
if err != nil {
return nil, err
}
if len(respModel.ModelList) == 0 {
return nil, errorx.New(errno.ErrAppNoModelInUseCode)
}
appID, err := a.DomainSVC.CreateDraftAPP(ctx, &service.CreateDraftAPPRequest{
SpaceID: req.SpaceID,
OwnerID: *userID,
@ -692,8 +703,8 @@ func (a *APPApplicationService) initTask(ctx context.Context, req *resourceAPI.R
}
func (a *APPApplicationService) handleCopyResult(ctx context.Context, taskID string, newResID int64,
req *resourceAPI.ResourceCopyDispatchRequest, copyErr error) (failedReason string, err error) {
req *resourceAPI.ResourceCopyDispatchRequest, copyErr error,
) (failedReason string, err error) {
resType, err := toResourceType(req.ResType)
if err != nil {
return "", err

View File

@ -34,6 +34,15 @@ import (
)
func (s *SingleAgentApplicationService) CreateSingleAgentDraft(ctx context.Context, req *developer_api.DraftBotCreateRequest) (*developer_api.DraftBotCreateResponse, error) {
resp, err := s.appContext.ModelMgr.ListInUseModel(ctx, 1, nil)
if err != nil {
return nil, err
}
if len(resp.ModelList) == 0 {
return nil, errorx.New(errno.ErrAgentNoModelInUseCode)
}
do, err := s.draftBotCreateRequestToSingleAgent(ctx, req)
if err != nil {
return nil, err

View File

@ -6,6 +6,7 @@ import (
type Manager interface {
ListModel(ctx context.Context, req *ListModelRequest) (*ListModelResponse, error)
ListInUseModel(ctx context.Context, limit int, Cursor *string) (*ListModelResponse, error)
MGetModelByID(ctx context.Context, req *MGetModelRequest) ([]*Model, error)
}

View File

@ -26,6 +26,14 @@ type staticModelManager struct {
modelMapping map[int64]*modelmgr.Model
}
func (s *staticModelManager) ListInUseModel(ctx context.Context, limit int, Cursor *string) (*modelmgr.ListModelResponse, error) {
return s.ListModel(ctx, &modelmgr.ListModelRequest{
Status: []modelmgr.ModelStatus{modelmgr.StatusInUse},
Limit: limit,
Cursor: Cursor,
})
}
func (s *staticModelManager) ListModel(_ context.Context, req *modelmgr.ListModelRequest) (*modelmgr.ListModelResponse, error) {
startIdx := 0
if req.Cursor != nil {

View File

@ -35,9 +35,16 @@ const (
ErrAgentPublishSingleAgentCode = 100000010
ErrAgentAlreadyBindDatabaseCode = 100000011
ErrAgentExecuteErrCode = 100000012
ErrAgentNoModelInUseCode = 100000013
)
func init() {
code.Register(
ErrAgentNoModelInUseCode,
"there is no llm model in use, please config a model first",
code.WithAffectStability(false),
)
code.Register(
ErrAgentPublishSingleAgentCode,
"publish single agent failed",

View File

@ -22,12 +22,19 @@ import "github.com/coze-dev/coze-studio/backend/pkg/errorx/code"
const (
ErrAppInvalidParamCode = 101000000
ErrAppPermissionCode = 101000001
ErrAppRecordNotFound = 109000002
ErrAppRecordNotFound = 101000002
ErrAppNoModelInUseCode = 101000003
)
const APPMsgKey = "msg"
func init() {
code.Register(
ErrAppNoModelInUseCode,
"there is no llm model in use, please config a model first",
code.WithAffectStability(false),
)
code.Register(
ErrAppPermissionCode,
"unauthorized access : {msg}",