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

Method listChatModelConfigs

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

Source from the content-addressed store, hash-verified

6737}
6738
6739func (api *API) listChatModelConfigs(rw http.ResponseWriter, r *http.Request) {
6740 ctx := r.Context()
6741
6742 // Admin users can see all model configs (including disabled ones)
6743 // for management purposes. Non-admin users see only enabled
6744 // configs, which is sufficient for using the chat feature.
6745 isAdmin := api.Authorize(r, policy.ActionRead, rbac.ResourceDeploymentConfig)
6746
6747 var configs []database.ChatModelConfig
6748 var err error
6749 if isAdmin {
6750 configs, err = api.Database.GetChatModelConfigs(ctx)
6751 } else {
6752 //nolint:gocritic // All authenticated users need to read enabled model configs to use the chat feature.
6753 configs, err = api.Database.GetEnabledChatModelConfigs(dbauthz.AsChatd(ctx))
6754 }
6755 if err != nil {
6756 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
6757 Message: "Failed to list chat model configs.",
6758 Detail: err.Error(),
6759 })
6760 return
6761 }
6762
6763 resp := make([]codersdk.ChatModelConfig, 0, len(configs))
6764 for _, config := range configs {
6765 resp = append(resp, convertChatModelConfig(config))
6766 }
6767
6768 httpapi.Write(ctx, rw, http.StatusOK, resp)
6769}
6770
6771type chatModelConfigProviderModelError struct {
6772 Response codersdk.Response

Callers

nothing calls this directly

Calls 8

AuthorizeMethod · 0.95
AsChatdFunction · 0.92
WriteFunction · 0.92
convertChatModelConfigFunction · 0.85
ContextMethod · 0.65
GetChatModelConfigsMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected