Browse Source

查询模型接口修改成接口文档的方式。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.11.2^2
zouap 3 years ago
parent
commit
6cea45e40a
2 changed files with 31 additions and 6 deletions
  1. +24
    -1
      routers/api/v1/repo/modelmanage.go
  2. +7
    -5
      routers/repo/ai_model_manage.go

+ 24
- 1
routers/api/v1/repo/modelmanage.go View File

@@ -8,6 +8,15 @@ import (
routerRepo "code.gitea.io/gitea/routers/repo"
)

type FileInfo struct {
FileName string `json:"fileName"`
ModTime string `json:"modTime"`
IsDir bool `json:"isDir"`
Size int64 `json:"size"`
ParenDir string `json:"parenDir"`
UUID string `json:"uuid"`
}

func CreateNewModel(ctx *context.APIContext) {
log.Info("CreateNewModel by api.")
routerRepo.SaveModel(ctx.Context)
@@ -35,7 +44,21 @@ func QueryModelListForPredict(ctx *context.APIContext) {

func QueryModelFileForPredict(ctx *context.APIContext) {
log.Info("QueryModelFileForPredict by api.")
routerRepo.QueryModelFileForPredict(ctx.Context)
id := ctx.Query("id")
result := routerRepo.QueryModelFileByID(id)
re := make([]FileInfo, len(result))
for _, file := range result {
tmpFile := FileInfo{
FileName: file.FileName,
ModTime: file.ModTime,
IsDir: file.IsDir,
Size: file.Size,
ParenDir: file.ParenDir,
UUID: file.UUID,
}
re = append(re, tmpFile)
}
ctx.JSON(http.StatusOK, re)
}

func CreateModelConvert(ctx *context.APIContext) {


+ 7
- 5
routers/repo/ai_model_manage.go View File

@@ -910,23 +910,25 @@ func QueryModelFileForPredict(ctx *context.Context) {
if id == "" {
id = ctx.Query("ID")
}
ctx.JSON(http.StatusOK, QueryModelFileByID(id))
}

func QueryModelFileByID(id string) []storage.FileInfo {
model, err := models.QueryModelById(id)
if err == nil {
if model.Type == models.TypeCloudBrainTwo {
prefix := model.Path[len(setting.Bucket)+1:]
fileinfos, _ := storage.GetAllObjectByBucketAndPrefix(setting.Bucket, prefix)
ctx.JSON(http.StatusOK, fileinfos)
return fileinfos
} else if model.Type == models.TypeCloudBrainOne {
prefix := model.Path[len(setting.Attachment.Minio.Bucket)+1:]
fileinfos, _ := storage.GetAllObjectByBucketAndPrefixMinio(setting.Attachment.Minio.Bucket, prefix)
ctx.JSON(http.StatusOK, fileinfos)
return fileinfos
}
} else {
log.Error("no such model!", err.Error())
ctx.ServerError("no such model:", err)
return
}
return nil
}

func QueryOneLevelModelFile(ctx *context.Context) {


Loading…
Cancel
Save