diff --git a/api/desc/inference/inference.api b/api/desc/inference/inference.api new file mode 100644 index 00000000..8e5b5340 --- /dev/null +++ b/api/desc/inference/inference.api @@ -0,0 +1,40 @@ +syntax = "v1" + +type ( + InferOption { + TaskName string `json:"taskName"` + Images []string `form:"images"` + // AdapterId string `json:"adapterId"` + // AiClusterIds []string `json:"aiClusterIds"` + // ResourceType string `json:"resourceType"` + // ComputeCard string `json:"card"` + // Tops float64 `json:"Tops,optional"` + // TaskType string `json:"taskType"` + // Datasets string `json:"datasets"` + // Algorithm string `json:"algorithm"` + // Strategy string `json:"strategy"` + // StaticWeightMap map[string]int32 `json:"staticWeightMap,optional"` + // Params []string `json:"params,optional"` + // Envs []string `json:"envs,optional"` + // Cmd string `json:"cmd,optional"` + // Replica int32 `json:"replicas"` + } + /******************image inference*************************/ + + ImageInferenceReq { + InferOption *InferOption `json:"inferOption,optional"` + } + + ImageInferenceResp { + } + +// InferResult { +// ClusterId string `json:"clusterId"` +// TaskId string `json:"taskId"` +// Card string `json:"card"` +// Strategy string `json:"strategy"` +// JobId string `json:"jobId"` +// Replica int32 `json:"replica"` +// Msg string `json:"msg"` +// } +) diff --git a/api/desc/pcm.api b/api/desc/pcm.api index be94f6eb..982b3d86 100644 --- a/api/desc/pcm.api +++ b/api/desc/pcm.api @@ -10,6 +10,7 @@ import ( "storelink/pcm-storelink.api" "schedule/pcm-schedule.api" "monitoring/pcm-monitoring.api" + "inference/inference.api" ) info( @@ -901,6 +902,15 @@ service pcm { get /schedule/getClusterBalanceById/:adapterId/:clusterId (GetClusterBalanceByIdReq) returns (GetClusterBalanceByIdResp) } +@server( + prefix: pcm/v1 + group: inference +) +service pcm { + @handler ImageInferenceHandler + post /inference/images (ImageInferenceReq) returns (ImageInferenceResp) +} + @server( prefix: pcm/v1 group: dictionary diff --git a/api/internal/handler/inference/imageinferencehandler.go b/api/internal/handler/inference/imageinferencehandler.go new file mode 100644 index 00000000..d617c790 --- /dev/null +++ b/api/internal/handler/inference/imageinferencehandler.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 ImageInferenceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.ImageInferenceReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := inference.NewImageInferenceLogic(r.Context(), svcCtx) + resp, err := l.ImageInference(&req) + 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 c8aecb33..94a504ca 100644 --- a/api/internal/handler/routes.go +++ b/api/internal/handler/routes.go @@ -10,6 +10,7 @@ import ( core "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/core" dictionary "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/dictionary" hpc "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/hpc" + inference "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/inference" monitoring "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/monitoring" schedule "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/schedule" storage "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/storage" @@ -1135,6 +1136,17 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { rest.WithPrefix("/pcm/v1"), ) + server.AddRoutes( + []rest.Route{ + { + Method: http.MethodPost, + Path: "/inference/images", + Handler: inference.ImageInferenceHandler(serverCtx), + }, + }, + rest.WithPrefix("/pcm/v1"), + ) + server.AddRoutes( []rest.Route{ { diff --git a/api/internal/logic/inference/imageinferencelogic.go b/api/internal/logic/inference/imageinferencelogic.go new file mode 100644 index 00000000..0a1f9d3e --- /dev/null +++ b/api/internal/logic/inference/imageinferencelogic.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 ImageInferenceLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewImageInferenceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ImageInferenceLogic { + return &ImageInferenceLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *ImageInferenceLogic) ImageInference(req *types.ImageInferenceReq) (resp *types.ImageInferenceResp, 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 8c9b254a..56bfa68f 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -5878,3 +5878,15 @@ type Link struct { type Category struct { Name string `json:"name"` } + +type InferOption struct { + TaskName string `json:"taskName"` + Images []string `form:"images"` +} + +type ImageInferenceReq struct { + InferOption *InferOption `json:"inferOption,optional"` +} + +type ImageInferenceResp struct { +}