From b8fb351fd80d53f8631dfb8d61af6f66f3253efc Mon Sep 17 00:00:00 2001 From: CaIon <1808837298@qq.com> Date: Sat, 20 Apr 2024 17:18:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9C=A8=E9=87=8D=E8=AF=95=E6=97=B6?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E9=87=8D=E8=AF=95=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/relay.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/controller/relay.go b/controller/relay.go index 0fd9d7a..089bde2 100644 --- a/controller/relay.go +++ b/controller/relay.go @@ -15,6 +15,7 @@ import ( "one-api/relay/constant" relayconstant "one-api/relay/constant" "one-api/service" + "strings" ) func relayHandler(c *gin.Context, relayMode int) *dto.OpenAIErrorWithStatusCode { @@ -42,7 +43,7 @@ func Relay(c *gin.Context) { group := c.GetString("group") originalModel := c.GetString("original_model") openaiErr := relayHandler(c, relayMode) - retryLogStr := fmt.Sprintf("重试:%d", channelId) + useChannel := []int{channelId} if openaiErr != nil { go processChannelError(c, channelId, openaiErr) } else { @@ -55,7 +56,7 @@ func Relay(c *gin.Context) { break } channelId = channel.Id - retryLogStr += fmt.Sprintf("->%d", channel.Id) + useChannel = append(useChannel, channelId) common.LogInfo(c.Request.Context(), fmt.Sprintf("using channel #%d to retry (remain times %d)", channel.Id, i)) middleware.SetupContextForSelectedChannel(c, channel, originalModel) @@ -66,7 +67,10 @@ func Relay(c *gin.Context) { go processChannelError(c, channelId, openaiErr) } } - common.LogInfo(c.Request.Context(), retryLogStr) + if len(useChannel) > 1 { + retryLogStr := fmt.Sprintf("重试:%s", strings.Trim(strings.Join(strings.Fields(fmt.Sprint(useChannel)), "->"), "[]")) + common.LogInfo(c.Request.Context(), retryLogStr) + } if openaiErr != nil { if openaiErr.StatusCode == http.StatusTooManyRequests {