MCPcopy Index your code
hub / github.com/coder/coder / deleteChatModelConfig

Method deleteChatModelConfig

coderd/exp_chats.go:7213–7253  ·  view source on GitHub ↗
(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

7211}
7212
7213func (api *API) deleteChatModelConfig(rw http.ResponseWriter, r *http.Request) {
7214 ctx := r.Context()
7215 if !api.Authorize(r, policy.ActionUpdate, rbac.ResourceDeploymentConfig) {
7216 httpapi.Forbidden(rw)
7217 return
7218 }
7219
7220 modelConfigID, ok := parseChatModelConfigID(rw, r)
7221 if !ok {
7222 return
7223 }
7224
7225 if _, err := api.Database.GetChatModelConfigByID(ctx, modelConfigID); err != nil {
7226 if httpapi.Is404Error(err) {
7227 httpapi.ResourceNotFound(rw)
7228 return
7229 }
7230 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
7231 Message: "Failed to get chat model config.",
7232 Detail: err.Error(),
7233 })
7234 return
7235 }
7236
7237 if err := api.Database.InTx(func(tx database.Store) error {
7238 if err := tx.DeleteChatModelConfigByID(ctx, modelConfigID); err != nil {
7239 return err
7240 }
7241 return ensureDefaultChatModelConfig(ctx, tx)
7242 }, nil); err != nil {
7243 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
7244 Message: "Failed to delete chat model config.",
7245 Detail: err.Error(),
7246 })
7247 return
7248 }
7249
7250 publishChatConfigEvent(api.Logger, api.Pubsub, pubsub.ChatConfigEventModelConfig, modelConfigID)
7251
7252 rw.WriteHeader(http.StatusNoContent)
7253}
7254
7255func ensureDefaultChatModelConfig(
7256 ctx context.Context,

Callers 1

deleteChatModelConfigFunction · 0.80

Calls 14

AuthorizeMethod · 0.95
ForbiddenFunction · 0.92
Is404ErrorFunction · 0.92
ResourceNotFoundFunction · 0.92
WriteFunction · 0.92
parseChatModelConfigIDFunction · 0.85
publishChatConfigEventFunction · 0.85
ContextMethod · 0.65
InTxMethod · 0.65

Tested by

no test coverage detected