fix: add instance center of ai

This commit is contained in:
qiwang 2024-09-30 17:03:29 +08:00
parent 016e9a2296
commit 18deae3589
6 changed files with 45 additions and 22 deletions

View File

@ -34,6 +34,9 @@ type (
}
/******************image inference*************************/
/******************instance center*************************/
InstanceCenterReq{
InstanceType int32 `form:"instance_type"`
}
InstanceCenterResp {
InstanceCenterList []InstanceCenterList `json:"instanceCenterList" copier:"InstanceCenterList"`
Code int32 `json:"code,omitempty"`
@ -46,6 +49,7 @@ type (
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"`
}

View File

@ -939,7 +939,7 @@ service pcm {
get /inference/modelTypes returns (ModelTypesResp)
@handler InstanceCenterHandler
get /inference/instanceCenter returns (InstanceCenterResp)
get /inference/instanceCenter (InstanceCenterReq) returns (InstanceCenterResp)
@handler ModelNamesByTypeHandler
get /inference/modelNames (ModelNamesReq) returns (ModelNamesResp)

View File

@ -6,12 +6,19 @@ import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/inference"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
)
func InstanceCenterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
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)
resp, err := l.InstanceCenter()
resp, err := l.InstanceCenter(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {

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
var resp types.InstanceCenterResp
var InstanceCenter *[]models.AiInstanceCenter
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
@ -41,6 +46,7 @@ func (l *InstanceCenterLogic) InstanceCenter() (*types.InstanceCenterResp, error
instanceCenterlist.InstanceType = instanceCenter.InstanceType
instanceCenterlist.InstanceClass = instanceCenter.InstanceClass
instanceCenterlist.Description = instanceCenter.Description
instanceCenterlist.InstanceClassChinese = instanceCenter.InstanceClassChinese
instanceCenterlist.Version = instanceCenter.Version
instanceCenterlist.LogoPath = instanceCenter.LogoPath
InstanceCenterLists = append(InstanceCenterLists, instanceCenterlist)

View File

@ -3656,12 +3656,17 @@ type InputsAlRq 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 {

View File

@ -34,15 +34,16 @@ type (
}
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) {
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
}
func (m *defaultAiInstanceCenterModel) Update(ctx context.Context, data *AiInstanceCenter) error {
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
}