mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-09-17 16:56:38 +08:00
fix: 用户使用自己绑定的 API 调用,则不计算 calls 和 token 消耗
This commit is contained in:
parent
9940e1210e
commit
49646a79e5
@ -151,7 +151,7 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session types.ChatSession
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if userVo.Calls <= 0 {
|
if userVo.Calls <= 0 && userVo.ChatConfig.ApiKey == "" {
|
||||||
replyMessage(ws, "您的对话次数已经用尽,请联系管理员充值!")
|
replyMessage(ws, "您的对话次数已经用尽,请联系管理员充值!")
|
||||||
replyMessage(ws, "")
|
replyMessage(ws, "")
|
||||||
return nil
|
return nil
|
||||||
@ -327,9 +327,11 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session types.ChatSession
|
|||||||
// 消息发送成功
|
// 消息发送成功
|
||||||
if len(contents) > 0 {
|
if len(contents) > 0 {
|
||||||
// 更新用户的对话次数
|
// 更新用户的对话次数
|
||||||
res := h.db.Model(&user).UpdateColumn("calls", gorm.Expr("calls - ?", 1))
|
if userVo.ChatConfig.ApiKey == "" { // 如果用户使用的是自己绑定的 API KEY 则不扣减对话次数
|
||||||
if res.Error != nil {
|
res := h.db.Model(&user).UpdateColumn("calls", gorm.Expr("calls - ?", 1))
|
||||||
return res.Error
|
if res.Error != nil {
|
||||||
|
return res.Error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if message.Role == "" {
|
if message.Role == "" {
|
||||||
@ -408,8 +410,10 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session types.ChatSession
|
|||||||
totalTokens += getTotalTokens(req)
|
totalTokens += getTotalTokens(req)
|
||||||
}
|
}
|
||||||
//replyChunkMessage(ws, types.WsMessage{Type: types.WsMiddle, Content: fmt.Sprintf("\n\n `本轮对话共消耗 Token 数量: %d`", totalTokens+11)})
|
//replyChunkMessage(ws, types.WsMessage{Type: types.WsMiddle, Content: fmt.Sprintf("\n\n `本轮对话共消耗 Token 数量: %d`", totalTokens+11)})
|
||||||
h.db.Model(&user).UpdateColumn("tokens", gorm.Expr("tokens + ?",
|
if userVo.ChatConfig.ApiKey != "" { // 调用自己的 API KEY 不计算 token 消耗
|
||||||
totalTokens))
|
h.db.Model(&user).UpdateColumn("tokens", gorm.Expr("tokens + ?",
|
||||||
|
totalTokens))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存当前会话
|
// 保存当前会话
|
||||||
|
Loading…
Reference in New Issue
Block a user