(c *gin.Context)
| 25 | } |
| 26 | |
| 27 | func SearchTokenByToken(c *gin.Context) { |
| 28 | var req TokenSearchRequest |
| 29 | if err := c.ShouldBindJSON(&req); err != nil { |
| 30 | common.ApiError(c, err) |
| 31 | return |
| 32 | } |
| 33 | |
| 34 | // 去掉前缀"sk-"后再查询数据库 |
| 35 | tokenKey := strings.TrimPrefix(req.Token, "sk-") |
| 36 | |
| 37 | // 获取token信息 |
| 38 | token, err := model.GetTokenByKey(tokenKey, false) |
| 39 | if err != nil { |
| 40 | common.ApiError(c, err) |
| 41 | return |
| 42 | } |
| 43 | |
| 44 | // 获取配比关系,默认使用gpt-3.5-turbo的配比 |
| 45 | modelRatio, _, _ := ratio_setting.GetModelRatio("gpt-3.5-turbo") |
| 46 | |
| 47 | // 构造返回信息 |
| 48 | response := TokenInfoResponse{ |
| 49 | TokenName: token.Name, |
| 50 | RemainQuota: token.RemainQuota, |
| 51 | UsedQuota: token.UsedQuota, |
| 52 | UnlimitedQuota: token.UnlimitedQuota, |
| 53 | ExpiredTime: token.ExpiredTime, |
| 54 | Status: token.Status, |
| 55 | ModelRatio: modelRatio, |
| 56 | } |
| 57 | |
| 58 | c.JSON(http.StatusOK, gin.H{ |
| 59 | "success": true, |
| 60 | "message": "", |
| 61 | "data": response, |
| 62 | }) |
| 63 | } |
nothing calls this directly
no test coverage detected