( rw http.ResponseWriter, r *http.Request, )
| 4720 | } |
| 4721 | |
| 4722 | func readChatModelOverrideContext( |
| 4723 | rw http.ResponseWriter, |
| 4724 | r *http.Request, |
| 4725 | ) (codersdk.ChatModelOverrideContext, bool) { |
| 4726 | ctx := r.Context() |
| 4727 | rawContext := chi.URLParam(r, "context") |
| 4728 | overrideContext, err := parseChatModelOverrideContext(rawContext) |
| 4729 | if err == nil { |
| 4730 | return overrideContext, true |
| 4731 | } |
| 4732 | validContextValues := make( |
| 4733 | []string, |
| 4734 | 0, |
| 4735 | len(codersdk.AllChatModelOverrideContexts()), |
| 4736 | ) |
| 4737 | for _, overrideContext := range codersdk.AllChatModelOverrideContexts() { |
| 4738 | validContextValues = append(validContextValues, string(overrideContext)) |
| 4739 | } |
| 4740 | validContexts := strings.Join(validContextValues, ", ") |
| 4741 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 4742 | Message: "Invalid chat model override context.", |
| 4743 | Detail: fmt.Sprintf( |
| 4744 | "Expected one of %s. Got %q.", |
| 4745 | validContexts, |
| 4746 | rawContext, |
| 4747 | ), |
| 4748 | }) |
| 4749 | return "", false |
| 4750 | } |
| 4751 | |
| 4752 | // EXPERIMENTAL: this endpoint is experimental and is subject to change. |
| 4753 | // |
no test coverage detected