mirror of
				https://github.com/yangjian102621/geekai.git
				synced 2025-11-04 16:23:42 +08:00 
			
		
		
		
	feat: 增加用户 token 消耗统计功能
This commit is contained in:
		@@ -319,6 +319,10 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session types.ChatSession
 | 
			
		||||
				if res.Error != nil {
 | 
			
		||||
					logger.Error("failed to save reply history message: ", res.Error)
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				// 统计用户 token 数量
 | 
			
		||||
				h.db.Model(&user).UpdateColumn("tokens", gorm.Expr("tokens + ?",
 | 
			
		||||
					historyUserMsg.Tokens+historyReplyMsg.Tokens))
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			// 保存当前会话
 | 
			
		||||
 
 | 
			
		||||
@@ -240,7 +240,7 @@ type userProfile struct {
 | 
			
		||||
	Avatar     string           `json:"avatar"`
 | 
			
		||||
	ChatConfig types.ChatConfig `json:"chat_config"`
 | 
			
		||||
	Calls      int              `json:"calls"`
 | 
			
		||||
	Tokens     int              `json:"tokens"`
 | 
			
		||||
	Tokens     int64            `json:"tokens"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (h *UserHandler) Profile(c *gin.Context) {
 | 
			
		||||
 
 | 
			
		||||
@@ -3,7 +3,7 @@
 | 
			
		||||
      v-model="showDialog"
 | 
			
		||||
      :close-on-click-modal="false"
 | 
			
		||||
      :before-close="close"
 | 
			
		||||
      :top="top"
 | 
			
		||||
      :top="50+'px'"
 | 
			
		||||
      title="用户设置"
 | 
			
		||||
  >
 | 
			
		||||
    <div class="user-info" id="user-info">
 | 
			
		||||
@@ -53,7 +53,7 @@
 | 
			
		||||
        <el-form-item label="剩余调用次数">
 | 
			
		||||
          <el-tag>{{ form['calls'] }}</el-tag>
 | 
			
		||||
        </el-form-item>
 | 
			
		||||
        <el-form-item label="剩余 Tokens">
 | 
			
		||||
        <el-form-item label="消耗 Tokens">
 | 
			
		||||
          <el-tag type="info">{{ form['tokens'] }}</el-tag>
 | 
			
		||||
        </el-form-item>
 | 
			
		||||
        <el-form-item label="API KEY">
 | 
			
		||||
@@ -100,13 +100,6 @@ const form = ref({
 | 
			
		||||
  tokens: 0,
 | 
			
		||||
  chat_configs: {}
 | 
			
		||||
})
 | 
			
		||||
const top = computed(() => {
 | 
			
		||||
  if (window.innerHeight < 1024) {
 | 
			
		||||
    return '5vh';
 | 
			
		||||
  } else {
 | 
			
		||||
    return '15vh';
 | 
			
		||||
  }
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
onMounted(() => {
 | 
			
		||||
  // 获取最新用户信息
 | 
			
		||||
 
 | 
			
		||||
@@ -35,7 +35,7 @@
 | 
			
		||||
            </template>
 | 
			
		||||
          </van-field>
 | 
			
		||||
 | 
			
		||||
          <van-field label="剩余 Tokens">
 | 
			
		||||
          <van-field label="消耗 Tokens">
 | 
			
		||||
            <template #input>
 | 
			
		||||
              <van-tag type="primary">{{ form.tokens }}</van-tag>
 | 
			
		||||
            </template>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user