EXPERIMENTAL: this endpoint is experimental and is subject to change. @Summary List chat models @ID list-chat-models @Security CoderSessionToken @Tags Chats @Produce json @Success 200 {object} codersdk.ChatModelsResponse @Router /api/experimental/chats/models [get] @Description Experimental: this e
(rw http.ResponseWriter, r *http.Request)
| 1304 | // @Router /api/experimental/chats/models [get] |
| 1305 | // @Description Experimental: this endpoint is subject to change. |
| 1306 | func (api *API) listChatModels(rw http.ResponseWriter, r *http.Request) { |
| 1307 | ctx := r.Context() |
| 1308 | apiKey := httpmw.APIKey(r) |
| 1309 | if api.chatDaemon == nil { |
| 1310 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 1311 | Message: "Chat processor is unavailable.", |
| 1312 | Detail: "Chat processor is not configured.", |
| 1313 | }) |
| 1314 | return |
| 1315 | } |
| 1316 | |
| 1317 | availability, err := api.getUserChatProviderAvailability(ctx, apiKey.UserID) |
| 1318 | if err != nil { |
| 1319 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 1320 | Message: "Failed to load chat model configuration.", |
| 1321 | Detail: err.Error(), |
| 1322 | }) |
| 1323 | return |
| 1324 | } |
| 1325 | catalog := chatprovider.NewModelCatalog() |
| 1326 | var response codersdk.ChatModelsResponse |
| 1327 | if configured, ok := catalog.ListConfiguredModels( |
| 1328 | availability.configuredProviders, |
| 1329 | availability.configuredModels, |
| 1330 | availability.providerStatus, |
| 1331 | availability.enabledProviderNames, |
| 1332 | ); ok { |
| 1333 | response = configured |
| 1334 | } else { |
| 1335 | response = catalog.ListConfiguredProviderAvailability( |
| 1336 | availability.providerStatus, |
| 1337 | availability.enabledProviderNames, |
| 1338 | ) |
| 1339 | } |
| 1340 | |
| 1341 | httpapi.Write(ctx, rw, http.StatusOK, response) |
| 1342 | } |
| 1343 | |
| 1344 | func (api *API) chatCostSummary(rw http.ResponseWriter, r *http.Request) { |
| 1345 | ctx := r.Context() |
nothing calls this directly
no test coverage detected