diff --git a/relay/channel/api_request.go b/relay/channel/api_request.go index ff7c63fa..3ccd2d78 100644 --- a/relay/channel/api_request.go +++ b/relay/channel/api_request.go @@ -223,7 +223,7 @@ func doRequest(c *gin.Context, req *http.Request, info *common.RelayInfo) (*http helper.SetEventStreamHeaders(c) // 处理流式请求的 ping 保活 generalSettings := operation_setting.GetGeneralSetting() - if generalSettings.PingIntervalEnabled { + if generalSettings.PingIntervalEnabled && !info.DisablePing { pingInterval := time.Duration(generalSettings.PingIntervalSeconds) * time.Second stopPinger = startPingKeepAlive(c, pingInterval) // 使用defer确保在任何情况下都能停止ping goroutine diff --git a/relay/channel/gemini/adaptor.go b/relay/channel/gemini/adaptor.go index da291aa9..2b7b7e39 100644 --- a/relay/channel/gemini/adaptor.go +++ b/relay/channel/gemini/adaptor.go @@ -173,6 +173,7 @@ func (a *Adaptor) DoRequest(c *gin.Context, info *relaycommon.RelayInfo, request func (a *Adaptor) DoResponse(c *gin.Context, resp *http.Response, info *relaycommon.RelayInfo) (usage any, err *types.NewAPIError) { if info.RelayMode == constant.RelayModeGemini { if info.IsStream { + info.DisablePing = true return GeminiTextGenerationStreamHandler(c, info, resp) } else { return GeminiTextGenerationHandler(c, info, resp) diff --git a/relay/common/relay_info.go b/relay/common/relay_info.go index 45fde019..27827d97 100644 --- a/relay/common/relay_info.go +++ b/relay/common/relay_info.go @@ -88,6 +88,7 @@ type RelayInfo struct { BaseUrl string SupportStreamOptions bool ShouldIncludeUsage bool + DisablePing bool // 是否禁止向下游发送自定义 Ping IsModelMapped bool ClientWs *websocket.Conn TargetWs *websocket.Conn diff --git a/relay/helper/stream_scanner.go b/relay/helper/stream_scanner.go index c72aea6a..df8c5072 100644 --- a/relay/helper/stream_scanner.go +++ b/relay/helper/stream_scanner.go @@ -54,7 +54,7 @@ func StreamScannerHandler(c *gin.Context, resp *http.Response, info *relaycommon ) generalSettings := operation_setting.GetGeneralSetting() - pingEnabled := generalSettings.PingIntervalEnabled + pingEnabled := generalSettings.PingIntervalEnabled && !info.DisablePing pingInterval := time.Duration(generalSettings.PingIntervalSeconds) * time.Second if pingInterval <= 0 { pingInterval = DefaultPingInterval