added modeltypes api

Former-commit-id: 5640bcde2019a2a174dbe84af5d802da2d1a4d99
This commit is contained in:
tzwang 2024-06-21 15:20:46 +08:00
parent b412019647
commit 63e6303152
8 changed files with 150 additions and 0 deletions

View File

@ -2,6 +2,18 @@ syntax = "v1"
type (
/******************image inference*************************/
ModelTypesResp {
ModelTypes []string `json:"types"`
}
ModelNamesReq {
Type string `form:"type"`
}
ModelNamesResp {
ModelNames []string `json:"models"`
}
/******************image inference*************************/
ImageInferenceReq {
TaskName string `form:"taskName"`
@ -31,4 +43,5 @@ type (
Card string `json:"card"`
ImageResult string `json:"imageResult"`
}
)

View File

@ -909,6 +909,12 @@ service pcm {
service pcm {
@handler ImageInferenceHandler
post /inference/images (ImageInferenceReq) returns (ImageInferenceResp)
@handler ModelTypesHandler
get /inference/modelTypes returns (ModelTypesResp)
@handler ModelNamesByTypeHandler
get /inference/modelNames (ModelNamesReq) returns (ModelNamesResp)
}
@server(

View File

@ -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 ModelNamesByTypeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ModelNamesReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := inference.NewModelNamesByTypeLogic(r.Context(), svcCtx)
resp, err := l.ModelNamesByType(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@ -0,0 +1,21 @@
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"
)
func ModelTypesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := inference.NewModelTypesLogic(r.Context(), svcCtx)
resp, err := l.ModelTypes()
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@ -1143,6 +1143,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/inference/images",
Handler: inference.ImageInferenceHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/inference/modelTypes",
Handler: inference.ModelTypesHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/inference/modelNames",
Handler: inference.ModelNamesByTypeHandler(serverCtx),
},
},
rest.WithPrefix("/pcm/v1"),
)

View File

@ -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 ModelNamesByTypeLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewModelNamesByTypeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ModelNamesByTypeLogic {
return &ModelNamesByTypeLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ModelNamesByTypeLogic) ModelNamesByType(req *types.ModelNamesReq) (resp *types.ModelNamesResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@ -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 ModelTypesLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewModelTypesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ModelTypesLogic {
return &ModelTypesLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ModelTypesLogic) ModelTypes() (resp *types.ModelTypesResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@ -5879,6 +5879,18 @@ type Category struct {
Name string `json:"name"`
}
type ModelTypesResp struct {
ModelTypes []string `json:"types"`
}
type ModelNamesReq struct {
Type string `form:"type"`
}
type ModelNamesResp struct {
ModelNames []string `json:"models"`
}
type ImageInferenceReq struct {
TaskName string `form:"taskName"`
TaskDesc string `form:"taskDesc"`