Browse Source

fix: error channel name on notify. #338

CalciumIon 1 year ago
parent
commit
1501ccb919
2 changed files with 7 additions and 7 deletions
  1. 5 5
      controller/relay.go
  2. 2 2
      model/channel.go

+ 5 - 5
controller/relay.go

@@ -43,12 +43,13 @@ func Relay(c *gin.Context) {
 	requestId := c.GetString(common.RequestIdKey)
 	requestId := c.GetString(common.RequestIdKey)
 	channelId := c.GetInt("channel_id")
 	channelId := c.GetInt("channel_id")
 	channelType := c.GetInt("channel_type")
 	channelType := c.GetInt("channel_type")
+	channelName := c.GetString("channel_name")
 	group := c.GetString("group")
 	group := c.GetString("group")
 	originalModel := c.GetString("original_model")
 	originalModel := c.GetString("original_model")
 	openaiErr := relayHandler(c, relayMode)
 	openaiErr := relayHandler(c, relayMode)
 	c.Set("use_channel", []string{fmt.Sprintf("%d", channelId)})
 	c.Set("use_channel", []string{fmt.Sprintf("%d", channelId)})
 	if openaiErr != nil {
 	if openaiErr != nil {
-		go processChannelError(c, channelId, channelType, openaiErr)
+		go processChannelError(c, channelId, channelType, channelName, openaiErr)
 	} else {
 	} else {
 		retryTimes = 0
 		retryTimes = 0
 	}
 	}
@@ -60,7 +61,7 @@ func Relay(c *gin.Context) {
 		}
 		}
 		channelId = channel.Id
 		channelId = channel.Id
 		useChannel := c.GetStringSlice("use_channel")
 		useChannel := c.GetStringSlice("use_channel")
-		useChannel = append(useChannel, fmt.Sprintf("%d", channelId))
+		useChannel = append(useChannel, fmt.Sprintf("%d", channel.Id))
 		c.Set("use_channel", useChannel)
 		c.Set("use_channel", useChannel)
 		common.LogInfo(c.Request.Context(), fmt.Sprintf("using channel #%d to retry (remain times %d)", channel.Id, i))
 		common.LogInfo(c.Request.Context(), fmt.Sprintf("using channel #%d to retry (remain times %d)", channel.Id, i))
 		middleware.SetupContextForSelectedChannel(c, channel, originalModel)
 		middleware.SetupContextForSelectedChannel(c, channel, originalModel)
@@ -69,7 +70,7 @@ func Relay(c *gin.Context) {
 		c.Request.Body = io.NopCloser(bytes.NewBuffer(requestBody))
 		c.Request.Body = io.NopCloser(bytes.NewBuffer(requestBody))
 		openaiErr = relayHandler(c, relayMode)
 		openaiErr = relayHandler(c, relayMode)
 		if openaiErr != nil {
 		if openaiErr != nil {
-			go processChannelError(c, channelId, channel.Type, openaiErr)
+			go processChannelError(c, channel.Id, channel.Type, channel.Name, openaiErr)
 		}
 		}
 	}
 	}
 	useChannel := c.GetStringSlice("use_channel")
 	useChannel := c.GetStringSlice("use_channel")
@@ -128,11 +129,10 @@ func shouldRetry(c *gin.Context, channelId int, openaiErr *dto.OpenAIErrorWithSt
 	return true
 	return true
 }
 }
 
 
-func processChannelError(c *gin.Context, channelId int, channelType int, err *dto.OpenAIErrorWithStatusCode) {
+func processChannelError(c *gin.Context, channelId int, channelType int, channelName string, err *dto.OpenAIErrorWithStatusCode) {
 	autoBan := c.GetBool("auto_ban")
 	autoBan := c.GetBool("auto_ban")
 	common.LogError(c.Request.Context(), fmt.Sprintf("relay error (channel #%d, status code: %d): %s", channelId, err.StatusCode, err.Error.Message))
 	common.LogError(c.Request.Context(), fmt.Sprintf("relay error (channel #%d, status code: %d): %s", channelId, err.StatusCode, err.Error.Message))
 	if service.ShouldDisableChannel(channelType, err) && autoBan {
 	if service.ShouldDisableChannel(channelType, err) && autoBan {
-		channelName := c.GetString("channel_name")
 		service.DisableChannel(channelId, channelName, err.Error.Message)
 		service.DisableChannel(channelId, channelName, err.Error.Message)
 	}
 	}
 }
 }

+ 2 - 2
model/channel.go

@@ -100,8 +100,8 @@ func SearchChannels(keyword string, group string, model string) ([]*Channel, err
 	var whereClause string
 	var whereClause string
 	var args []interface{}
 	var args []interface{}
 	if group != "" {
 	if group != "" {
-		whereClause = "(id = ? OR name LIKE ? OR " + keyCol + " = ?) AND " + groupCol + " LIKE ? AND " + modelsCol + " LIKE ?"
-		args = append(args, common.String2Int(keyword), "%"+keyword+"%", keyword, "%"+group+"%", "%"+model+"%")
+		whereClause = "(id = ? OR name LIKE ? OR " + keyCol + " = ?) AND " + groupCol + " = ? AND " + modelsCol + " LIKE ?"
+		args = append(args, common.String2Int(keyword), "%"+keyword+"%", keyword, group, "%"+model+"%")
 	} else {
 	} else {
 		whereClause = "(id = ? OR name LIKE ? OR " + keyCol + " = ?) AND " + modelsCol + " LIKE ?"
 		whereClause = "(id = ? OR name LIKE ? OR " + keyCol + " = ?) AND " + modelsCol + " LIKE ?"
 		args = append(args, common.String2Int(keyword), "%"+keyword+"%", keyword, "%"+model+"%")
 		args = append(args, common.String2Int(keyword), "%"+keyword+"%", keyword, "%"+model+"%")