From 5213bdf08ba96a15d550a92e561a29a71a3ac841 Mon Sep 17 00:00:00 2001 From: RockYang Date: Sun, 19 Jan 2025 13:08:38 +0800 Subject: [PATCH] fixed bug for calculate chat message tokens --- api/handler/chatimpl/chat_handler.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/api/handler/chatimpl/chat_handler.go b/api/handler/chatimpl/chat_handler.go index 8ea002fa..bf686d31 100644 --- a/api/handler/chatimpl/chat_handler.go +++ b/api/handler/chatimpl/chat_handler.go @@ -379,17 +379,17 @@ func (h *ChatHandler) Tokens(c *gin.Context) { } // 如果没有传入 text 字段,则说明是获取当前 reply 总的 token 消耗(带上下文) - if data.Text == "" && data.ChatId != "" { - var item model.ChatMessage - userId, _ := c.Get(types.LoginUserID) - res := h.DB.Where("user_id = ?", userId).Where("chat_id = ?", data.ChatId).Last(&item) - if res.Error != nil { - resp.ERROR(c, res.Error.Error()) - return - } - resp.SUCCESS(c, item.Tokens) - return - } + //if data.Text == "" && data.ChatId != "" { + // var item model.ChatMessage + // userId, _ := c.Get(types.LoginUserID) + // res := h.DB.Where("user_id = ?", userId).Where("chat_id = ?", data.ChatId).Last(&item) + // if res.Error != nil { + // resp.ERROR(c, res.Error.Error()) + // return + // } + // resp.SUCCESS(c, item.Tokens) + // return + //} tokens, err := utils.CalcTokens(data.Text, data.Model) if err != nil {