updated inference apis

Former-commit-id: d907a498a213be552236b306f48903942d63078d
This commit is contained in:
tzwang 2024-08-27 15:09:58 +08:00
parent 46e3bc064f
commit 5ec517690a
9 changed files with 101 additions and 88 deletions

View File

@ -92,7 +92,7 @@ type (
AiClusterIds []string `form:"aiClusterIds"` AiClusterIds []string `form:"aiClusterIds"`
} }
TextToImageInferenceResp{ TextToImageInferenceResp{
Result []byte Result []byte `json:"result"`
} }
/******************Deploy instance*************************/ /******************Deploy instance*************************/
@ -156,20 +156,12 @@ type (
} }
GetDeployTasksReq {
PageInfo
}
GetDeployTasksResp {
PageResult
}
GetRunningInstanceReq { GetRunningInstanceReq {
AdapterIds []string `form:"adapterIds"` AdapterIds []string `form:"adapterIds"`
ModelType string `form:"modelType"` ModelType string `form:"modelType"`
} }
GetRunningInstanceResp { GetRunningInstanceResp {
List interface{} `json:"list,omitempty"` List interface{} `json:"list"`
} }
GetDeployTasksByTypeReq { GetDeployTasksByTypeReq {
@ -177,6 +169,6 @@ type (
} }
GetDeployTasksByTypeResp { GetDeployTasksByTypeResp {
List interface{} `json:"list,omitempty"` List interface{} `json:"list"`
} }
) )

View File

@ -966,11 +966,11 @@ service pcm {
@handler StopAllByDeployTaskId @handler StopAllByDeployTaskId
post /inference/stopAll (StopAllByDeployTaskIdReq) returns (StopAllByDeployTaskIdResp) post /inference/stopAll (StopAllByDeployTaskIdReq) returns (StopAllByDeployTaskIdResp)
@handler GetDeployTasks @handler GetRunningInstanceByType
get /inference/getDeployTasks (GetDeployTasksReq) returns (GetDeployTasksResp) get /inference/getInstanceByType (GetRunningInstanceReq) returns (GetRunningInstanceResp)
@handler GetRunningInstanceByModel @handler GetDeployTasksByType
get /inference/getInstanceByModel (GetRunningInstanceReq) returns (GetRunningInstanceResp) get /inference/getDeployTasksByType (GetDeployTasksByTypeReq) returns (GetDeployTasksByTypeResp)
} }
@server( @server(

View File

@ -9,16 +9,16 @@ import (
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
) )
func GetDeployTasksHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { func GetDeployTasksByTypeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
var req types.GetDeployTasksReq var req types.GetDeployTasksByTypeReq
if err := httpx.Parse(r, &req); err != nil { if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err) httpx.ErrorCtx(r.Context(), w, err)
return return
} }
l := inference.NewGetDeployTasksLogic(r.Context(), svcCtx) l := inference.NewGetDeployTasksByTypeLogic(r.Context(), svcCtx)
resp, err := l.GetDeployTasks(&req) resp, err := l.GetDeployTasksByType(&req)
if err != nil { if err != nil {
httpx.ErrorCtx(r.Context(), w, err) httpx.ErrorCtx(r.Context(), w, err)
} else { } else {

View File

@ -1,7 +1,6 @@
package inference package inference
import ( import (
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http" "net/http"
"github.com/zeromicro/go-zero/rest/httpx" "github.com/zeromicro/go-zero/rest/httpx"
@ -10,16 +9,20 @@ import (
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
) )
func GetRunningInstanceByModelHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { func GetRunningInstanceByTypeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
var req types.GetRunningInstanceReq var req types.GetRunningInstanceReq
if err := httpx.Parse(r, &req); err != nil { if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err) httpx.ErrorCtx(r.Context(), w, err)
return return
} }
l := inference.NewGetRunningInstanceByModelLogic(r.Context(), svcCtx) l := inference.NewGetRunningInstanceByTypeLogic(r.Context(), svcCtx)
resp, err := l.GetRunningInstanceByModel(&req) resp, err := l.GetRunningInstanceByType(&req)
result.HttpResult(r, w, resp, err) if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
} }
} }

View File

@ -1225,13 +1225,13 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
}, },
{ {
Method: http.MethodGet, Method: http.MethodGet,
Path: "/inference/getDeployTasks", Path: "/inference/getInstanceByType",
Handler: inference.GetDeployTasksHandler(serverCtx), Handler: inference.GetRunningInstanceByTypeHandler(serverCtx),
}, },
{ {
Method: http.MethodGet, Method: http.MethodGet,
Path: "/inference/getInstanceByModel", Path: "/inference/getDeployTasksByType",
Handler: inference.GetRunningInstanceByModelHandler(serverCtx), Handler: inference.GetDeployTasksByTypeHandler(serverCtx),
}, },
}, },
rest.WithPrefix("/pcm/v1"), rest.WithPrefix("/pcm/v1"),

View File

@ -9,21 +9,21 @@ import (
"github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/logx"
) )
type GetDeployTasksLogic struct { type GetDeployTasksByTypeLogic struct {
logx.Logger logx.Logger
ctx context.Context ctx context.Context
svcCtx *svc.ServiceContext svcCtx *svc.ServiceContext
} }
func NewGetDeployTasksLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDeployTasksLogic { func NewGetDeployTasksByTypeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDeployTasksByTypeLogic {
return &GetDeployTasksLogic{ return &GetDeployTasksByTypeLogic{
Logger: logx.WithContext(ctx), Logger: logx.WithContext(ctx),
ctx: ctx, ctx: ctx,
svcCtx: svcCtx, svcCtx: svcCtx,
} }
} }
func (l *GetDeployTasksLogic) GetDeployTasks(req *types.GetDeployTasksReq) (resp *types.GetDeployTasksResp, err error) { func (l *GetDeployTasksByTypeLogic) GetDeployTasksByType(req *types.GetDeployTasksByTypeReq) (resp *types.GetDeployTasksByTypeResp, err error) {
// todo: add your logic here and delete this line // todo: add your logic here and delete this line
return return

View File

@ -1,30 +0,0 @@
package inference
import (
"context"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetRunningInstanceByModelLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetRunningInstanceByModelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRunningInstanceByModelLogic {
return &GetRunningInstanceByModelLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetRunningInstanceByModelLogic) GetRunningInstanceByModel(req *types.GetRunningInstanceReq) (resp *types.GetRunningInstanceResp, err error) {
resp = &types.GetRunningInstanceResp{}
return
}

View File

@ -0,0 +1,30 @@
package inference
import (
"context"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetRunningInstanceByTypeLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetRunningInstanceByTypeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRunningInstanceByTypeLogic {
return &GetRunningInstanceByTypeLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetRunningInstanceByTypeLogic) GetRunningInstanceByType(req *types.GetRunningInstanceReq) (resp *types.GetRunningInstanceResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@ -5904,6 +5904,19 @@ type Category struct {
Name string `json:"name"` Name string `json:"name"`
} }
type DeployInstance struct {
InstanceId string `json:"instanceId"`
InstanceName string `json:"instanceName"`
AdapterId string `json:"adapterId"`
AdapterName string `json:"adapterName"`
ClusterId string `json:"clusterId"`
ClusterName string `json:"clusterName"`
ModelName string `json:"modelName"`
ModelType string `json:"modelType"`
InferCard string `json:"inferCard"`
Status string `json:"status"`
}
type ModelTypesResp struct { type ModelTypesResp struct {
ModelTypes []string `json:"types"` ModelTypes []string `json:"types"`
} }
@ -5917,20 +5930,13 @@ type ModelNamesResp struct {
} }
type ImageInferenceReq struct { type ImageInferenceReq struct {
TaskName string `form:"taskName"` TaskName string `json:"taskName"`
TaskDesc string `form:"taskDesc"` TaskDesc string `json:"taskDesc"`
ModelName string `form:"modelName"` ModelType string `json:"modelType"`
ModelType string `form:"modelType"` Instances []DeployInstance `json:"instances"`
AdapterId string `form:"adapterId"` Strategy string `json:"strategy,,optional"`
AiClusterIds []string `form:"aiClusterIds,optional"` StaticWeightMap map[string]int32 `json:"staticWeightMap,optional"`
ResourceType string `form:"resourceType,optional"` Replica int32 `json:"replicas,optional"`
ComputeCard string `form:"card,optional"`
Strategy string `form:"strategy"`
StaticWeightMap map[string]int32 `form:"staticWeightMap,optional"`
Params []string `form:"params,optional"`
Envs []string `form:"envs,optional"`
Cmd string `form:"cmd,optional"`
Replica int32 `form:"replicas,optional"`
} }
type ImageInferenceResp struct { type ImageInferenceResp struct {
@ -5976,6 +5982,18 @@ type TextToTextInferenceReq struct {
type TextToTextInferenceResp struct { type TextToTextInferenceResp struct {
} }
type TextToImageInferenceReq struct {
TaskName string `form:"taskName"`
TaskDesc string `form:"taskDesc"`
ModelName string `form:"modelName"`
ModelType string `form:"modelType"`
AiClusterIds []string `form:"aiClusterIds"`
}
type TextToImageInferenceResp struct {
Result []byte `json:"result"`
}
type DeployInstanceListReq struct { type DeployInstanceListReq struct {
PageInfo PageInfo
} }
@ -6034,19 +6052,19 @@ type StopAllByDeployTaskIdReq struct {
type StopAllByDeployTaskIdResp struct { type StopAllByDeployTaskIdResp struct {
} }
type GetDeployTasksReq struct {
PageInfo
}
type GetDeployTasksResp struct {
PageResult
}
type GetRunningInstanceReq struct { type GetRunningInstanceReq struct {
ModelType string `path:"modelType"` AdapterIds []string `form:"adapterIds"`
ModelName string `path:"modelName"` ModelType string `form:"modelType"`
} }
type GetRunningInstanceResp struct { type GetRunningInstanceResp struct {
List interface{} `json:"list,omitempty"` List interface{} `json:"list"`
}
type GetDeployTasksByTypeReq struct {
ModelType string `form:"modelType"`
}
type GetDeployTasksByTypeResp struct {
List interface{} `json:"list"`
} }