Unverified Commit 0026e871 authored by 刀刀's avatar 刀刀 Committed by GitHub
Browse files

CC Stream 响应流中出现 error 时, 增加返回重试 (#86)

* 响应流中出现 error, 返回重试

* 响应流中出现 error, 返回重试
parent 942c3e15
......@@ -216,7 +216,7 @@ func (h *GatewayHandler) Messages(c *gin.Context) {
}
}
const maxAccountSwitches = 3
const maxAccountSwitches = 10
switchCount := 0
failedAccountIDs := make(map[int64]struct{})
lastFailoverStatus := 0
......
......@@ -695,6 +695,11 @@ func (s *GatewayService) Forward(ctx context.Context, c *gin.Context, account *A
if req.Stream {
streamResult, err := s.handleStreamingResponse(ctx, resp, c, account, startTime, originalModel, req.Model)
if err != nil {
if err.Error() == "have error in stream" {
return nil, &UpstreamFailoverError{
StatusCode: 403,
}
}
return nil, err
}
usage = streamResult.usage
......@@ -969,6 +974,9 @@ func (s *GatewayService) handleStreamingResponse(ctx context.Context, resp *http
for scanner.Scan() {
line := scanner.Text()
if line == "event: error" {
return nil, errors.New("have error in stream")
}
// Extract data from SSE line (supports both "data: " and "data:" formats)
if sseDataRe.MatchString(line) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment