pcm-coordinator/api/internal/logic/ai/createnotebooklogic.go

43 lines
1.4 KiB
Go

package ai
import (
"context"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils"
"gitlink.org.cn/jcce-pcm/pcm-participant-modelarts/modelarts"
"gitlink.org.cn/jcce-pcm/utils/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
type CreateNotebookLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewCreateNotebookLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateNotebookLogic {
return &CreateNotebookLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CreateNotebookLogic) CreateNotebook(req *types.CreateNotebookReq) (resp *types.CreateNotebookResp, err error) {
modelartsReq := &modelarts.CreateNotebookReq{}
err = copier.CopyWithOption(modelartsReq, req, copier.Option{Converters: utils.Converters})
createNotebookResp, err := l.svcCtx.ModelArtsRpc.CreateNotebook(l.ctx, modelartsReq)
if err != nil {
return nil, errors.Wrapf(xerr.NewErrMsg("Failed to create notebook"), "Failed to create notebook err : %v ,req:%+v", err, req)
}
resp = &types.CreateNotebookResp{}
err = copier.CopyWithOption(resp, createNotebookResp, copier.Option{IgnoreEmpty: true, DeepCopy: true, Converters: utils.Converters})
return resp, nil
}