(c *gin.Context)
| 115 | } |
| 116 | |
| 117 | func models(c *gin.Context) { |
| 118 | client := groqHttp.NewBasicClient() |
| 119 | proxyUrl := global.ProxyPool.GetProxyIP() |
| 120 | if proxyUrl != "" { |
| 121 | client.SetProxy(proxyUrl) |
| 122 | } |
| 123 | authorization := c.Request.Header.Get("Authorization") |
| 124 | account := global.AccountPool.Get() |
| 125 | if authorization != "" { |
| 126 | customToken := strings.Replace(authorization, "Bearer ", "", 1) |
| 127 | if customToken != "" { |
| 128 | // 说明传递的是session_token |
| 129 | if strings.HasPrefix(customToken, "eyJhbGciOiJSUzI1NiI") { |
| 130 | account = groq.NewAccount("", "") |
| 131 | err := authSessionHandler(client, account, customToken, "") |
| 132 | if err != nil { |
| 133 | c.JSON(400, gin.H{"error": err.Error()}) |
| 134 | c.Abort() |
| 135 | return |
| 136 | } |
| 137 | } |
| 138 | if len(customToken) == 44 { |
| 139 | account = groq.NewAccount(customToken, "") |
| 140 | err := authRefreshHandler(client, account, customToken, "") |
| 141 | if err != nil { |
| 142 | c.JSON(400, gin.H{"error": err.Error()}) |
| 143 | c.Abort() |
| 144 | return |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | if _, ok := global.Cache.Get(account.Organization); !ok { |
| 151 | err := authRefreshHandler(client, account, account.SessionToken, "") |
| 152 | if err != nil { |
| 153 | c.JSON(400, gin.H{"error": err.Error()}) |
| 154 | c.Abort() |
| 155 | return |
| 156 | } |
| 157 | } |
| 158 | api_key, _ := global.Cache.Get(account.Organization) |
| 159 | response, err := groqHttp.GetModels(client, api_key.(string), account.Organization, "") |
| 160 | if err != nil { |
| 161 | c.JSON(400, gin.H{"error": err.Error()}) |
| 162 | c.Abort() |
| 163 | return |
| 164 | } |
| 165 | var mo groq.Models |
| 166 | |
| 167 | if err := json.NewDecoder(response.Body).Decode(&mo); err != nil { |
| 168 | c.JSON(400, gin.H{"error": err.Error()}) |
| 169 | c.Abort() |
| 170 | return |
| 171 | } |
| 172 | c.JSON(http.StatusOK, mo) |
| 173 | } |
| 174 |
nothing calls this directly
no test coverage detected