From 338363f0ee8db68a2187b3acc971913f397d6b80 Mon Sep 17 00:00:00 2001 From: ImYrS <44287632+imyrs@users.noreply.github.com> Date: Sun, 28 Jan 2024 21:26:17 +0800 Subject: [PATCH 1/2] chore: update model prices --- common/model-ratio.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/model-ratio.go b/common/model-ratio.go index 08cde8c70b..b1f6df4b21 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 From c1db6dc0f780e78c163551fd11aff494a63b72b5 Mon Sep 17 00:00:00 2001 From: ImYrS <44287632+imyrs@users.noreply.github.com> Date: Sun, 28 Jan 2024 22:18:49 +0800 Subject: [PATCH 2/2] update: record consume logs of 0 quota --- relay/controller/helper.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/relay/controller/helper.go b/relay/controller/helper.go index 6154f291a6..1b02cd40d6 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) {