MCPcopy Create free account
hub / github.com/tbphp/gpt-load / handleModelListResponse

Method handleModelListResponse

internal/proxy/model_list_handler.go:28–54  ·  view source on GitHub ↗

handleModelListResponse processes the model list response and applies filtering based on redirect rules

(c *gin.Context, resp *http.Response, group *models.Group, channelHandler channel.ChannelProxy)

Source from the content-addressed store, hash-verified

26
27// handleModelListResponse processes the model list response and applies filtering based on redirect rules
28func (ps *ProxyServer) handleModelListResponse(c *gin.Context, resp *http.Response, group *models.Group, channelHandler channel.ChannelProxy) {
29 // Read the upstream response body
30 bodyBytes, err := io.ReadAll(resp.Body)
31 if err != nil {
32 logrus.WithError(err).Error("Failed to read model list response body")
33 c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to read response"})
34 return
35 }
36
37 // Decompress response data based on Content-Encoding
38 contentEncoding := resp.Header.Get("Content-Encoding")
39 decompressed, err := utils.DecompressResponse(contentEncoding, bodyBytes)
40 if err != nil {
41 logrus.WithError(err).Warn("Decompression failed, using original data")
42 decompressed = bodyBytes
43 }
44
45 // Transform model list (returns map[string]any directly, no marshaling)
46 response, err := channelHandler.TransformModelList(c.Request, decompressed, group)
47 if err != nil {
48 logrus.WithError(err).Error("Failed to transform model list")
49 c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to process response"})
50 return
51 }
52
53 c.JSON(http.StatusOK, response)
54}

Callers 1

Calls 4

DecompressResponseFunction · 0.92
GetMethod · 0.65
TransformModelListMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected