From fd0a3af5bd2efead3ff6392246d6d132598186eb Mon Sep 17 00:00:00 2001 From: tbphp Date: Sat, 26 Jul 2025 10:05:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81gemini=E5=AE=98?= =?UTF-8?q?=E6=96=B9openai=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/channel/gemini_channel.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/internal/channel/gemini_channel.go b/internal/channel/gemini_channel.go index 5a1676f..b44c0f2 100644 --- a/internal/channel/gemini_channel.go +++ b/internal/channel/gemini_channel.go @@ -36,9 +36,13 @@ func newGeminiChannel(f *Factory, group *models.Group) (ChannelProxy, error) { // ModifyRequest adds the API key as a query parameter for Gemini requests. func (ch *GeminiChannel) ModifyRequest(req *http.Request, apiKey *models.APIKey, group *models.Group) { - q := req.URL.Query() - q.Set("key", apiKey.KeyValue) - req.URL.RawQuery = q.Encode() + if strings.Contains(req.URL.Path, "v1beta/openai") { + req.Header.Set("Authorization", "Bearer "+apiKey.KeyValue) + } else { + q := req.URL.Query() + q.Set("key", apiKey.KeyValue) + req.URL.RawQuery = q.Encode() + } } // IsStreamRequest checks if the request is for a streaming response. @@ -56,6 +60,14 @@ func (ch *GeminiChannel) IsStreamRequest(c *gin.Context, bodyBytes []byte) bool return true } + type streamPayload struct { + Stream bool `json:"stream"` + } + var p streamPayload + if err := json.Unmarshal(bodyBytes, &p); err == nil { + return p.Stream + } + return false }