新增4个任务相关路由及http服务

This commit is contained in:
Jake 2025-07-14 18:51:48 +08:00
parent 996f8d1a55
commit a8629db69d
2 changed files with 71 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import (
"gitlink.org.cn/JointCloud/pcm-participant-ai/dataset"
aiModel "gitlink.org.cn/JointCloud/pcm-participant-ai/model"
"gitlink.org.cn/JointCloud/pcm-participant-ai/service"
"gitlink.org.cn/JointCloud/pcm-participant-ai/task"
"gitlink.org.cn/JointCloud/pcm-participant-openi/model"
"net/http"
"strconv"
@ -210,6 +211,65 @@ func (a *aiApi) CreateTrainTaskHandler(c *gin.Context) {
model.Response(c, http.StatusOK, "success", resp)
}
// TaskResultSyncHandler 同步任务结果数据
func (a *aiApi) TaskResultSyncHandler(c *gin.Context) {
pfIdStr := c.Query("pfId")
var param task.ResultSyncParam
if err := c.ShouldBindJSON(&param); err != nil {
model.Response(c, http.StatusBadRequest, "invalid request body", nil)
return
}
pfId, err := strconv.ParseInt(pfIdStr, 10, 64)
if err != nil {
model.Response(c, http.StatusBadRequest, "invalid pfId", nil)
return
}
a.service.TaskResultSync(c, pfId, &param)
model.Response(c, http.StatusOK, "success", nil)
}
// TaskLogHandler 查询任务日志
func (a *aiApi) TaskLogHandler(c *gin.Context) {
pfIdStr := c.Query("pfId")
taskId := c.Query("taskId")
pfId, err := strconv.ParseInt(pfIdStr, 10, 64)
if err != nil {
model.Response(c, http.StatusBadRequest, "invalid pfId", nil)
return
}
a.service.TaskLog(c, pfId, taskId)
model.Response(c, http.StatusOK, "success", nil)
}
// TrainTaskDetailHandler 查询训练任务详情
func (a *aiApi) TrainTaskDetailHandler(c *gin.Context) {
pfIdStr := c.Query("pfId")
taskId := c.Query("taskId")
pfId, err := strconv.ParseInt(pfIdStr, 10, 64)
if err != nil {
model.Response(c, http.StatusBadRequest, "invalid pfId", nil)
return
}
a.service.GetTrainingTask(c, pfId, taskId)
model.Response(c, http.StatusOK, "success", nil)
}
// InferTaskDetailHandler 查询推理任务详情
func (a *aiApi) InferTaskDetailHandler(c *gin.Context) {
pfIdStr := c.Query("pfId")
taskId := c.Query("taskId")
pfId, err := strconv.ParseInt(pfIdStr, 10, 64)
if err != nil {
model.Response(c, http.StatusBadRequest, "invalid pfId", nil)
return
}
a.service.GetInferenceTask(c, pfId, taskId)
model.Response(c, http.StatusOK, "success", nil)
}
// TestFuncResHandler 处理测试资源相关功能的请求
func (a *aiApi) TestFuncResHandler(c *gin.Context) {
pfIdStr := c.Query("pfId")

View File

@ -9,18 +9,28 @@ func AIRoutes(server *gin.Engine) {
ai := server.Group("/ai")
aiApi := api.AiApi
{
//算法路由
ai.GET("/algorithm/get", aiApi.TrainAlgorithmsHandler)
ai.GET("/algorithm/list", aiApi.AllTrainAlgorithmsHandler)
ai.POST("/algorithm/create", aiApi.CreateAlgorithmHandler)
//数据集路由
ai.POST("/dataset/create", aiApi.CreateDatasetHandler)
// 模型相关路由
ai.POST("/model/create", aiApi.CreateModelHandler)
// 资源相关路由
ai.GET("/resource/specs", aiApi.GetResourceSpecsHandler)
ai.GET("/resource/get", aiApi.TrainResourcesHandler)
ai.GET("/resource/list", aiApi.AllTrainResourcesHandler)
// 算法相关路由
// 任务相关路由
ai.GET("/task/train", aiApi.CreateTrainTaskHandler)
ai.GET("/task/sync", aiApi.TaskResultSyncHandler)
ai.GET("/task/log", aiApi.TaskLogHandler)
ai.GET("/task/train/detail", aiApi.TrainTaskDetailHandler)
ai.GET("/task/infer/detail", aiApi.InferTaskDetailHandler)
}
}