(c *gin.Context)
| 176 | } |
| 177 | |
| 178 | func RelayClaude(c *gin.Context) { |
| 179 | //relayMode := constant.Path2RelayMode(c.Request.URL.Path) |
| 180 | log.Println("===========RelayClaude==========", c) |
| 181 | requestId := c.GetString(common.RequestIdKey) |
| 182 | group := c.GetString("group") |
| 183 | originalModel := c.GetString("original_model") |
| 184 | var newAPIError *types.NewAPIError |
| 185 | |
| 186 | for i := 0; i <= common.RetryTimes; i++ { |
| 187 | channel, err := getChannel(c, group, originalModel, i) |
| 188 | if err != nil { |
| 189 | common.LogError(c, err.Error()) |
| 190 | newAPIError = err |
| 191 | break |
| 192 | } |
| 193 | |
| 194 | newAPIError = claudeRequest(c, channel) |
| 195 | |
| 196 | if newAPIError == nil { |
| 197 | return // 成功处理请求,直接返回 |
| 198 | } |
| 199 | |
| 200 | go processChannelError(c, *types.NewChannelError(channel.Id, channel.Type, channel.Name, channel.ChannelInfo.IsMultiKey, common.GetContextKeyString(c, constant.ContextKeyChannelKey), channel.GetAutoBan()), newAPIError) |
| 201 | |
| 202 | if !shouldRetry(c, newAPIError, common.RetryTimes-i) { |
| 203 | break |
| 204 | } |
| 205 | } |
| 206 | useChannel := c.GetStringSlice("use_channel") |
| 207 | if len(useChannel) > 1 { |
| 208 | retryLogStr := fmt.Sprintf("重试:%s", strings.Trim(strings.Join(strings.Fields(fmt.Sprint(useChannel)), "->"), "[]")) |
| 209 | common.LogInfo(c, retryLogStr) |
| 210 | } |
| 211 | |
| 212 | if newAPIError != nil { |
| 213 | newAPIError.SetMessage(common.MessageWithRequestId(newAPIError.Error(), requestId)) |
| 214 | c.JSON(newAPIError.StatusCode, gin.H{ |
| 215 | "type": "error", |
| 216 | "error": newAPIError.ToClaudeError(), |
| 217 | }) |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | func relayRequest(c *gin.Context, relayMode int, channel *model.Channel) *types.NewAPIError { |
| 222 | addUsedChannel(c, channel.Id) |
nothing calls this directly
no test coverage detected