add onlineInferUrl

This commit is contained in:
jagger 2025-03-20 18:37:18 +08:00
parent c5dc5179d7
commit 7bd6650118
4 changed files with 69 additions and 4 deletions

View File

@ -2,6 +2,7 @@ package apis
import (
"github.com/gin-gonic/gin"
json "github.com/json-iterator/go"
"gitlink.org.cn/JointCloud/pcm-openi/common"
"gitlink.org.cn/JointCloud/pcm-openi/model"
"io"
@ -140,18 +141,23 @@ func GetTaskDetail(ctx *gin.Context) {
func CreateTask(ctx *gin.Context) {
var param model.CreateTaskReq
if err := ctx.BindJSON(&param); err != nil {
model.Response(ctx, http.StatusBadRequest, common.INVALIDPARAMS, err)
model.Response(ctx, http.StatusBadRequest, common.INVALIDPARAMS, translate(err))
return
}
token := ctx.Query(common.ACCESSTOKEN)
if token == "" {
model.Response(ctx, 401, "access_token为必填字段", nil)
return
}
reqUrl := common.OPENIPREFIX + common.TASKCREATE
var resp model.CreateTask
req := common.GetRestyRequest(common.TIMEOUT)
_, err := req.
res, err := req.
SetQueryParam(common.ACCESSTOKEN, token).
SetPathParam("username", param.UserName).
SetPathParam("reponame", param.RepoName).
@ -163,7 +169,17 @@ func CreateTask(ctx *gin.Context) {
model.Response(ctx, 500, common.INVOKEERROR, err)
return
}
if res != nil {
if res.StatusCode() != 200 {
errStr := json.Get(res.Body(), "message").ToString()
model.Response(ctx, 500, errStr, nil)
return
}
}
if resp.Code != 0 {
model.Response(ctx, 500, resp.Msg, nil)
return
}
if resp.Data.Id == 0 {
model.Response(ctx, 500, common.INVOKEERROR, err)
return
@ -311,3 +327,42 @@ func GetTaskOutput(ctx *gin.Context) {
model.Response(ctx, http.StatusOK, common.SUCCESS, resp.Data)
}
func GetTaskOnlineUrl(ctx *gin.Context) {
var param model.TaskDetailParam
if err := ctx.BindJSON(&param); err != nil {
model.Response(ctx, http.StatusBadRequest, common.INVALIDPARAMS, translate(err))
return
}
token := ctx.Query(common.ACCESSTOKEN)
reqUrl := common.OPENIPREFIX + common.SelfEndpointUrl
var resp model.SelfEndpointUrlResp
req := common.GetRestyRequest(common.TIMEOUT)
rp, err := req.
SetQueryParam(common.ACCESSTOKEN, token).
SetQueryParam("id", param.Id).
SetPathParam("username", param.UserName).
SetPathParam("reponame", param.RepoName).
SetResult(&resp).
Get(reqUrl)
if err != nil {
model.Response(ctx, 500, common.INVOKEERROR, err)
return
}
if resp.Code != 0 {
model.Response(ctx, 500, resp.Msg, nil)
return
}
if rp.StatusCode() != http.StatusOK {
model.Response(ctx, rp.StatusCode(), rp.Status(), nil)
return
}
model.Response(ctx, http.StatusOK, common.SUCCESS, resp.Data)
}

View File

@ -44,6 +44,7 @@ const (
TASKOUTPUT = "/api/v1/{username}/{reponame}/ai_task/output" // 查询结果列表接口
TASKRESULTDOWNLOAD = "/api/v1/{username}/{reponame}/ai_task/output/download/all" // 所有结果下载接口
TASKLOGDOWNLOAD = "/api/v1/{username}/{reponame}/ai_task/log/download" //日志下载
SelfEndpointUrl = "/api/v1/{username}/{reponame}/ai_task/self_endpoint_url" //在线推理接口
// model
MODELCREATE = "/api/v1/repos/{username}/{reponame}/modelmanage/create_new_model" //模型新增接口

View File

@ -272,7 +272,7 @@ type CreateTaskParam struct {
Params string `json:"params"`
BootFile string `json:"boot_file"`
HasInternet int `json:"has_internet"`
WorkServerNumber int `json:"work_server_number"`
WorkServerNumber int `json:"work_server_number,optional"`
}
type StopTaskParam struct {
@ -350,3 +350,11 @@ type GetTaskOutput struct {
} `json:"output"`
} `json:"data"`
}
type SelfEndpointUrlResp struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data struct {
Url string `json:"url"`
} `json:"data"`
}

View File

@ -63,6 +63,7 @@ func Create(conf *config.Configuration) (*gin.Engine, error) {
task.POST("/create", apis.CreateTask)
task.POST("/stop", apis.StopTask)
task.GET("/downloadAll", apis.DownloadAllById)
task.GET("/onlineInferUrl", apis.GetTaskOnlineUrl)
//model
modelApi := apis.ModelApi