From 46c43396d8f8c23ad2c3f2f5a669475ea7a3794c Mon Sep 17 00:00:00 2001 From: Miniers Date: Sat, 17 Jun 2023 14:56:03 +0800 Subject: [PATCH] feat: add token name to log (#172) * add token name to log * chore: update expression --------- Co-authored-by: JustSong --- controller/relay.go | 3 ++- middleware/auth.go | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/controller/relay.go b/controller/relay.go index cf01f180..6d957a0a 100644 --- a/controller/relay.go +++ b/controller/relay.go @@ -259,8 +259,9 @@ func relayHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode { if err != nil { common.SysError("Error consuming token remain quota: " + err.Error()) } + tokenName := c.GetString("token_name") userId := c.GetInt("id") - model.RecordLog(userId, model.LogTypeConsume, fmt.Sprintf("使用模型 %s 消耗 %d 点额度(模型倍率 %.2f,分组倍率 %.2f)", textRequest.Model, quota, modelRatio, groupRatio)) + model.RecordLog(userId, model.LogTypeConsume, fmt.Sprintf("通过令牌「%s」使用模型 %s 消耗 %d 点额度(模型倍率 %.2f,分组倍率 %.2f)", tokenName, textRequest.Model, quota, modelRatio, groupRatio)) model.UpdateUserUsedQuotaAndRequestCount(userId, quota) channelId := c.GetInt("channel_id") model.UpdateChannelUsedQuota(channelId, quota) diff --git a/middleware/auth.go b/middleware/auth.go index f652f058..c172078c 100644 --- a/middleware/auth.go +++ b/middleware/auth.go @@ -112,6 +112,7 @@ func TokenAuth() func(c *gin.Context) { } c.Set("id", token.UserId) c.Set("token_id", token.Id) + c.Set("token_name", token.Name) requestURL := c.Request.URL.String() consumeQuota := true if strings.HasPrefix(requestURL, "/v1/models") {