Browse Source

提交代码,增加模型信息

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.11.2^2
zouap 3 years ago
parent
commit
a4ff6baa36
3 changed files with 79 additions and 11 deletions
  1. +17
    -0
      models/ai_model_manage.go
  2. +30
    -9
      routers/repo/ai_model_manage.go
  3. +32
    -2
      routers/repo/attachment.go

+ 17
- 0
models/ai_model_manage.go View File

@@ -288,6 +288,23 @@ func ModifyModelDescription(id string, description string) error {
return nil
}

func ModifyLocalModel(id string, name, label, description string, engine int) error {
var sess *xorm.Session
sess = x.ID(id)
defer sess.Close()
re, err := sess.Cols("name", "label", "description", "engine").Update(&AiModelManage{
Description: description,
Name: name,
Label: label,
Engine: int64(engine),
})
if err != nil {
return err
}
log.Info("success to update description from db.re=" + fmt.Sprint((re)))
return nil
}

func ModifyModelSize(id string, size int64) error {
var sess *xorm.Session
sess = x.ID(id)


+ 30
- 9
routers/repo/ai_model_manage.go View File

@@ -37,6 +37,9 @@ const (
STATUS_COPY_MODEL = 1
STATUS_FINISHED = 0
STATUS_ERROR = 2

MODEL_LOCAL_TYPE = 1
MODEL_ONLINE_TYPE = 0
)

func saveModelByParameters(jobId string, versionName string, name string, version string, label string, description string, engine int, ctx *context.Context) (string, error) {
@@ -1032,28 +1035,46 @@ func ModifyModelInfo(ctx *context.Context) {
log.Info("modify model start.")
id := ctx.Query("id")
description := ctx.Query("description")

re := map[string]string{
"code": "-1",
}
task, err := models.QueryModelById(id)
if err != nil {
re["msg"] = err.Error()
log.Error("no such model!", err.Error())
ctx.ServerError("no such model:", err)
ctx.JSON(200, re)
return
}
if !isOper(ctx, task.UserId) {
ctx.NotFound(ctx.Req.URL.RequestURI(), nil)
//ctx.ServerError("no right.", errors.New(ctx.Tr("repo.model_noright")))
re["msg"] = "No right to operation."
ctx.JSON(200, re)
return
}
if task.ModelType == MODEL_LOCAL_TYPE {
name := ctx.Query("name")
label := ctx.Query("label")
description := ctx.Query("description")
engine := ctx.QueryInt("engine")
aimodels := models.QueryModelByName(name, task.RepoId)
if aimodels != nil && len(aimodels) > 0 {
re["msg"] = ctx.Tr("repo.model.manage.create_error")
ctx.JSON(200, re)
return
}
err = models.ModifyLocalModel(id, name, label, description, engine)

err = ModifyModel(id, description)
} else {
err = ModifyModel(id, description)
}

if err != nil {
log.Info("modify error," + err.Error())
ctx.ServerError("error.", err)
re["msg"] = err.Error()
ctx.JSON(200, re)
return
} else {
ctx.JSON(200, "success")
re["code"] = "0"
ctx.JSON(200, re)
}

}

func QueryModelListForPredict(ctx *context.Context) {


+ 32
- 2
routers/repo/attachment.go View File

@@ -664,7 +664,24 @@ func GetSuccessChunks(ctx *context.Context) {
}
if scene == Attachment_model {
//使用description存储模型信息

modeluuid := attach.Description
modelname := ""
if modeluuid != "" {
model, err := models.QueryModelById(modeluuid)
if err == nil {
modelname = model.Name
}
}
ctx.JSON(200, map[string]string{
"uuid": fileChunk.UUID,
"uploaded": strconv.Itoa(fileChunk.IsUploaded),
"uploadID": fileChunk.UploadID,
"chunks": string(chunks),
"attachID": strconv.Itoa(int(attachID)),
"modeluuid": modeluuid,
"fileName": attach.Name,
"modelName": modelname,
})
} else {
dataset, err := models.GetDatasetByID(attach.DatasetID)
if err != nil {
@@ -953,7 +970,20 @@ func CompleteMultipart(ctx *context.Context) {
if scene == Attachment_model {
//更新模型大小信息
UpdateModelSize(modeluuid)

_, err := models.InsertAttachment(&models.Attachment{
UUID: uuid,
UploaderID: ctx.User.ID,
IsPrivate: true,
Name: fileName,
Size: ctx.QueryInt64("size"),
DatasetID: 0,
Description: modeluuid,
Type: typeCloudBrain,
})
if err != nil {
ctx.Error(500, fmt.Sprintf("InsertAttachment: %v", err))
return
}
ctx.JSON(200, map[string]string{
"result_code": "0",
})


Loading…
Cancel
Save