🔖 chore: Update variable name to follow naming conventions
This commit is contained in:
parent
021f8c65da
commit
c2f8a79be2
@ -93,7 +93,7 @@ var AutomaticEnableChannelEnabled = false
|
|||||||
var QuotaRemindThreshold = 1000
|
var QuotaRemindThreshold = 1000
|
||||||
var PreConsumedQuota = 500
|
var PreConsumedQuota = 500
|
||||||
var ApproximateTokenEnabled = false
|
var ApproximateTokenEnabled = false
|
||||||
var DISABLE_TOKEN_ENCODERS = false
|
var DisableTokenEncoders = false
|
||||||
var RetryTimes = 0
|
var RetryTimes = 0
|
||||||
var DefaultChannelWeight = uint(1)
|
var DefaultChannelWeight = uint(1)
|
||||||
var RetryCooldownSeconds = 5
|
var RetryCooldownSeconds = 5
|
||||||
|
@ -26,26 +26,26 @@ func InitEmailNotifier() {
|
|||||||
logger.SysLog("email notifier disabled")
|
logger.SysLog("email notifier disabled")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
smtp_to := viper.GetString("notify.email.smtp_to")
|
smtpTo := viper.GetString("notify.email.smtp_to")
|
||||||
emailNotifier := channel.NewEmail(smtp_to)
|
emailNotifier := channel.NewEmail(smtpTo)
|
||||||
AddNotifiers(emailNotifier)
|
AddNotifiers(emailNotifier)
|
||||||
logger.SysLog("email notifier enable")
|
logger.SysLog("email notifier enable")
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitDingTalkNotifier() {
|
func InitDingTalkNotifier() {
|
||||||
access_token := viper.GetString("notify.dingtalk.token")
|
accessToken := viper.GetString("notify.dingtalk.token")
|
||||||
secret := viper.GetString("notify.dingtalk.secret")
|
secret := viper.GetString("notify.dingtalk.secret")
|
||||||
keyWord := viper.GetString("notify.dingtalk.keyWord")
|
keyWord := viper.GetString("notify.dingtalk.keyWord")
|
||||||
if access_token == "" || (secret == "" && keyWord == "") {
|
if accessToken == "" || (secret == "" && keyWord == "") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var dingTalkNotifier Notifier
|
var dingTalkNotifier Notifier
|
||||||
|
|
||||||
if secret != "" {
|
if secret != "" {
|
||||||
dingTalkNotifier = channel.NewDingTalk(access_token, secret)
|
dingTalkNotifier = channel.NewDingTalk(accessToken, secret)
|
||||||
} else {
|
} else {
|
||||||
dingTalkNotifier = channel.NewDingTalkWithKeyWord(access_token, keyWord)
|
dingTalkNotifier = channel.NewDingTalkWithKeyWord(accessToken, keyWord)
|
||||||
}
|
}
|
||||||
|
|
||||||
AddNotifiers(dingTalkNotifier)
|
AddNotifiers(dingTalkNotifier)
|
||||||
@ -53,19 +53,19 @@ func InitDingTalkNotifier() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func InitLarkNotifier() {
|
func InitLarkNotifier() {
|
||||||
access_token := viper.GetString("notify.lark.token")
|
accessToken := viper.GetString("notify.lark.token")
|
||||||
secret := viper.GetString("notify.lark.secret")
|
secret := viper.GetString("notify.lark.secret")
|
||||||
keyWord := viper.GetString("notify.lark.keyWord")
|
keyWord := viper.GetString("notify.lark.keyWord")
|
||||||
if access_token == "" || (secret == "" && keyWord == "") {
|
if accessToken == "" || (secret == "" && keyWord == "") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var larkNotifier Notifier
|
var larkNotifier Notifier
|
||||||
|
|
||||||
if secret != "" {
|
if secret != "" {
|
||||||
larkNotifier = channel.NewLark(access_token, secret)
|
larkNotifier = channel.NewLark(accessToken, secret)
|
||||||
} else {
|
} else {
|
||||||
larkNotifier = channel.NewLarkWithKeyWord(access_token, keyWord)
|
larkNotifier = channel.NewLarkWithKeyWord(accessToken, keyWord)
|
||||||
}
|
}
|
||||||
|
|
||||||
AddNotifiers(larkNotifier)
|
AddNotifiers(larkNotifier)
|
||||||
@ -85,14 +85,14 @@ func InitPushdeerNotifier() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func InitTelegramNotifier() {
|
func InitTelegramNotifier() {
|
||||||
bot_token := viper.GetString("notify.telegram.bot_api_key")
|
botToken := viper.GetString("notify.telegram.bot_api_key")
|
||||||
chat_id := viper.GetString("notify.telegram.chat_id")
|
chatId := viper.GetString("notify.telegram.chat_id")
|
||||||
httpProxy := viper.GetString("notify.telegram.http_proxy")
|
httpProxy := viper.GetString("notify.telegram.http_proxy")
|
||||||
if bot_token == "" || chat_id == "" {
|
if botToken == "" || chatId == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
telegramNotifier := channel.NewTelegram(bot_token, chat_id, httpProxy)
|
telegramNotifier := channel.NewTelegram(botToken, chatId, httpProxy)
|
||||||
|
|
||||||
AddNotifiers(telegramNotifier)
|
AddNotifiers(telegramNotifier)
|
||||||
logger.SysLog("telegram notifier enable")
|
logger.SysLog("telegram notifier enable")
|
||||||
|
@ -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)
|
header := make(http.Header)
|
||||||
for k, v := range headers {
|
for k, v := range headers {
|
||||||
header.Set(k, v)
|
header.Set(k, v)
|
||||||
|
@ -70,10 +70,10 @@ func getPaginationInlineKeyboard(key string, page int, total int) gotgbot.Inline
|
|||||||
return bt
|
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
|
total := totalCount / size
|
||||||
if total_count%size > 0 {
|
if totalCount%size > 0 {
|
||||||
total++
|
total++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ var gpt4oTokenEncoder *tiktoken.Tiktoken
|
|||||||
|
|
||||||
func InitTokenEncoders() {
|
func InitTokenEncoders() {
|
||||||
if viper.GetBool("disable_token_encoders") {
|
if viper.GetBool("disable_token_encoders") {
|
||||||
config.DISABLE_TOKEN_ENCODERS = true
|
config.DisableTokenEncoders = true
|
||||||
logger.SysLog("token encoders disabled")
|
logger.SysLog("token encoders disabled")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ func InitTokenEncoders() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getTokenEncoder(model string) *tiktoken.Tiktoken {
|
func getTokenEncoder(model string) *tiktoken.Tiktoken {
|
||||||
if config.DISABLE_TOKEN_ENCODERS {
|
if config.DisableTokenEncoders {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ func getTokenEncoder(model string) *tiktoken.Tiktoken {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getTokenNum(tokenEncoder *tiktoken.Tiktoken, text string) int {
|
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 int(float64(len(text)) * 0.38)
|
||||||
}
|
}
|
||||||
return len(tokenEncoder.Encode(text, nil, nil))
|
return len(tokenEncoder.Encode(text, nil, nil))
|
||||||
|
@ -15,9 +15,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func GetStatus(c *gin.Context) {
|
func GetStatus(c *gin.Context) {
|
||||||
telegram_bot := ""
|
telegramBot := ""
|
||||||
if telegram.TGEnabled {
|
if telegram.TGEnabled {
|
||||||
telegram_bot = telegram.TGBot.User.Username
|
telegramBot = telegram.TGBot.User.Username
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
@ -43,7 +43,7 @@ func GetStatus(c *gin.Context) {
|
|||||||
"chat_link": config.ChatLink,
|
"chat_link": config.ChatLink,
|
||||||
"quota_per_unit": config.QuotaPerUnit,
|
"quota_per_unit": config.QuotaPerUnit,
|
||||||
"display_in_currency": config.DisplayInCurrencyEnabled,
|
"display_in_currency": config.DisplayInCurrencyEnabled,
|
||||||
"telegram_bot": telegram_bot,
|
"telegram_bot": telegramBot,
|
||||||
"mj_notify_enabled": config.MjNotifyEnabled,
|
"mj_notify_enabled": config.MjNotifyEnabled,
|
||||||
"chat_cache_enabled": config.ChatCacheEnabled,
|
"chat_cache_enabled": config.ChatCacheEnabled,
|
||||||
"chat_links": config.ChatLinks,
|
"chat_links": config.ChatLinks,
|
||||||
|
@ -208,7 +208,7 @@ type LogStatisticGroupModel struct {
|
|||||||
ModelName string `gorm:"column:model_name"`
|
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")
|
groupSelect := getTimestampGroupsSelect("created_at", "day", "date")
|
||||||
|
|
||||||
err = DB.Raw(`
|
err = DB.Raw(`
|
||||||
@ -223,7 +223,7 @@ func GetUserModelExpensesByPeriod(user_id, startTimestamp, endTimestamp int) (Lo
|
|||||||
AND created_at BETWEEN ? AND ?
|
AND created_at BETWEEN ? AND ?
|
||||||
GROUP BY date, model_name
|
GROUP BY date, model_name
|
||||||
ORDER BY date, model_name
|
ORDER BY date, model_name
|
||||||
`, user_id, startTimestamp, endTimestamp).Scan(&LogStatistic).Error
|
`, userId, startTimestamp, endTimestamp).Scan(&LogStatistic).Error
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -112,13 +112,13 @@ func GetTokenById(id int) (*Token, error) {
|
|||||||
return &token, err
|
return &token, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTokenByName(name string, user_id int) (*Token, error) {
|
func GetTokenByName(name string, userId int) (*Token, error) {
|
||||||
if name == "" {
|
if name == "" {
|
||||||
return nil, errors.New("name 为空!")
|
return nil, errors.New("name 为空!")
|
||||||
}
|
}
|
||||||
token := Token{Name: name}
|
token := Token{Name: name}
|
||||||
var err error = nil
|
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
|
return &token, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,12 +70,12 @@ func (p *AzureProvider) ResponseAzureImageHandler(resp *http.Response, azure *Im
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
operation_location := resp.Header.Get("operation-location")
|
operationLocation := resp.Header.Get("operation-location")
|
||||||
if operation_location == "" {
|
if operationLocation == "" {
|
||||||
return nil, common.ErrorWrapper(errors.New("image url is empty"), "get_images_url_failed", http.StatusInternalServerError)
|
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 {
|
if err != nil {
|
||||||
return nil, common.ErrorWrapper(err, "get_images_request_failed", http.StatusInternalServerError)
|
return nil, common.ErrorWrapper(err, "get_images_request_failed", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
@ -189,16 +189,16 @@ func (p *ZhipuProvider) pluginHandle(request *ZhipuRequest) {
|
|||||||
|
|
||||||
// 检测是否开启了 retrieval 插件
|
// 检测是否开启了 retrieval 插件
|
||||||
if pRetrieval, ok := plugin["retrieval"]; ok {
|
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{
|
retrieval := ZhipuTool{
|
||||||
Type: "retrieval",
|
Type: "retrieval",
|
||||||
Retrieval: &ZhipuRetrieval{
|
Retrieval: &ZhipuRetrieval{
|
||||||
KnowledgeId: knowledge_id,
|
KnowledgeId: knowledgeId,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if prompt_template, ok := pRetrieval["prompt_template"].(string); ok && prompt_template != "" {
|
if promptTemplate, ok := pRetrieval["prompt_template"].(string); ok && promptTemplate != "" {
|
||||||
retrieval.Retrieval.PromptTemplate = prompt_template
|
retrieval.Retrieval.PromptTemplate = promptTemplate
|
||||||
}
|
}
|
||||||
|
|
||||||
request.Tools = append(request.Tools, retrieval)
|
request.Tools = append(request.Tools, retrieval)
|
||||||
|
@ -40,7 +40,7 @@ func (r *relayChat) setRequest() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !r.chatRequest.Stream && r.chatRequest.StreamOptions != nil {
|
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
|
r.originalModel = r.chatRequest.Model
|
||||||
|
@ -103,14 +103,14 @@ func fetchChannelById(channelId int) (*model.Channel, error) {
|
|||||||
|
|
||||||
func fetchChannelByModel(c *gin.Context, modelName string) (*model.Channel, error) {
|
func fetchChannelByModel(c *gin.Context, modelName string) (*model.Channel, error) {
|
||||||
group := c.GetString("group")
|
group := c.GetString("group")
|
||||||
skip_channel_id := c.GetInt("skip_channel_id")
|
skipChannelId := c.GetInt("skip_channel_id")
|
||||||
skip_only_chat := c.GetBool("skip_only_chat")
|
skipOnlyChat := c.GetBool("skip_only_chat")
|
||||||
var filters []model.ChannelsFilterFunc
|
var filters []model.ChannelsFilterFunc
|
||||||
if skip_only_chat {
|
if skipOnlyChat {
|
||||||
filters = append(filters, model.FilterOnlyChat())
|
filters = append(filters, model.FilterOnlyChat())
|
||||||
}
|
}
|
||||||
if skip_channel_id > 0 {
|
if skipChannelId > 0 {
|
||||||
filters = append(filters, model.FilterChannelId(skip_channel_id))
|
filters = append(filters, model.FilterChannelId(skipChannelId))
|
||||||
}
|
}
|
||||||
|
|
||||||
channel, err := model.ChannelGroup.Next(group, modelName, filters...)
|
channel, err := model.ChannelGroup.Next(group, modelName, filters...)
|
||||||
|
@ -36,7 +36,7 @@ func (r *relayCompletions) setRequest() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !r.request.Stream && r.request.StreamOptions != nil {
|
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
|
r.originalModel = r.request.Model
|
||||||
|
@ -558,8 +558,8 @@ func getMJProviderWithRequest(c *gin.Context, relayMode int, request *provider.M
|
|||||||
return getMJProvider(c, midjourneyModel)
|
return getMJProvider(c, midjourneyModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMJProviderWithChannelId(c *gin.Context, channel_id int) (*provider.MidjourneyProvider, *provider.MidjourneyResponse) {
|
func getMJProviderWithChannelId(c *gin.Context, channelId int) (*provider.MidjourneyProvider, *provider.MidjourneyResponse) {
|
||||||
c.Set("specific_channel_id", channel_id)
|
c.Set("specific_channel_id", channelId)
|
||||||
|
|
||||||
return getMJProvider(c, "")
|
return getMJProvider(c, "")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user