EXPERIMENTAL: this endpoint is experimental and is subject to change.
(rw http.ResponseWriter, r *http.Request)
| 4786 | |
| 4787 | // EXPERIMENTAL: this endpoint is experimental and is subject to change. |
| 4788 | func (api *API) putChatModelOverride(rw http.ResponseWriter, r *http.Request) { |
| 4789 | ctx := r.Context() |
| 4790 | if !api.Authorize(r, policy.ActionUpdate, rbac.ResourceDeploymentConfig) { |
| 4791 | httpapi.Forbidden(rw) |
| 4792 | return |
| 4793 | } |
| 4794 | overrideContext, ok := readChatModelOverrideContext(rw, r) |
| 4795 | if !ok { |
| 4796 | return |
| 4797 | } |
| 4798 | |
| 4799 | var req codersdk.UpdateChatModelOverrideRequest |
| 4800 | if !httpapi.Read(ctx, rw, r, &req) { |
| 4801 | return |
| 4802 | } |
| 4803 | |
| 4804 | modelConfigID, err := parseChatModelOverride(req.ModelConfigID) |
| 4805 | if err != nil { |
| 4806 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 4807 | Message: "Invalid model_config_id.", |
| 4808 | Detail: fmt.Sprintf("Value %q is not a valid UUID.", req.ModelConfigID), |
| 4809 | }) |
| 4810 | return |
| 4811 | } |
| 4812 | |
| 4813 | status, resp := validateChatModelOverrideID(ctx, api.Database, modelConfigID) |
| 4814 | if resp != nil { |
| 4815 | httpapi.Write(ctx, rw, status, *resp) |
| 4816 | return |
| 4817 | } |
| 4818 | |
| 4819 | label, err := api.upsertChatModelOverrideConfig(ctx, overrideContext, modelConfigID) |
| 4820 | if err != nil { |
| 4821 | if label == "" { |
| 4822 | label = string(overrideContext) |
| 4823 | } |
| 4824 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 4825 | Message: fmt.Sprintf("Internal error updating %s model override.", label), |
| 4826 | Detail: err.Error(), |
| 4827 | }) |
| 4828 | return |
| 4829 | } |
| 4830 | |
| 4831 | rw.WriteHeader(http.StatusNoContent) |
| 4832 | } |
| 4833 | |
| 4834 | func readChatPersonalModelOverrideContext( |
| 4835 | rw http.ResponseWriter, |
nothing calls this directly
no test coverage detected