diff --git a/models/ai_model_manage.go b/models/ai_model_manage.go index 399c02e28..5b14b9ba2 100644 --- a/models/ai_model_manage.go +++ b/models/ai_model_manage.go @@ -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) diff --git a/routers/repo/ai_model_manage.go b/routers/repo/ai_model_manage.go index 2682a34a5..3a25c37d2 100644 --- a/routers/repo/ai_model_manage.go +++ b/routers/repo/ai_model_manage.go @@ -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) { diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index 44db6c8bc..271183e65 100755 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -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", })