訓練進度測試
This commit is contained in:
@@ -33,7 +33,7 @@ func ModelsGet(w http.ResponseWriter, r *http.Request) {
|
||||
listview.WriteJSON(w)
|
||||
}
|
||||
|
||||
// 創建模型
|
||||
// 創建模型(訓練新模型)
|
||||
func ModelsPost(w http.ResponseWriter, r *http.Request) {
|
||||
models.AccountRead(w, r, func(account *models.Account) {
|
||||
fmt.Println(account)
|
||||
@@ -50,6 +50,44 @@ func ModelsPost(w http.ResponseWriter, r *http.Request) {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
if model.Name == "" {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte("模型名稱不能為空"))
|
||||
return
|
||||
}
|
||||
|
||||
if model.Type == "" {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte("模型類型不能為空(recommend|lora|ckp|hyper|ti)"))
|
||||
return
|
||||
}
|
||||
|
||||
if model.TriggerWords == "" {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte("觸發詞不能為空"))
|
||||
return
|
||||
}
|
||||
|
||||
if model.BaseModel == "" {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte("基礎模型不能為空(SD1.5|SD2)"))
|
||||
return
|
||||
}
|
||||
|
||||
if model.Epochs <= 0 {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte("訓練輪數不能小於0"))
|
||||
return
|
||||
}
|
||||
|
||||
if model.Tags == nil {
|
||||
model.Tags = []string{}
|
||||
}
|
||||
|
||||
model.UserID = account.ID
|
||||
model.Status = "initial"
|
||||
|
||||
if err := configs.ORMDB().Create(&model).Error; err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
@@ -62,6 +100,7 @@ func ModelsPost(w http.ResponseWriter, r *http.Request) {
|
||||
})
|
||||
}
|
||||
|
||||
// 獲取模型詳情
|
||||
func ModelItemGet(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Header.Get("Upgrade") == "websocket" {
|
||||
vars := mux.Vars(r)
|
||||
@@ -97,8 +136,10 @@ func ModelItemGet(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
var model = models.Model{ID: utils.ParamInt(mux.Vars(r)["id"], 0)}
|
||||
if err := configs.ORMDB().Take(&model, utils.ParamInt(mux.Vars(r)["id"], 0)); err != nil {
|
||||
fmt.Println(model)
|
||||
if err := configs.ORMDB().Take(&model, utils.ParamInt(mux.Vars(r)["id"], 0)).Error; err != nil {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -106,6 +147,7 @@ func ModelItemGet(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write(utils.ToJSON(model))
|
||||
}
|
||||
|
||||
// 更新模型
|
||||
func ModelItemPatch(w http.ResponseWriter, r *http.Request) {
|
||||
var model = models.Model{ID: utils.ParamInt(mux.Vars(r)["id"], 0)}
|
||||
if err := configs.ORMDB().Take(&model, utils.ParamInt(mux.Vars(r)["id"], 0)).Error; err != nil {
|
||||
@@ -157,6 +199,7 @@ func ModelItemPatch(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write(utils.ToJSON(model))
|
||||
}
|
||||
|
||||
// 刪除模型
|
||||
func ModelItemDelete(w http.ResponseWriter, r *http.Request) {
|
||||
var model = models.Model{ID: utils.ParamInt(mux.Vars(r)["id"], 0)}
|
||||
if err := configs.ORMDB().Take(&model, utils.ParamInt(mux.Vars(r)["id"], 0)); err != nil {
|
||||
|
Reference in New Issue
Block a user