Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update: sync "text-moderation-*" model prices and record zero quota log #979

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions common/model-ratio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion relay/controller/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down