MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / RelayClaude

Function RelayClaude

controller/relay.go:178–219  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

176}
177
178func 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
221func relayRequest(c *gin.Context, relayMode int, channel *model.Channel) *types.NewAPIError {
222 addUsedChannel(c, channel.Id)

Callers

nothing calls this directly

Calls 13

ErrorMethod · 0.95
SetMessageMethod · 0.95
ToClaudeErrorMethod · 0.95
LogErrorFunction · 0.92
NewChannelErrorFunction · 0.92
GetContextKeyStringFunction · 0.92
LogInfoFunction · 0.92
MessageWithRequestIdFunction · 0.92
getChannelFunction · 0.85
claudeRequestFunction · 0.85
processChannelErrorFunction · 0.85
shouldRetryFunction · 0.85

Tested by

no test coverage detected