Fix/gemini-fetch-models - #1517
Conversation
WalkthroughThis change removes special-case parsing for Google-compatible model responses in the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant FetchUpstreamModels
participant UpstreamAPI
Client->>FetchUpstreamModels: Request model list
FetchUpstreamModels->>UpstreamAPI: GET /models (with Authorization header)
UpstreamAPI-->>FetchUpstreamModels: Standard OpenAI models response
FetchUpstreamModels-->>Client: Forward parsed models response
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
controller/channel.go (2)
187-187: Clarify the comment to reflect the actual change.The comment is contradictory - it mentions "key in url" but then says "we need to use AuthHeader". Since the code is now using authorization headers instead of URL parameters, the comment should be updated to reflect this change accurately.
- url = fmt.Sprintf("%s/v1beta/openai/models", baseURL) // Remember key in url since we need to use AuthHeader + url = fmt.Sprintf("%s/v1beta/openai/models", baseURL) // Use AuthHeader instead of key in URL
197-201: Simplify redundant conditional logic.Both the Gemini and non-Gemini branches now execute identical code. The conditional check is no longer necessary and can be simplified.
- key := strings.Split(channel.Key, "\n")[0] - if channel.Type == constant.ChannelTypeGemini { - body, err = GetResponseBody("GET", url, channel, GetAuthHeader(key)) // Use AuthHeader since Gemini now forces it - } else { - body, err = GetResponseBody("GET", url, channel, GetAuthHeader(key)) - } + key := strings.Split(channel.Key, "\n")[0] + body, err = GetResponseBody("GET", url, channel, GetAuthHeader(key))
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
controller/channel.go(2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: 9Ninety
PR: QuantumNous/new-api#1273
File: relay/channel/gemini/relay-gemini.go:97-116
Timestamp: 2025-06-21T03:37:41.726Z
Learning: In relay/channel/gemini/relay-gemini.go, the thinking budget calculation logic (including the MaxOutputTokens multiplication) was introduced in PR #1247. PR #1273 focused specifically on decoupling the thoughts summary feature from thinking budget settings and did not modify the existing thinking budget behavior.
Learnt from: antecanis8
PR: QuantumNous/new-api#1500
File: relay/channel/gemini/adaptor.go:0-0
Timestamp: 2025-08-04T14:36:34.528Z
Learning: In the Gemini API batchEmbedContents endpoint, each request item in the "requests" array should include its own "model" field, as shown in the official documentation at https://ai.google.dev/api/embeddings?hl=zh-cn#method:-models.batchembedcontents. The model field is not a top-level parameter.
Learnt from: neotf
PR: QuantumNous/new-api#1511
File: setting/ratio_setting/model_ratio.go:118-123
Timestamp: 2025-08-05T17:14:17.246Z
Learning: Claude models handle "-thinking" variants differently from Gemini models. For Claude models, only the base model (without "-thinking") gets an entry in defaultModelRatio map. The "-thinking" variants rely on the Claude relay handler stripping the suffix using strings.TrimSuffix(textRequest.Model, "-thinking") before looking up the ratio, so they automatically use the base model's ratio.
Learnt from: antecanis8
PR: QuantumNous/new-api#1500
File: relay/channel/gemini/adaptor.go:0-0
Timestamp: 2025-08-04T14:36:34.528Z
Learning: All currently serviced Gemini embedding models support the outputDimensionality parameter, not just specific models like text-embedding-004.
📚 Learning: claude models handle "-thinking" variants differently from gemini models. for claude models, only th...
Learnt from: neotf
PR: QuantumNous/new-api#1511
File: setting/ratio_setting/model_ratio.go:118-123
Timestamp: 2025-08-05T17:14:17.246Z
Learning: Claude models handle "-thinking" variants differently from Gemini models. For Claude models, only the base model (without "-thinking") gets an entry in defaultModelRatio map. The "-thinking" variants rely on the Claude relay handler stripping the suffix using strings.TrimSuffix(textRequest.Model, "-thinking") before looking up the ratio, so they automatically use the base model's ratio.
Applied to files:
controller/channel.go
🔇 Additional comments (1)
controller/channel.go (1)
208-214: LGTM! Excellent simplification of response parsing.The removal of special-case parsing for Google-compatible responses simplifies the code significantly. Since the Gemini endpoint now returns OpenAI-compatible responses directly, this change eliminates unnecessary complexity while maintaining functionality.
aaed890 to
ed95a9f
Compare
…dels Fix/gemini-fetch-models
PR 类型
PR 是否包含破坏性更新?
PR 描述
Close #1515
目前在URL中使用key无效,改为使用与文档一致的Authheader;
适配了多key渠道的获取模型列表。使用第一个key向上游鉴权。未实现错误回退机制。
修复效果
Summary by CodeRabbit
Refactor
Chores