From 0e11cbd5f2b43a3c62b11400f04cfbfa72558d71 Mon Sep 17 00:00:00 2001 From: zhouqunjie Date: Sat, 22 Jun 2024 16:20:43 +0800 Subject: [PATCH] task ai sub Former-commit-id: 31fce577fe3f873facd5bde998a56c5d9fe0041f --- api/desc/inference/inference.api | 17 ++++-- api/desc/pcm.api | 3 ++ .../inference/inferencetaskdetailhandler.go | 28 ++++++++++ api/internal/handler/routes.go | 5 ++ .../logic/inference/imageinferencelogic.go | 7 +-- .../inference/inferencetaskdetaillogic.go | 54 +++++++++++++++++++ api/internal/types/types.go | 8 ++- 7 files changed, 113 insertions(+), 9 deletions(-) create mode 100644 api/internal/handler/inference/inferencetaskdetailhandler.go create mode 100644 api/internal/logic/inference/inferencetaskdetaillogic.go diff --git a/api/desc/inference/inference.api b/api/desc/inference/inference.api index e7a04c83..bc7022cd 100644 --- a/api/desc/inference/inference.api +++ b/api/desc/inference/inference.api @@ -45,14 +45,21 @@ type ( } InferenceTaskDetailReq{ - aiTaskId int64 `json:"aiTaskId"` + aiTaskId int64 `form:"aiTaskId"` } InferenceTaskDetailResp{ - imageName string `json:"imageName"` - result string `json:"result"` - card string `json:"card"` - clusterName string `json:"clusterName"` + InferenceResults []InferenceResult `json:"inferenceResults"` + Code int32 `json:"code,omitempty"` + Msg string `json:"msg,omitempty"` + + } + + InferenceResult{ + imageName string `json:"imageName"` + result string `json:"result"` + card string `json:"card"` + clusterName string `json:"clusterName"` } ) diff --git a/api/desc/pcm.api b/api/desc/pcm.api index 85d2f768..b912fda9 100644 --- a/api/desc/pcm.api +++ b/api/desc/pcm.api @@ -915,6 +915,9 @@ service pcm { @handler ModelNamesByTypeHandler get /inference/modelNames (ModelNamesReq) returns (ModelNamesResp) + + @handler InferenceTaskDetailHandler + get /inference/taskDetail (InferenceTaskDetailReq) returns (InferenceTaskDetailResp) } @server( diff --git a/api/internal/handler/inference/inferencetaskdetailhandler.go b/api/internal/handler/inference/inferencetaskdetailhandler.go new file mode 100644 index 00000000..a1f5a30f --- /dev/null +++ b/api/internal/handler/inference/inferencetaskdetailhandler.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 InferenceTaskDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.InferenceTaskDetailReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := inference.NewInferenceTaskDetailLogic(r.Context(), svcCtx) + resp, err := l.InferenceTaskDetail(&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 081c4d85..e04c7750 100644 --- a/api/internal/handler/routes.go +++ b/api/internal/handler/routes.go @@ -1153,6 +1153,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/inference/modelNames", Handler: inference.ModelNamesByTypeHandler(serverCtx), }, + { + Method: http.MethodGet, + Path: "/inference/taskDetail", + Handler: inference.InferenceTaskDetailHandler(serverCtx), + }, }, rest.WithPrefix("/pcm/v1"), ) diff --git a/api/internal/logic/inference/imageinferencelogic.go b/api/internal/logic/inference/imageinferencelogic.go index c8f2e247..b526ee04 100644 --- a/api/internal/logic/inference/imageinferencelogic.go +++ b/api/internal/logic/inference/imageinferencelogic.go @@ -43,9 +43,10 @@ func NewImageInferenceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Im } } -func (l *ImageInferenceLogic) ImageInference(req *types.ImageInferenceReq) (resp *types.ImageInferenceResp, err error) { - return nil, nil -} +// +//func (l *ImageInferenceLogic) ImageInference(req *types.ImageInferenceReq) (resp *types.ImageInferenceResp, err error) { +// return nil, nil +//} func (l *ImageInferenceLogic) ImageInfer(r *http.Request, req *types.ImageInferenceReq) (resp *types.ImageInferenceResp, err error) { resp = &types.ImageInferenceResp{} diff --git a/api/internal/logic/inference/inferencetaskdetaillogic.go b/api/internal/logic/inference/inferencetaskdetaillogic.go new file mode 100644 index 00000000..fde975db --- /dev/null +++ b/api/internal/logic/inference/inferencetaskdetaillogic.go @@ -0,0 +1,54 @@ +package inference + +import ( + "context" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models" + + "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 InferenceTaskDetailLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewInferenceTaskDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InferenceTaskDetailLogic { + return &InferenceTaskDetailLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *InferenceTaskDetailLogic) InferenceTaskDetail(req *types.InferenceTaskDetailReq) (resp *types.InferenceTaskDetailResp, err error) { + // todo: add your logic here and delete this line + var taskAiSub []*models.TaskAiSub + var results []types.InferenceResult + l.svcCtx.DbEngin.Table("task_ai_sub").Where("id", req.AiTaskId).Scan(&taskAiSub) + + if len(taskAiSub) != 0 { + for _, sub := range taskAiSub { + result := types.InferenceResult{ + ImageName: sub.ImageName, + Result: sub.Result, + Card: sub.Card, + ClusterName: sub.ClusterName, + } + results = append(results, result) + } + } else { + return nil, nil + } + + resp = &types.InferenceTaskDetailResp{ + Code: 200, + Msg: "success", + InferenceResults: results, + } + + return resp, nil +} diff --git a/api/internal/types/types.go b/api/internal/types/types.go index 1e632bd3..47f9e358 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -5921,10 +5921,16 @@ type ImageResult struct { } type InferenceTaskDetailReq struct { - AiTaskId int64 `json:"aiTaskId"` + AiTaskId int64 `form:"aiTaskId"` } type InferenceTaskDetailResp struct { + InferenceResults []InferenceResult `json:"inferenceResults"` + Code int32 `json:"code,omitempty"` + Msg string `json:"msg,omitempty"` +} + +type InferenceResult struct { ImageName string `json:"imageName"` Result string `json:"result"` Card string `json:"card"`