pcm-modelarts/internal/logic/modelartsservice/showmodelslogic.go

55 lines
1.3 KiB
Go

package modelartsservicelogic
/*
desc: "AI core微服务"
author: "xie"
*/
import (
"context"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-modelarts/internal/svc"
"gitlink.org.cn/JointCloud/pcm-modelarts/internal/util"
"gitlink.org.cn/JointCloud/pcm-modelarts/modelarts"
"k8s.io/apimachinery/pkg/util/json"
)
type ShowModelsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewShowModelsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowModelsLogic {
return &ShowModelsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *ShowModelsLogic) ShowModels(in *modelarts.ShowModelReq) (*modelarts.ShowModelResp, error) {
var resp modelarts.ShowModelResp
platform, err := util.GetModelArtsConfWithPlatform(l.svcCtx.Config.ModelArtsConf.Platform)
if err != nil {
return nil, err
}
body, err := util.SendRequest("GET", platform.Endpoint+"v1/"+platform.ProjectId+"/models/"+in.ModelId,
nil, l.svcCtx.Config.ModelArtsConf.Platform)
if err != nil {
return nil, err
}
json.Unmarshal(*body, &resp.ShowModelDetail)
if resp.ShowModelDetail.ModelId != "" {
resp.Code = 200
resp.Msg = "Success"
} else {
resp.Code = 201
resp.Msg = "find Models is nil"
}
return &resp, nil
}