Skip to content

Commit

Permalink
feat: 余额不足提示中文增强引导性
Browse files Browse the repository at this point in the history
  • Loading branch information
jinjianming committed Jul 17, 2024
1 parent adba54a commit e9d4226
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions relay/controller/audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ func RelayAudioHelper(c *gin.Context, relayMode int) *relaymodel.ErrorWithStatus
return openai.ErrorWrapper(err, "get_user_quota_failed", http.StatusInternalServerError)
}

// Check if user quota is enough
// Check if user quota is enough Message prompts the user to use Chinese
if userQuota-preConsumedQuota < 0 {
return openai.ErrorWrapper(errors.New("user quota is not enough"), "insufficient_user_quota", http.StatusForbidden)
return openai.ErrorWrapper(errors.New("请移步充值页面进行充值,可在日志中查阅使用明细"), "insufficient_user_quota", http.StatusForbidden)

Check warning on line 76 in relay/controller/audio.go

View check run for this annotation

Codecov / codecov/patch

relay/controller/audio.go#L76

Added line #L76 was not covered by tests
}
err = model.CacheDecreaseUserQuota(userId, preConsumedQuota)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion relay/controller/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ func preConsumeQuota(ctx context.Context, textRequest *relaymodel.GeneralOpenAIR
if err != nil {
return preConsumedQuota, openai.ErrorWrapper(err, "get_user_quota_failed", http.StatusInternalServerError)
}
// Check if user quota is enough Message prompts the user to use Chinese
if userQuota-preConsumedQuota < 0 {
return preConsumedQuota, openai.ErrorWrapper(errors.New("user quota is not enough"), "insufficient_user_quota", http.StatusForbidden)
return preConsumedQuota, openai.ErrorWrapper(errors.New("请移步充值页面进行充值,可在日志中查阅使用明细"), "insufficient_user_quota", http.StatusForbidden)

Check warning on line 73 in relay/controller/helper.go

View check run for this annotation

Codecov / codecov/patch

relay/controller/helper.go#L73

Added line #L73 was not covered by tests

}
err = model.CacheDecreaseUserQuota(meta.UserId, preConsumedQuota)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions relay/controller/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ func RelayImageHelper(c *gin.Context, relayMode int) *relaymodel.ErrorWithStatus
userQuota, err := model.CacheGetUserQuota(ctx, meta.UserId)

quota := int64(ratio*imageCostRatio*1000) * int64(imageRequest.N)

// Check if user quota is enough Message prompts the user to use Chinese
if userQuota-quota < 0 {
return openai.ErrorWrapper(errors.New("user quota is not enough"), "insufficient_user_quota", http.StatusForbidden)
return openai.ErrorWrapper(errors.New("请移步充值页面进行充值,可在日志中查阅使用明细"), "insufficient_user_quota", http.StatusForbidden)

Check warning on line 178 in relay/controller/image.go

View check run for this annotation

Codecov / codecov/patch

relay/controller/image.go#L178

Added line #L178 was not covered by tests
}

// do request
Expand Down

0 comments on commit e9d4226

Please sign in to comment.