diff --git a/api/desc/inference/inference.api b/api/desc/inference/inference.api index e7a04c83..ba9b1946 100644 --- a/api/desc/inference/inference.api +++ b/api/desc/inference/inference.api @@ -45,14 +45,25 @@ type ( } InferenceTaskDetailReq{ - aiTaskId int64 `json:"aiTaskId"` + taskId int64 `form:"taskId"` } InferenceTaskDetailResp{ - imageName string `json:"imageName"` - result string `json:"result"` - card string `json:"card"` - clusterName string `json:"clusterName"` + InferenceResults []InferenceResult `json:"data"` + Code int32 `json:"code,omitempty"` + Msg string `json:"msg,omitempty"` } + InferenceResult{ + imageName string `json:"imageName"` + TaskName string `json:"taskName"` + TaskAiName string `json:"taskAiName"` + 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 c2511ac0..20284d47 100644 --- a/api/desc/pcm.api +++ b/api/desc/pcm.api @@ -928,6 +928,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 710fed4f..3cffcaae 100644 --- a/api/internal/handler/routes.go +++ b/api/internal/handler/routes.go @@ -1168,6 +1168,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 a9a84d97..fc842356 100644 --- a/api/internal/logic/inference/imageinferencelogic.go +++ b/api/internal/logic/inference/imageinferencelogic.go @@ -1,6 +1,5 @@ package inference -import "C" import ( "bytes" "context" diff --git a/api/internal/logic/inference/inferencetaskdetaillogic.go b/api/internal/logic/inference/inferencetaskdetaillogic.go new file mode 100644 index 00000000..0638742a --- /dev/null +++ b/api/internal/logic/inference/inferencetaskdetaillogic.go @@ -0,0 +1,58 @@ +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("task_id", req.TaskId).Scan(&taskAiSub) + + if len(taskAiSub) != 0 { + for _, sub := range taskAiSub { + result := types.InferenceResult{ + TaskName: sub.TaskName, + TaskAiName: sub.TaskAiName, + 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 55ad12df..35266b38 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -5912,11 +5912,19 @@ type ImageResult struct { } type InferenceTaskDetailReq struct { - AiTaskId int64 `json:"aiTaskId"` + TaskId int64 `form:"taskId"` } type InferenceTaskDetailResp struct { + InferenceResults []InferenceResult `json:"data"` + Code int32 `json:"code,omitempty"` + Msg string `json:"msg,omitempty"` +} + +type InferenceResult struct { ImageName string `json:"imageName"` + TaskName string `json:"taskName"` + TaskAiName string `json:"taskAiName"` Result string `json:"result"` Card string `json:"card"` ClusterName string `json:"clusterName"`