|
|
|
@@ -190,7 +190,100 @@ func SaveNewNameModel(ctx *context.Context) { |
|
|
|
} |
|
|
|
|
|
|
|
func SaveLocalModel(ctx *context.Context) { |
|
|
|
if !ctx.Repo.CanWrite(models.UnitTypeModelManage) { |
|
|
|
ctx.Error(403, ctx.Tr("repo.model_noright")) |
|
|
|
return |
|
|
|
} |
|
|
|
re := map[string]string{ |
|
|
|
"code": "-1", |
|
|
|
} |
|
|
|
log.Info("save SaveLocalModel start.") |
|
|
|
uuid := uuid.NewV4() |
|
|
|
id := uuid.String() |
|
|
|
name := ctx.Query("name") |
|
|
|
version := ctx.Query("version") |
|
|
|
if version == "" { |
|
|
|
version = "0.0.1" |
|
|
|
} |
|
|
|
label := ctx.Query("label") |
|
|
|
description := ctx.Query("description") |
|
|
|
engine := ctx.QueryInt("engine") |
|
|
|
taskType := ctx.QueryInt("type") |
|
|
|
modelActualPath := "" |
|
|
|
if taskType == models.TypeCloudBrainOne { |
|
|
|
destKeyNamePrefix := Model_prefix + models.AttachmentRelativePath(id) + "/" |
|
|
|
modelActualPath = setting.Bucket + "/" + destKeyNamePrefix |
|
|
|
} else if taskType == models.TypeCloudBrainTwo { |
|
|
|
destKeyNamePrefix := Model_prefix + models.AttachmentRelativePath(id) + "/" |
|
|
|
modelActualPath = setting.Attachment.Minio.Bucket + "/" + destKeyNamePrefix |
|
|
|
} else { |
|
|
|
re["msg"] = "type is error." |
|
|
|
ctx.JSON(200, re) |
|
|
|
return |
|
|
|
} |
|
|
|
var lastNewModelId string |
|
|
|
repoId := ctx.Repo.Repository.RepoID |
|
|
|
aimodels := models.QueryModelByName(name, repoId) |
|
|
|
if len(aimodels) > 0 { |
|
|
|
for _, model := range aimodels { |
|
|
|
if model.Version == version { |
|
|
|
re["msg"] = ctx.Tr("repo.model.manage.create_error") |
|
|
|
ctx.JSON(200, re) |
|
|
|
return |
|
|
|
} |
|
|
|
if model.New == MODEL_LATEST { |
|
|
|
lastNewModelId = model.ID |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
model := &models.AiModelManage{ |
|
|
|
ID: id, |
|
|
|
Version: version, |
|
|
|
VersionCount: len(aimodels) + 1, |
|
|
|
Label: label, |
|
|
|
Name: name, |
|
|
|
Description: description, |
|
|
|
New: MODEL_LATEST, |
|
|
|
Type: taskType, |
|
|
|
Path: modelActualPath, |
|
|
|
Size: 0, |
|
|
|
AttachmentId: "", |
|
|
|
RepoId: repoId, |
|
|
|
UserId: ctx.User.ID, |
|
|
|
Engine: int64(engine), |
|
|
|
TrainTaskInfo: "", |
|
|
|
Accuracy: "", |
|
|
|
Status: STATUS_FINISHED, |
|
|
|
} |
|
|
|
|
|
|
|
err := models.SaveModelToDb(model) |
|
|
|
if err != nil { |
|
|
|
re["msg"] = err.Error() |
|
|
|
ctx.JSON(200, re) |
|
|
|
return |
|
|
|
} |
|
|
|
if len(lastNewModelId) > 0 { |
|
|
|
//udpate status and version count |
|
|
|
models.ModifyModelNewProperty(lastNewModelId, MODEL_NOT_LATEST, 0) |
|
|
|
} |
|
|
|
var units []models.RepoUnit |
|
|
|
var deleteUnitTypes []models.UnitType |
|
|
|
units = append(units, models.RepoUnit{ |
|
|
|
RepoID: ctx.Repo.Repository.ID, |
|
|
|
Type: models.UnitTypeModelManage, |
|
|
|
Config: &models.ModelManageConfig{ |
|
|
|
EnableModelManage: true, |
|
|
|
}, |
|
|
|
}) |
|
|
|
deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeModelManage) |
|
|
|
|
|
|
|
models.UpdateRepositoryUnits(ctx.Repo.Repository, units, deleteUnitTypes) |
|
|
|
|
|
|
|
log.Info("save model end.") |
|
|
|
notification.NotifyOtherTask(ctx.User, ctx.Repo.Repository, id, name, models.ActionCreateNewModelTask) |
|
|
|
re["code"] = "0" |
|
|
|
re["id"] = id |
|
|
|
ctx.JSON(200, re) |
|
|
|
} |
|
|
|
|
|
|
|
func UploadLocalModel(ctx *context.Context) { |
|
|
|
|