diff --git a/backend/docs/swagger.json b/backend/docs/swagger.json index a396efa..4765455 100644 --- a/backend/docs/swagger.json +++ b/backend/docs/swagger.json @@ -1113,6 +1113,37 @@ } } } + }, + "delete": { + "description": "删除模型", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Model" + ], + "summary": "删除模型", + "operationId": "delete-model", + "parameters": [ + { + "type": "string", + "description": "模型ID", + "name": "id", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/web.Resp" + } + } + } } }, "/api/v1/model/check": { @@ -2471,7 +2502,8 @@ "BaiZhiCloud", "Hunyuan", "BaiLian", - "Volcengine" + "Volcengine", + "Other" ], "allOf": [ { @@ -2853,6 +2885,10 @@ "description": "是否启用", "type": "boolean" }, + "is_internal": { + "description": "是否内部模型", + "type": "boolean" + }, "model_name": { "description": "模型名称 如: deepseek-v3", "type": "string" @@ -2921,7 +2957,8 @@ "BaiZhiCloud", "Hunyuan", "BaiLian", - "Volcengine" + "Volcengine", + "Other" ], "allOf": [ { @@ -3301,7 +3338,8 @@ "BaiZhiCloud", "Hunyuan", "BaiLian", - "Volcengine" + "Volcengine", + "Other" ], "allOf": [ { diff --git a/backend/domain/model.go b/backend/domain/model.go index bda9f67..6ed6e82 100644 --- a/backend/domain/model.go +++ b/backend/domain/model.go @@ -14,6 +14,7 @@ type ModelUsecase interface { MyModelList(ctx context.Context, req *MyModelListReq) ([]*Model, error) Create(ctx context.Context, req *CreateModelReq) (*Model, error) Update(ctx context.Context, req *UpdateModelReq) (*Model, error) + Delete(ctx context.Context, id string) error Check(ctx context.Context, req *CheckModelReq) (*Model, error) GetTokenUsage(ctx context.Context, modelType consts.ModelType) (*ModelTokenUsageResp, error) InitModel(ctx context.Context) error @@ -25,6 +26,7 @@ type ModelRepo interface { List(ctx context.Context) (*AllModelResp, error) Create(ctx context.Context, m *CreateModelReq) (*db.Model, error) Update(ctx context.Context, id string, fn func(tx *db.Tx, old *db.Model, up *db.ModelUpdateOne) error) (*db.Model, error) + Delete(ctx context.Context, id string) error MyModelList(ctx context.Context, req *MyModelListReq) ([]*db.Model, error) ModelUsage(ctx context.Context, ids []uuid.UUID) (map[uuid.UUID]ModelUsage, error) GetTokenUsage(ctx context.Context, modelType consts.ModelType) (*ModelTokenUsageResp, error) diff --git a/backend/internal/model/handler/http/v1/model.go b/backend/internal/model/handler/http/v1/model.go index ee8c284..8a67b06 100644 --- a/backend/internal/model/handler/http/v1/model.go +++ b/backend/internal/model/handler/http/v1/model.go @@ -27,13 +27,14 @@ func NewModelHandler( g := w.Group("/api/v1/model") g.Use(auth.Auth(), active.Active("admin")) - g.POST("/check", web.BindHandler(m.Check)) g.GET("", web.BaseHandler(m.List)) - g.POST("", web.BindHandler(m.Create)) - g.PUT("", web.BindHandler(m.Update)) g.GET("/provider/supported", web.BindHandler(m.GetProviderModelList)) g.GET("/token-usage", web.BindHandler(m.GetTokenUsage)) g.GET("/my", web.BindHandler(m.MyModelList)) + g.POST("", web.BindHandler(m.Create)) + g.POST("/check", web.BindHandler(m.Check)) + g.PUT("", web.BindHandler(m.Update)) + g.DELETE("", web.BaseHandler(m.Delete)) return m } @@ -174,6 +175,24 @@ func (h *ModelHandler) GetProviderModelList(c *web.Context, req domain.GetProvid return c.Success(resp) } +// Delete 删除模型 +// +// @Tags Model +// @Summary 删除模型 +// @Description 删除模型 +// @ID delete-model +// @Accept json +// @Produce json +// @Param id query string true "模型ID" +// @Success 200 {object} web.Resp{} +// @Router /api/v1/model [delete] +func (h *ModelHandler) Delete(c *web.Context) error { + if err := h.usecase.Delete(c.Request().Context(), c.QueryParam("id")); err != nil { + return err + } + return c.Success(nil) +} + func (h *ModelHandler) InitModel() error { return h.usecase.InitModel(context.Background()) } diff --git a/backend/internal/model/repo/model.go b/backend/internal/model/repo/model.go index a90cf8c..51e7414 100644 --- a/backend/internal/model/repo/model.go +++ b/backend/internal/model/repo/model.go @@ -243,3 +243,11 @@ func (r *ModelRepo) InitModel(ctx context.Context, modelName, modelKey, modelURL SetIsInternal(true). Exec(ctx) } + +func (r *ModelRepo) Delete(ctx context.Context, id string) error { + uuidID, err := uuid.Parse(id) + if err != nil { + return err + } + return r.db.Model.DeleteOneID(uuidID).Exec(ctx) +} diff --git a/backend/internal/model/usecase/model.go b/backend/internal/model/usecase/model.go index 07da554..62a3483 100644 --- a/backend/internal/model/usecase/model.go +++ b/backend/internal/model/usecase/model.go @@ -356,3 +356,7 @@ func (m *ModelUsecase) GetProviderModelList(ctx context.Context, req *domain.Get return nil, fmt.Errorf("invalid provider: %s", req.Provider) } } + +func (m *ModelUsecase) Delete(ctx context.Context, id string) error { + return m.repo.Delete(ctx, id) +}