Browse Source

fix: add instance center of ai

pull/318/head
qiwang 1 year ago
parent
commit
18deae3589
6 changed files with 45 additions and 22 deletions
  1. +4
    -0
      desc/inference/inference.api
  2. +1
    -1
      desc/pcm.api
  3. +8
    -1
      internal/handler/inference/instancecenterhandler.go
  4. +8
    -2
      internal/logic/inference/instancecenterlogic.go
  5. +11
    -6
      internal/types/types.go
  6. +13
    -12
      pkg/models/aiinstancecentermodel_gen.go

+ 4
- 0
desc/inference/inference.api View File

@@ -34,6 +34,9 @@ type (
} }
/******************image inference*************************/ /******************image inference*************************/
/******************instance center*************************/ /******************instance center*************************/
InstanceCenterReq{
InstanceType int32 `form:"instance_type"`
}
InstanceCenterResp { InstanceCenterResp {
InstanceCenterList []InstanceCenterList `json:"instanceCenterList" copier:"InstanceCenterList"` InstanceCenterList []InstanceCenterList `json:"instanceCenterList" copier:"InstanceCenterList"`
Code int32 `json:"code,omitempty"` Code int32 `json:"code,omitempty"`
@@ -46,6 +49,7 @@ type (
InstanceName string `json:"instance_name"` InstanceName string `json:"instance_name"`
InstanceType int32 `json:"instance_type"` InstanceType int32 `json:"instance_type"`
InstanceClass string `json:"instance_class"` InstanceClass string `json:"instance_class"`
InstanceClassChinese string `json:"instance_class_chinese"`
Description string `json:"description"` Description string `json:"description"`
Version string `json:"version"` Version string `json:"version"`
} }


+ 1
- 1
desc/pcm.api View File

@@ -939,7 +939,7 @@ service pcm {
get /inference/modelTypes returns (ModelTypesResp) get /inference/modelTypes returns (ModelTypesResp)


@handler InstanceCenterHandler @handler InstanceCenterHandler
get /inference/instanceCenter returns (InstanceCenterResp)
get /inference/instanceCenter (InstanceCenterReq) returns (InstanceCenterResp)


@handler ModelNamesByTypeHandler @handler ModelNamesByTypeHandler
get /inference/modelNames (ModelNamesReq) returns (ModelNamesResp) get /inference/modelNames (ModelNamesReq) returns (ModelNamesResp)


+ 8
- 1
internal/handler/inference/instancecenterhandler.go View File

@@ -6,12 +6,19 @@ import (
"github.com/zeromicro/go-zero/rest/httpx" "github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/inference" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/inference"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
) )


func InstanceCenterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { func InstanceCenterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
var req types.InstanceCenterReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}

l := inference.NewInstanceCenterLogic(r.Context(), svcCtx) l := inference.NewInstanceCenterLogic(r.Context(), svcCtx)
resp, err := l.InstanceCenter()
resp, err := l.InstanceCenter(&req)
if err != nil { if err != nil {
httpx.ErrorCtx(r.Context(), w, err) httpx.ErrorCtx(r.Context(), w, err)
} else { } else {


+ 8
- 2
internal/logic/inference/instancecenterlogic.go View File

@@ -24,14 +24,19 @@ func NewInstanceCenterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *In
} }
} }


func (l *InstanceCenterLogic) InstanceCenter() (*types.InstanceCenterResp, error) {
func (l *InstanceCenterLogic) InstanceCenter(req *types.InstanceCenterReq) (*types.InstanceCenterResp, error) {
// todo: add your logic here and delete this line // todo: add your logic here and delete this line
var resp types.InstanceCenterResp var resp types.InstanceCenterResp


var InstanceCenter *[]models.AiInstanceCenter var InstanceCenter *[]models.AiInstanceCenter
var InstanceCenterLists []types.InstanceCenterList var InstanceCenterLists []types.InstanceCenterList


l.svcCtx.DbEngin.Raw("select * from ai_instance_center").Scan(&InstanceCenter)
if req.InstanceType == 0 {
l.svcCtx.DbEngin.Raw("select * from ai_instance_center").Scan(&InstanceCenter)
} else {
l.svcCtx.DbEngin.Raw("select * from ai_instance_center where instance_type = ?", req.InstanceType).Scan(&InstanceCenter)

}


var instanceCenter = *InstanceCenter var instanceCenter = *InstanceCenter


@@ -41,6 +46,7 @@ func (l *InstanceCenterLogic) InstanceCenter() (*types.InstanceCenterResp, error
instanceCenterlist.InstanceType = instanceCenter.InstanceType instanceCenterlist.InstanceType = instanceCenter.InstanceType
instanceCenterlist.InstanceClass = instanceCenter.InstanceClass instanceCenterlist.InstanceClass = instanceCenter.InstanceClass
instanceCenterlist.Description = instanceCenter.Description instanceCenterlist.Description = instanceCenter.Description
instanceCenterlist.InstanceClassChinese = instanceCenter.InstanceClassChinese
instanceCenterlist.Version = instanceCenter.Version instanceCenterlist.Version = instanceCenter.Version
instanceCenterlist.LogoPath = instanceCenter.LogoPath instanceCenterlist.LogoPath = instanceCenter.LogoPath
InstanceCenterLists = append(InstanceCenterLists, instanceCenterlist) InstanceCenterLists = append(InstanceCenterLists, instanceCenterlist)


+ 11
- 6
internal/types/types.go View File

@@ -3656,12 +3656,17 @@ type InputsAlRq struct {
} }


type InstanceCenterList struct { type InstanceCenterList struct {
LogoPath string `json:"logo_path"`
InstanceName string `json:"instance_name"`
InstanceType int32 `json:"instance_type"`
InstanceClass string `json:"instance_class"`
Description string `json:"description"`
Version string `json:"version"`
LogoPath string `json:"logo_path"`
InstanceName string `json:"instance_name"`
InstanceType int32 `json:"instance_type"`
InstanceClass string `json:"instance_class"`
InstanceClassChinese string `json:"instance_class_chinese"`
Description string `json:"description"`
Version string `json:"version"`
}

type InstanceCenterReq struct {
InstanceType int32 `form:"instance_type"`
} }


type InstanceCenterResp struct { type InstanceCenterResp struct {


+ 13
- 12
pkg/models/aiinstancecentermodel_gen.go View File

@@ -34,15 +34,16 @@ type (
} }


AiInstanceCenter struct { AiInstanceCenter struct {
Id int64 `db:"id"` // 平台唯一id
LogoPath string `db:"logo_path"` // logo图像的位置
InstanceName string `db:"instance_name"` // 实例名称
InstanceType int32 `db:"instance_type"` // 实例类型(1是应用实例,2是模型实例)
InstanceClass string `db:"instance_class"` // 实例类别
Description string `db:"description"` // 描述
Version string `db:"version"` // 版本
CreateTime string `db:"create_time"` // 创建时间
UpdateTime string `db:"update_time"` // 更新时间
Id int64 `db:"id"` // 平台唯一id
LogoPath string `db:"logo_path"` // logo图像的位置
InstanceName string `db:"instance_name"` // 实例名称
InstanceType int32 `db:"instance_type"` // 实例类型(1是应用实例,2是模型实例)
InstanceClass string `db:"instance_class"` // 实例类别
InstanceClassChinese string `db:"instance_class_chinese"` // 实例类别中文描述
Description string `db:"description"` // 描述
Version string `db:"version"` // 版本
CreateTime string `db:"create_time"` // 创建时间
UpdateTime string `db:"update_time"` // 更新时间
} }
) )


@@ -74,14 +75,14 @@ func (m *defaultAiInstanceCenterModel) FindOne(ctx context.Context, id int64) (*
} }


func (m *defaultAiInstanceCenterModel) Insert(ctx context.Context, data *AiInstanceCenter) (sql.Result, error) { func (m *defaultAiInstanceCenterModel) Insert(ctx context.Context, data *AiInstanceCenter) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?)", m.table, aiInstanceCenterRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Id, data.LogoPath, data.InstanceName, data.InstanceType, data.InstanceClass, data.Description, data.Version)
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?)", m.table, aiInstanceCenterRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Id, data.LogoPath, data.InstanceName, data.InstanceType, data.InstanceClass, data.InstanceClassChinese, data.Description, data.Version)
return ret, err return ret, err
} }


func (m *defaultAiInstanceCenterModel) Update(ctx context.Context, data *AiInstanceCenter) error { func (m *defaultAiInstanceCenterModel) Update(ctx context.Context, data *AiInstanceCenter) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, aiInstanceCenterRowsWithPlaceHolder) query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, aiInstanceCenterRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, data.LogoPath, data.InstanceName, data.InstanceType, data.InstanceClass, data.Description, data.Version, data.Id)
_, err := m.conn.ExecCtx(ctx, query, data.LogoPath, data.InstanceName, data.InstanceType, data.InstanceClass, data.InstanceClassChinese, data.Description, data.Version, data.Id)
return err return err
} }




Loading…
Cancel
Save