Skip to content

Commit 4e20a74

Browse files
authored
Merge pull request #1148 from RedwindA/x-goog-api-key
feat: support X-goog-api-key;remove [Done] in stream mode
2 parents a494206 + c7e8123 commit 4e20a74

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

middleware/auth.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ func TokenAuth() func(c *gin.Context) {
189189
if skKey != "" {
190190
c.Request.Header.Set("Authorization", "Bearer "+skKey)
191191
}
192+
// 从x-goog-api-key header中获取key
193+
xGoogKey := c.Request.Header.Get("x-goog-api-key")
194+
if xGoogKey != "" {
195+
c.Request.Header.Set("Authorization", "Bearer "+xGoogKey)
196+
}
192197
}
193198
key := c.Request.Header.Get("Authorization")
194199
parts := make([]string, 0)

relay/channel/gemini/relay-gemini-native.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ func GeminiTextGenerationStreamHandler(c *gin.Context, resp *http.Response, info
121121
usage.PromptTokensDetails.TextTokens = usage.PromptTokens
122122
usage.CompletionTokens = usage.TotalTokens - usage.PromptTokens
123123

124-
// 结束流式响应
125-
helper.Done(c)
124+
// 移除流式响应结尾的[Done],因为Gemini API没有发送Done的行为
125+
//helper.Done(c)
126126

127127
return usage, nil
128128
}

0 commit comments

Comments
 (0)