|
|
@@ -221,7 +221,7 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
|
|
|
if err != nil {
|
|
|
return errorWrapper(err, "get_user_quota_failed", http.StatusInternalServerError)
|
|
|
}
|
|
|
- if userQuota-preConsumedQuota < 0 {
|
|
|
+ if userQuota < 0 || userQuota-preConsumedQuota < 0 {
|
|
|
return errorWrapper(errors.New("user quota is not enough"), "insufficient_user_quota", http.StatusForbidden)
|
|
|
}
|
|
|
err = model.CacheDecreaseUserQuota(userId, preConsumedQuota)
|
|
|
@@ -232,7 +232,7 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
|
|
|
// in this case, we do not pre-consume quota
|
|
|
// because the user has enough quota
|
|
|
preConsumedQuota = 0
|
|
|
- //common.LogInfo(c.Request.Context(), fmt.Sprintf("user %d has enough quota %d, trusted and no need to pre-consume", userId, userQuota))
|
|
|
+ common.LogInfo(c.Request.Context(), fmt.Sprintf("user %d has enough quota %d, trusted and no need to pre-consume", userId, userQuota))
|
|
|
}
|
|
|
if preConsumedQuota > 0 {
|
|
|
userQuota, err = model.PreConsumeTokenQuota(tokenId, preConsumedQuota)
|