(c *gin.Context)
| 58 | } |
| 59 | |
| 60 | func GetUsage(c *gin.Context) { |
| 61 | var quota int |
| 62 | var err error |
| 63 | var token *model.Token |
| 64 | if common.DisplayTokenStatEnabled { |
| 65 | tokenId := c.GetInt("token_id") |
| 66 | token, err = model.GetTokenById(tokenId) |
| 67 | quota = token.UsedQuota |
| 68 | } else { |
| 69 | userId := c.GetInt("id") |
| 70 | quota, err = model.GetUserUsedQuota(userId) |
| 71 | } |
| 72 | if err != nil { |
| 73 | openAIError := dto.OpenAIError{ |
| 74 | Message: err.Error(), |
| 75 | Type: "new_api_error", |
| 76 | } |
| 77 | c.JSON(200, gin.H{ |
| 78 | "error": openAIError, |
| 79 | }) |
| 80 | return |
| 81 | } |
| 82 | amount := float64(quota) |
| 83 | if common.DisplayInCurrencyEnabled { |
| 84 | amount /= common.QuotaPerUnit |
| 85 | } |
| 86 | usage := OpenAIUsageResponse{ |
| 87 | Object: "list", |
| 88 | TotalUsage: amount * 100, |
| 89 | } |
| 90 | c.JSON(200, usage) |
| 91 | return |
| 92 | } |
nothing calls this directly
no test coverage detected