From 53b2cace0b5ea70fc5bbcc05d1d5cc5b9d653c00 Mon Sep 17 00:00:00 2001 From: JustSong Date: Fri, 29 Sep 2023 18:13:57 +0800 Subject: [PATCH] chore: sync model schema --- model/channel.go | 2 +- model/log.go | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/model/channel.go b/model/channel.go index aa3b8a10..61fe9093 100644 --- a/model/channel.go +++ b/model/channel.go @@ -11,7 +11,7 @@ type Channel struct { Key string `json:"key" gorm:"not null;index"` Status int `json:"status" gorm:"default:1"` Name string `json:"name" gorm:"index"` - Weight int `json:"weight"` + Weight *uint `json:"weight" gorm:"default:0"` CreatedTime int64 `json:"created_time" gorm:"bigint"` TestTime int64 `json:"test_time" gorm:"bigint"` ResponseTime int `json:"response_time"` // in milliseconds diff --git a/model/log.go b/model/log.go index 8e177258..c189e01d 100644 --- a/model/log.go +++ b/model/log.go @@ -9,7 +9,7 @@ import ( type Log struct { Id int `json:"id"` - UserId int `json:"user_id"` + UserId int `json:"user_id" gorm:"index"` CreatedAt int64 `json:"created_at" gorm:"bigint;index"` Type int `json:"type" gorm:"index"` Content string `json:"content"` @@ -19,7 +19,7 @@ type Log struct { Quota int `json:"quota" gorm:"default:0"` PromptTokens int `json:"prompt_tokens" gorm:"default:0"` CompletionTokens int `json:"completion_tokens" gorm:"default:0"` - Channel int `json:"channel" gorm:"default:0"` + ChannelId int `json:"channel" gorm:"index"` } const ( @@ -47,7 +47,6 @@ func RecordLog(userId int, logType int, content string) { } } - func RecordConsumeLog(ctx context.Context, userId int, channelId int, promptTokens int, completionTokens int, modelName string, tokenName string, quota int, content string) { common.LogInfo(ctx, fmt.Sprintf("record consume log: userId=%d, channelId=%d, promptTokens=%d, completionTokens=%d, modelName=%s, tokenName=%s, quota=%d, content=%s", userId, channelId, promptTokens, completionTokens, modelName, tokenName, quota, content)) if !common.LogConsumeEnabled { @@ -64,7 +63,7 @@ func RecordConsumeLog(ctx context.Context, userId int, channelId int, promptToke TokenName: tokenName, ModelName: modelName, Quota: quota, - Channel: channelId, + ChannelId: channelId, } err := DB.Create(log).Error if err != nil {