From 5ec517690ae7a8ec79cdfc1ce5bf9184e5b8dd11 Mon Sep 17 00:00:00 2001 From: tzwang Date: Tue, 27 Aug 2024 15:09:58 +0800 Subject: [PATCH] updated inference apis Former-commit-id: d907a498a213be552236b306f48903942d63078d --- desc/inference/inference.api | 14 +--- desc/pcm.api | 8 +-- ...dler.go => getdeploytasksbytypehandler.go} | 8 +-- ....go => getrunninginstancebytypehandler.go} | 15 ++-- internal/handler/routes.go | 8 +-- ...slogic.go => getdeploytasksbytypelogic.go} | 8 +-- .../getrunninginstancebymodellogic.go | 30 -------- .../getrunninginstancebytypelogic.go | 30 ++++++++ internal/types/types.go | 68 ++++++++++++------- 9 files changed, 101 insertions(+), 88 deletions(-) rename internal/handler/inference/{getdeploytaskshandler.go => getdeploytasksbytypehandler.go} (70%) rename internal/handler/inference/{getrunninginstancebymodelhandler.go => getrunninginstancebytypehandler.go} (55%) rename internal/logic/inference/{getdeploytaskslogic.go => getdeploytasksbytypelogic.go} (54%) delete mode 100644 internal/logic/inference/getrunninginstancebymodellogic.go create mode 100644 internal/logic/inference/getrunninginstancebytypelogic.go diff --git a/desc/inference/inference.api b/desc/inference/inference.api index 272f318c..63a5e21d 100644 --- a/desc/inference/inference.api +++ b/desc/inference/inference.api @@ -92,7 +92,7 @@ type ( AiClusterIds []string `form:"aiClusterIds"` } TextToImageInferenceResp{ - Result []byte + Result []byte `json:"result"` } /******************Deploy instance*************************/ @@ -156,20 +156,12 @@ type ( } - GetDeployTasksReq { - PageInfo - } - - GetDeployTasksResp { - PageResult - } - GetRunningInstanceReq { AdapterIds []string `form:"adapterIds"` ModelType string `form:"modelType"` } GetRunningInstanceResp { - List interface{} `json:"list,omitempty"` + List interface{} `json:"list"` } GetDeployTasksByTypeReq { @@ -177,6 +169,6 @@ type ( } GetDeployTasksByTypeResp { - List interface{} `json:"list,omitempty"` + List interface{} `json:"list"` } ) diff --git a/desc/pcm.api b/desc/pcm.api index 6eacc710..421604fc 100644 --- a/desc/pcm.api +++ b/desc/pcm.api @@ -966,11 +966,11 @@ service pcm { @handler StopAllByDeployTaskId post /inference/stopAll (StopAllByDeployTaskIdReq) returns (StopAllByDeployTaskIdResp) - @handler GetDeployTasks - get /inference/getDeployTasks (GetDeployTasksReq) returns (GetDeployTasksResp) + @handler GetRunningInstanceByType + get /inference/getInstanceByType (GetRunningInstanceReq) returns (GetRunningInstanceResp) - @handler GetRunningInstanceByModel - get /inference/getInstanceByModel (GetRunningInstanceReq) returns (GetRunningInstanceResp) + @handler GetDeployTasksByType + get /inference/getDeployTasksByType (GetDeployTasksByTypeReq) returns (GetDeployTasksByTypeResp) } @server( diff --git a/internal/handler/inference/getdeploytaskshandler.go b/internal/handler/inference/getdeploytasksbytypehandler.go similarity index 70% rename from internal/handler/inference/getdeploytaskshandler.go rename to internal/handler/inference/getdeploytasksbytypehandler.go index ef6aeeea..1d40c870 100644 --- a/internal/handler/inference/getdeploytaskshandler.go +++ b/internal/handler/inference/getdeploytasksbytypehandler.go @@ -9,16 +9,16 @@ import ( "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) { - var req types.GetDeployTasksReq + var req types.GetDeployTasksByTypeReq if err := httpx.Parse(r, &req); err != nil { httpx.ErrorCtx(r.Context(), w, err) return } - l := inference.NewGetDeployTasksLogic(r.Context(), svcCtx) - resp, err := l.GetDeployTasks(&req) + l := inference.NewGetDeployTasksByTypeLogic(r.Context(), svcCtx) + resp, err := l.GetDeployTasksByType(&req) if err != nil { httpx.ErrorCtx(r.Context(), w, err) } else { diff --git a/internal/handler/inference/getrunninginstancebymodelhandler.go b/internal/handler/inference/getrunninginstancebytypehandler.go similarity index 55% rename from internal/handler/inference/getrunninginstancebymodelhandler.go rename to internal/handler/inference/getrunninginstancebytypehandler.go index 8075a73e..cf342f0f 100644 --- a/internal/handler/inference/getrunninginstancebymodelhandler.go +++ b/internal/handler/inference/getrunninginstancebytypehandler.go @@ -1,7 +1,6 @@ package inference import ( - "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" "net/http" "github.com/zeromicro/go-zero/rest/httpx" @@ -10,16 +9,20 @@ import ( "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) { var req types.GetRunningInstanceReq if err := httpx.Parse(r, &req); err != nil { - result.ParamErrorResult(r, w, err) + httpx.ErrorCtx(r.Context(), w, err) return } - l := inference.NewGetRunningInstanceByModelLogic(r.Context(), svcCtx) - resp, err := l.GetRunningInstanceByModel(&req) - result.HttpResult(r, w, resp, err) + l := inference.NewGetRunningInstanceByTypeLogic(r.Context(), svcCtx) + resp, err := l.GetRunningInstanceByType(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } } } diff --git a/internal/handler/routes.go b/internal/handler/routes.go index c317a876..c9524f9d 100644 --- a/internal/handler/routes.go +++ b/internal/handler/routes.go @@ -1225,13 +1225,13 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { }, { Method: http.MethodGet, - Path: "/inference/getDeployTasks", - Handler: inference.GetDeployTasksHandler(serverCtx), + Path: "/inference/getInstanceByType", + Handler: inference.GetRunningInstanceByTypeHandler(serverCtx), }, { Method: http.MethodGet, - Path: "/inference/getInstanceByModel", - Handler: inference.GetRunningInstanceByModelHandler(serverCtx), + Path: "/inference/getDeployTasksByType", + Handler: inference.GetDeployTasksByTypeHandler(serverCtx), }, }, rest.WithPrefix("/pcm/v1"), diff --git a/internal/logic/inference/getdeploytaskslogic.go b/internal/logic/inference/getdeploytasksbytypelogic.go similarity index 54% rename from internal/logic/inference/getdeploytaskslogic.go rename to internal/logic/inference/getdeploytasksbytypelogic.go index 1f545613..d81a92e2 100644 --- a/internal/logic/inference/getdeploytaskslogic.go +++ b/internal/logic/inference/getdeploytasksbytypelogic.go @@ -9,21 +9,21 @@ import ( "github.com/zeromicro/go-zero/core/logx" ) -type GetDeployTasksLogic struct { +type GetDeployTasksByTypeLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } -func NewGetDeployTasksLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDeployTasksLogic { - return &GetDeployTasksLogic{ +func NewGetDeployTasksByTypeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDeployTasksByTypeLogic { + return &GetDeployTasksByTypeLogic{ Logger: logx.WithContext(ctx), ctx: ctx, 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 return diff --git a/internal/logic/inference/getrunninginstancebymodellogic.go b/internal/logic/inference/getrunninginstancebymodellogic.go deleted file mode 100644 index 1e598dad..00000000 --- a/internal/logic/inference/getrunninginstancebymodellogic.go +++ /dev/null @@ -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 -} diff --git a/internal/logic/inference/getrunninginstancebytypelogic.go b/internal/logic/inference/getrunninginstancebytypelogic.go new file mode 100644 index 00000000..fc2c1c63 --- /dev/null +++ b/internal/logic/inference/getrunninginstancebytypelogic.go @@ -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 +} diff --git a/internal/types/types.go b/internal/types/types.go index d0124b66..30bcf2ef 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -5904,6 +5904,19 @@ type Category struct { 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 { ModelTypes []string `json:"types"` } @@ -5917,20 +5930,13 @@ type ModelNamesResp struct { } type ImageInferenceReq struct { - TaskName string `form:"taskName"` - TaskDesc string `form:"taskDesc"` - ModelName string `form:"modelName"` - ModelType string `form:"modelType"` - AdapterId string `form:"adapterId"` - AiClusterIds []string `form:"aiClusterIds,optional"` - ResourceType string `form:"resourceType,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"` + TaskName string `json:"taskName"` + TaskDesc string `json:"taskDesc"` + ModelType string `json:"modelType"` + Instances []DeployInstance `json:"instances"` + Strategy string `json:"strategy,,optional"` + StaticWeightMap map[string]int32 `json:"staticWeightMap,optional"` + Replica int32 `json:"replicas,optional"` } type ImageInferenceResp struct { @@ -5976,6 +5982,18 @@ type TextToTextInferenceReq 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 { PageInfo } @@ -6034,19 +6052,19 @@ type StopAllByDeployTaskIdReq struct { type StopAllByDeployTaskIdResp struct { } -type GetDeployTasksReq struct { - PageInfo -} - -type GetDeployTasksResp struct { - PageResult -} - type GetRunningInstanceReq struct { - ModelType string `path:"modelType"` - ModelName string `path:"modelName"` + AdapterIds []string `form:"adapterIds"` + ModelType string `form:"modelType"` } 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"` }