diff --git a/common/model-ratio.go b/common/model-ratio.go index 08cde8c70..b1f6df4b2 100644 --- a/common/model-ratio.go +++ b/common/model-ratio.go @@ -78,8 +78,8 @@ var ModelRatio = map[string]float64{ "text-embedding-3-small": 0.01, "text-embedding-3-large": 0.065, "text-search-ada-doc-001": 10, - "text-moderation-stable": 0.1, - "text-moderation-latest": 0.1, + "text-moderation-stable": 0, // free to use + "text-moderation-latest": 0, // free to use "dall-e-2": 8, // $0.016 - $0.020 / image "dall-e-3": 20, // $0.040 - $0.120 / image "claude-instant-1": 0.815, // $1.63 / 1M tokens diff --git a/relay/controller/helper.go b/relay/controller/helper.go index 6154f291a..1b02cd40d 100644 --- a/relay/controller/helper.go +++ b/relay/controller/helper.go @@ -113,12 +113,18 @@ func postConsumeQuota(ctx context.Context, usage *openai.Usage, meta *util.Relay if err != nil { logger.Error(ctx, "error update user quota cache: "+err.Error()) } - if quota != 0 { + + // if model ratio is zero, quota can be zero too + // without setting custom ratios, only "text-moderation-*" from OpenAI is currently 0 + if quota >= 0 { logContent := fmt.Sprintf("模型倍率 %.2f,分组倍率 %.2f,补全倍率 %.2f", modelRatio, groupRatio, completionRatio) model.RecordConsumeLog(ctx, meta.UserId, meta.ChannelId, promptTokens, completionTokens, textRequest.Model, meta.TokenName, quota, logContent) model.UpdateUserUsedQuotaAndRequestCount(meta.UserId, quota) model.UpdateChannelUsedQuota(meta.ChannelId, quota) } + if quota < 0 { + logger.Error(ctx, fmt.Sprintf("quota consumed is %d, something is wrong", quota)) + } } func doRequest(ctx context.Context, c *gin.Context, meta *util.RelayMeta, isStream bool, fullRequestURL string, requestBody io.Reader) (*http.Response, error) {