diff --git a/common/config/constants.go b/common/config/constants.go index f9c55061..5acd1f12 100644 --- a/common/config/constants.go +++ b/common/config/constants.go @@ -93,7 +93,7 @@ var AutomaticEnableChannelEnabled = false var QuotaRemindThreshold = 1000 var PreConsumedQuota = 500 var ApproximateTokenEnabled = false -var DISABLE_TOKEN_ENCODERS = false +var DisableTokenEncoders = false var RetryTimes = 0 var DefaultChannelWeight = uint(1) var RetryCooldownSeconds = 5 diff --git a/common/notify/notifier.go b/common/notify/notifier.go index e1b24d9c..69d5fd21 100644 --- a/common/notify/notifier.go +++ b/common/notify/notifier.go @@ -26,26 +26,26 @@ func InitEmailNotifier() { logger.SysLog("email notifier disabled") return } - smtp_to := viper.GetString("notify.email.smtp_to") - emailNotifier := channel.NewEmail(smtp_to) + smtpTo := viper.GetString("notify.email.smtp_to") + emailNotifier := channel.NewEmail(smtpTo) AddNotifiers(emailNotifier) logger.SysLog("email notifier enable") } func InitDingTalkNotifier() { - access_token := viper.GetString("notify.dingtalk.token") + accessToken := viper.GetString("notify.dingtalk.token") secret := viper.GetString("notify.dingtalk.secret") keyWord := viper.GetString("notify.dingtalk.keyWord") - if access_token == "" || (secret == "" && keyWord == "") { + if accessToken == "" || (secret == "" && keyWord == "") { return } var dingTalkNotifier Notifier if secret != "" { - dingTalkNotifier = channel.NewDingTalk(access_token, secret) + dingTalkNotifier = channel.NewDingTalk(accessToken, secret) } else { - dingTalkNotifier = channel.NewDingTalkWithKeyWord(access_token, keyWord) + dingTalkNotifier = channel.NewDingTalkWithKeyWord(accessToken, keyWord) } AddNotifiers(dingTalkNotifier) @@ -53,19 +53,19 @@ func InitDingTalkNotifier() { } func InitLarkNotifier() { - access_token := viper.GetString("notify.lark.token") + accessToken := viper.GetString("notify.lark.token") secret := viper.GetString("notify.lark.secret") keyWord := viper.GetString("notify.lark.keyWord") - if access_token == "" || (secret == "" && keyWord == "") { + if accessToken == "" || (secret == "" && keyWord == "") { return } var larkNotifier Notifier if secret != "" { - larkNotifier = channel.NewLark(access_token, secret) + larkNotifier = channel.NewLark(accessToken, secret) } else { - larkNotifier = channel.NewLarkWithKeyWord(access_token, keyWord) + larkNotifier = channel.NewLarkWithKeyWord(accessToken, keyWord) } AddNotifiers(larkNotifier) @@ -85,14 +85,14 @@ func InitPushdeerNotifier() { } func InitTelegramNotifier() { - bot_token := viper.GetString("notify.telegram.bot_api_key") - chat_id := viper.GetString("notify.telegram.chat_id") + botToken := viper.GetString("notify.telegram.bot_api_key") + chatId := viper.GetString("notify.telegram.chat_id") httpProxy := viper.GetString("notify.telegram.http_proxy") - if bot_token == "" || chat_id == "" { + if botToken == "" || chatId == "" { return } - telegramNotifier := channel.NewTelegram(bot_token, chat_id, httpProxy) + telegramNotifier := channel.NewTelegram(botToken, chatId, httpProxy) AddNotifiers(telegramNotifier) logger.SysLog("telegram notifier enable") diff --git a/common/requester/ws_requester.go b/common/requester/ws_requester.go index 914e6f1e..b71f5a88 100644 --- a/common/requester/ws_requester.go +++ b/common/requester/ws_requester.go @@ -50,7 +50,7 @@ func SendWSJsonRequest[T streamable](conn *websocket.Conn, data any, handlerPref } // 设置请求头 -func (r *WSRequester) WithHeader(headers map[string]string) http.Header { +func (w *WSRequester) WithHeader(headers map[string]string) http.Header { header := make(http.Header) for k, v := range headers { header.Set(k, v) diff --git a/common/telegram/pagination.go b/common/telegram/pagination.go index c38faff0..2524203b 100644 --- a/common/telegram/pagination.go +++ b/common/telegram/pagination.go @@ -70,10 +70,10 @@ func getPaginationInlineKeyboard(key string, page int, total int) gotgbot.Inline return bt } -func getPageParams(key string, page, size, total_count int) *paginationParams { +func getPageParams(key string, page, size, totalCount int) *paginationParams { // 根据总数计算总页数 - total := total_count / size - if total_count%size > 0 { + total := totalCount / size + if totalCount%size > 0 { total++ } diff --git a/common/token.go b/common/token.go index ba1d985e..f02652ac 100644 --- a/common/token.go +++ b/common/token.go @@ -22,7 +22,7 @@ var gpt4oTokenEncoder *tiktoken.Tiktoken func InitTokenEncoders() { if viper.GetBool("disable_token_encoders") { - config.DISABLE_TOKEN_ENCODERS = true + config.DisableTokenEncoders = true logger.SysLog("token encoders disabled") return } @@ -47,7 +47,7 @@ func InitTokenEncoders() { } func getTokenEncoder(model string) *tiktoken.Tiktoken { - if config.DISABLE_TOKEN_ENCODERS { + if config.DisableTokenEncoders { return nil } @@ -76,7 +76,7 @@ func getTokenEncoder(model string) *tiktoken.Tiktoken { } func getTokenNum(tokenEncoder *tiktoken.Tiktoken, text string) int { - if config.DISABLE_TOKEN_ENCODERS || config.ApproximateTokenEnabled { + if config.DisableTokenEncoders || config.ApproximateTokenEnabled { return int(float64(len(text)) * 0.38) } return len(tokenEncoder.Encode(text, nil, nil)) diff --git a/controller/misc.go b/controller/misc.go index f026262e..98aa405c 100644 --- a/controller/misc.go +++ b/controller/misc.go @@ -15,9 +15,9 @@ import ( ) func GetStatus(c *gin.Context) { - telegram_bot := "" + telegramBot := "" if telegram.TGEnabled { - telegram_bot = telegram.TGBot.User.Username + telegramBot = telegram.TGBot.User.Username } c.JSON(http.StatusOK, gin.H{ @@ -43,7 +43,7 @@ func GetStatus(c *gin.Context) { "chat_link": config.ChatLink, "quota_per_unit": config.QuotaPerUnit, "display_in_currency": config.DisplayInCurrencyEnabled, - "telegram_bot": telegram_bot, + "telegram_bot": telegramBot, "mj_notify_enabled": config.MjNotifyEnabled, "chat_cache_enabled": config.ChatCacheEnabled, "chat_links": config.ChatLinks, diff --git a/model/log.go b/model/log.go index 57ee33d5..638e1d31 100644 --- a/model/log.go +++ b/model/log.go @@ -208,7 +208,7 @@ type LogStatisticGroupModel struct { ModelName string `gorm:"column:model_name"` } -func GetUserModelExpensesByPeriod(user_id, startTimestamp, endTimestamp int) (LogStatistic []*LogStatisticGroupModel, err error) { +func GetUserModelExpensesByPeriod(userId, startTimestamp, endTimestamp int) (LogStatistic []*LogStatisticGroupModel, err error) { groupSelect := getTimestampGroupsSelect("created_at", "day", "date") err = DB.Raw(` @@ -223,7 +223,7 @@ func GetUserModelExpensesByPeriod(user_id, startTimestamp, endTimestamp int) (Lo AND created_at BETWEEN ? AND ? GROUP BY date, model_name ORDER BY date, model_name - `, user_id, startTimestamp, endTimestamp).Scan(&LogStatistic).Error + `, userId, startTimestamp, endTimestamp).Scan(&LogStatistic).Error return } diff --git a/model/token.go b/model/token.go index 44e49fbb..559efe57 100644 --- a/model/token.go +++ b/model/token.go @@ -112,13 +112,13 @@ func GetTokenById(id int) (*Token, error) { return &token, err } -func GetTokenByName(name string, user_id int) (*Token, error) { +func GetTokenByName(name string, userId int) (*Token, error) { if name == "" { return nil, errors.New("name 为空!") } token := Token{Name: name} var err error = nil - err = DB.First(&token, "user_id = ? and name = ?", user_id, name).Error + err = DB.First(&token, "user_id = ? and name = ?", userId, name).Error return &token, err } diff --git a/providers/azure/image_generations.go b/providers/azure/image_generations.go index f34db2f9..7e9a726c 100644 --- a/providers/azure/image_generations.go +++ b/providers/azure/image_generations.go @@ -70,12 +70,12 @@ func (p *AzureProvider) ResponseAzureImageHandler(resp *http.Response, azure *Im return } - operation_location := resp.Header.Get("operation-location") - if operation_location == "" { + operationLocation := resp.Header.Get("operation-location") + if operationLocation == "" { return nil, common.ErrorWrapper(errors.New("image url is empty"), "get_images_url_failed", http.StatusInternalServerError) } - req, err := p.Requester.NewRequest("GET", operation_location, p.Requester.WithHeader(p.GetRequestHeaders())) + req, err := p.Requester.NewRequest("GET", operationLocation, p.Requester.WithHeader(p.GetRequestHeaders())) if err != nil { return nil, common.ErrorWrapper(err, "get_images_request_failed", http.StatusInternalServerError) } diff --git a/providers/zhipu/chat.go b/providers/zhipu/chat.go index fabe557a..982096ae 100644 --- a/providers/zhipu/chat.go +++ b/providers/zhipu/chat.go @@ -189,16 +189,16 @@ func (p *ZhipuProvider) pluginHandle(request *ZhipuRequest) { // 检测是否开启了 retrieval 插件 if pRetrieval, ok := plugin["retrieval"]; ok { - if knowledge_id, ok := pRetrieval["knowledge_id"].(string); ok && knowledge_id != "" { + if knowledgeId, ok := pRetrieval["knowledge_id"].(string); ok && knowledgeId != "" { retrieval := ZhipuTool{ Type: "retrieval", Retrieval: &ZhipuRetrieval{ - KnowledgeId: knowledge_id, + KnowledgeId: knowledgeId, }, } - if prompt_template, ok := pRetrieval["prompt_template"].(string); ok && prompt_template != "" { - retrieval.Retrieval.PromptTemplate = prompt_template + if promptTemplate, ok := pRetrieval["prompt_template"].(string); ok && promptTemplate != "" { + retrieval.Retrieval.PromptTemplate = promptTemplate } request.Tools = append(request.Tools, retrieval) diff --git a/relay/chat.go b/relay/chat.go index e7bb6c26..02d67df9 100644 --- a/relay/chat.go +++ b/relay/chat.go @@ -40,7 +40,7 @@ func (r *relayChat) setRequest() error { } if !r.chatRequest.Stream && r.chatRequest.StreamOptions != nil { - return errors.New("The 'stream_options' parameter is only allowed when 'stream' is enabled.") + return errors.New("the 'stream_options' parameter is only allowed when 'stream' is enabled") } r.originalModel = r.chatRequest.Model diff --git a/relay/common.go b/relay/common.go index 48b67f58..058580c9 100644 --- a/relay/common.go +++ b/relay/common.go @@ -103,14 +103,14 @@ func fetchChannelById(channelId int) (*model.Channel, error) { func fetchChannelByModel(c *gin.Context, modelName string) (*model.Channel, error) { group := c.GetString("group") - skip_channel_id := c.GetInt("skip_channel_id") - skip_only_chat := c.GetBool("skip_only_chat") + skipChannelId := c.GetInt("skip_channel_id") + skipOnlyChat := c.GetBool("skip_only_chat") var filters []model.ChannelsFilterFunc - if skip_only_chat { + if skipOnlyChat { filters = append(filters, model.FilterOnlyChat()) } - if skip_channel_id > 0 { - filters = append(filters, model.FilterChannelId(skip_channel_id)) + if skipChannelId > 0 { + filters = append(filters, model.FilterChannelId(skipChannelId)) } channel, err := model.ChannelGroup.Next(group, modelName, filters...) diff --git a/relay/completions.go b/relay/completions.go index 4aa69136..b78598c1 100644 --- a/relay/completions.go +++ b/relay/completions.go @@ -36,7 +36,7 @@ func (r *relayCompletions) setRequest() error { } if !r.request.Stream && r.request.StreamOptions != nil { - return errors.New("The 'stream_options' parameter is only allowed when 'stream' is enabled.") + return errors.New("the 'stream_options' parameter is only allowed when 'stream' is enabled") } r.originalModel = r.request.Model diff --git a/relay/midjourney/relay-mj.go b/relay/midjourney/relay-mj.go index 0d5d3533..6f3de034 100644 --- a/relay/midjourney/relay-mj.go +++ b/relay/midjourney/relay-mj.go @@ -558,8 +558,8 @@ func getMJProviderWithRequest(c *gin.Context, relayMode int, request *provider.M return getMJProvider(c, midjourneyModel) } -func getMJProviderWithChannelId(c *gin.Context, channel_id int) (*provider.MidjourneyProvider, *provider.MidjourneyResponse) { - c.Set("specific_channel_id", channel_id) +func getMJProviderWithChannelId(c *gin.Context, channelId int) (*provider.MidjourneyProvider, *provider.MidjourneyResponse) { + c.Set("specific_channel_id", channelId) return getMJProvider(c, "") }