🔖 chore: Update variable name to follow naming conventions

This commit is contained in:
MartialBE 2024-05-29 04:58:28 +08:00
parent 021f8c65da
commit c2f8a79be2
No known key found for this signature in database
GPG Key ID: 27C0267EC84B0A5C
14 changed files with 45 additions and 45 deletions

View File

@ -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

View File

@ -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")

View File

@ -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)

View File

@ -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++
}

View File

@ -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))

View File

@ -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,

View File

@ -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
}

View File

@ -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
}

View File

@ -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)
}

View File

@ -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)

View File

@ -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

View File

@ -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...)

View File

@ -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

View File

@ -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, "")
}