From 63e63031527c348993a120eca37e01aa64339556 Mon Sep 17 00:00:00 2001 From: tzwang Date: Fri, 21 Jun 2024 15:20:46 +0800 Subject: [PATCH] added modeltypes api Former-commit-id: 5640bcde2019a2a174dbe84af5d802da2d1a4d99 --- api/desc/inference/inference.api | 13 ++++++++ api/desc/pcm.api | 6 ++++ .../inference/modelnamesbytypehandler.go | 28 +++++++++++++++++ .../handler/inference/modeltypeshandler.go | 21 +++++++++++++ api/internal/handler/routes.go | 10 +++++++ .../logic/inference/modelnamesbytypelogic.go | 30 +++++++++++++++++++ .../logic/inference/modeltypeslogic.go | 30 +++++++++++++++++++ api/internal/types/types.go | 12 ++++++++ 8 files changed, 150 insertions(+) create mode 100644 api/internal/handler/inference/modelnamesbytypehandler.go create mode 100644 api/internal/handler/inference/modeltypeshandler.go create mode 100644 api/internal/logic/inference/modelnamesbytypelogic.go create mode 100644 api/internal/logic/inference/modeltypeslogic.go diff --git a/api/desc/inference/inference.api b/api/desc/inference/inference.api index c8b6b8da..86b3ad0e 100644 --- a/api/desc/inference/inference.api +++ b/api/desc/inference/inference.api @@ -2,6 +2,18 @@ syntax = "v1" type ( /******************image inference*************************/ + ModelTypesResp { + ModelTypes []string `json:"types"` + } + + ModelNamesReq { + Type string `form:"type"` + } + + ModelNamesResp { + ModelNames []string `json:"models"` + } + /******************image inference*************************/ ImageInferenceReq { TaskName string `form:"taskName"` @@ -31,4 +43,5 @@ type ( Card string `json:"card"` ImageResult string `json:"imageResult"` } + ) diff --git a/api/desc/pcm.api b/api/desc/pcm.api index 982b3d86..85d2f768 100644 --- a/api/desc/pcm.api +++ b/api/desc/pcm.api @@ -909,6 +909,12 @@ service pcm { service pcm { @handler ImageInferenceHandler post /inference/images (ImageInferenceReq) returns (ImageInferenceResp) + + @handler ModelTypesHandler + get /inference/modelTypes returns (ModelTypesResp) + + @handler ModelNamesByTypeHandler + get /inference/modelNames (ModelNamesReq) returns (ModelNamesResp) } @server( diff --git a/api/internal/handler/inference/modelnamesbytypehandler.go b/api/internal/handler/inference/modelnamesbytypehandler.go new file mode 100644 index 00000000..18f872b9 --- /dev/null +++ b/api/internal/handler/inference/modelnamesbytypehandler.go @@ -0,0 +1,28 @@ +package inference + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/inference" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" +) + +func ModelNamesByTypeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.ModelNamesReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := inference.NewModelNamesByTypeLogic(r.Context(), svcCtx) + resp, err := l.ModelNamesByType(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/api/internal/handler/inference/modeltypeshandler.go b/api/internal/handler/inference/modeltypeshandler.go new file mode 100644 index 00000000..81684459 --- /dev/null +++ b/api/internal/handler/inference/modeltypeshandler.go @@ -0,0 +1,21 @@ +package inference + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/inference" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" +) + +func ModelTypesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + l := inference.NewModelTypesLogic(r.Context(), svcCtx) + resp, err := l.ModelTypes() + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/api/internal/handler/routes.go b/api/internal/handler/routes.go index 94a504ca..081c4d85 100644 --- a/api/internal/handler/routes.go +++ b/api/internal/handler/routes.go @@ -1143,6 +1143,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/inference/images", Handler: inference.ImageInferenceHandler(serverCtx), }, + { + Method: http.MethodGet, + Path: "/inference/modelTypes", + Handler: inference.ModelTypesHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/inference/modelNames", + Handler: inference.ModelNamesByTypeHandler(serverCtx), + }, }, rest.WithPrefix("/pcm/v1"), ) diff --git a/api/internal/logic/inference/modelnamesbytypelogic.go b/api/internal/logic/inference/modelnamesbytypelogic.go new file mode 100644 index 00000000..09e24a0e --- /dev/null +++ b/api/internal/logic/inference/modelnamesbytypelogic.go @@ -0,0 +1,30 @@ +package inference + +import ( + "context" + + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ModelNamesByTypeLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewModelNamesByTypeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ModelNamesByTypeLogic { + return &ModelNamesByTypeLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *ModelNamesByTypeLogic) ModelNamesByType(req *types.ModelNamesReq) (resp *types.ModelNamesResp, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/api/internal/logic/inference/modeltypeslogic.go b/api/internal/logic/inference/modeltypeslogic.go new file mode 100644 index 00000000..9bb60999 --- /dev/null +++ b/api/internal/logic/inference/modeltypeslogic.go @@ -0,0 +1,30 @@ +package inference + +import ( + "context" + + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ModelTypesLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewModelTypesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ModelTypesLogic { + return &ModelTypesLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *ModelTypesLogic) ModelTypes() (resp *types.ModelTypesResp, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/api/internal/types/types.go b/api/internal/types/types.go index b92be857..5aea737a 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -5879,6 +5879,18 @@ type Category struct { Name string `json:"name"` } +type ModelTypesResp struct { + ModelTypes []string `json:"types"` +} + +type ModelNamesReq struct { + Type string `form:"type"` +} + +type ModelNamesResp struct { + ModelNames []string `json:"models"` +} + type ImageInferenceReq struct { TaskName string `form:"taskName"` TaskDesc string `form:"taskDesc"`