mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-18 04:10:51 +08:00
feat(claude-executor): add ZSTD decoding support for Claude executor responses
- Integrated ZSTD decompression via `github.com/klauspost/compress` for responses with "zstd" content-encoding. - Added helper `hasZSTDEcoding` to detect ZSTD-encoded responses. - Updated response handling logic to initialize and use a ZSTD decoder when necessary. refactor(api-handlers): split streaming and non-streaming response handling - Introduced `handleNonStreamingResponse` for processing non-streaming requests in `ClaudeCodeAPIHandler`. - Improved code clarity by separating streaming and non-streaming logic. fix(service): remove redundant token refresh interval assignment logic in `cliproxy` service.
This commit is contained in:
@@ -76,10 +76,10 @@ func (h *ClaudeCodeAPIHandler) ClaudeMessages(c *gin.Context) {
|
||||
// Check if the client requested a streaming response.
|
||||
streamResult := gjson.GetBytes(rawJSON, "stream")
|
||||
if !streamResult.Exists() || streamResult.Type == gjson.False {
|
||||
return
|
||||
h.handleNonStreamingResponse(c, rawJSON)
|
||||
} else {
|
||||
h.handleStreamingResponse(c, rawJSON)
|
||||
}
|
||||
|
||||
h.handleStreamingResponse(c, rawJSON)
|
||||
}
|
||||
|
||||
// ClaudeModels handles the Claude models listing endpoint.
|
||||
@@ -93,6 +93,32 @@ func (h *ClaudeCodeAPIHandler) ClaudeModels(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// handleNonStreamingResponse handles non-streaming content generation requests for Claude models.
|
||||
// This function processes the request synchronously and returns the complete generated
|
||||
// response in a single API call. It supports various generation parameters and
|
||||
// response formats.
|
||||
//
|
||||
// Parameters:
|
||||
// - c: The Gin context for the request
|
||||
// - modelName: The name of the Gemini model to use for content generation
|
||||
// - rawJSON: The raw JSON request body containing generation parameters and content
|
||||
func (h *ClaudeCodeAPIHandler) handleNonStreamingResponse(c *gin.Context, rawJSON []byte) {
|
||||
c.Header("Content-Type", "application/json")
|
||||
alt := h.GetAlt(c)
|
||||
cliCtx, cliCancel := h.GetContextWithCancel(h, c, context.Background())
|
||||
|
||||
modelName := gjson.GetBytes(rawJSON, "model").String()
|
||||
|
||||
resp, errMsg := h.ExecuteWithAuthManager(cliCtx, h.HandlerType(), modelName, rawJSON, alt)
|
||||
if errMsg != nil {
|
||||
h.WriteErrorResponse(c, errMsg)
|
||||
cliCancel(errMsg.Error)
|
||||
return
|
||||
}
|
||||
_, _ = c.Writer.Write(resp)
|
||||
cliCancel()
|
||||
}
|
||||
|
||||
// handleStreamingResponse streams Claude-compatible responses backed by Gemini.
|
||||
// It sets up SSE, selects a backend client with rotation/quota logic,
|
||||
// forwards chunks, and translates them to Claude CLI format.
|
||||
|
||||
Reference in New Issue
Block a user