Repository navigation
Go: implement ListModels in ZhipuAI driver - #14886
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a ChangesZhipu-AI Model Listing Feature
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
|
Hi @Magicbook1108, gentle ping for review when you have a moment. This follows the same OpenAI-compatible |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/entity/models/zhipu-ai.go`:
- Around line 460-465: The code uses z.BaseURL[region] directly when building
the models URL (see usage in the method that constructs url :=
fmt.Sprintf("%s/%s", z.BaseURL[region], z.URLSuffix.Models)), which can panic or
produce invalid URLs for unknown apiConfig.Region; update the method to first
validate that region exists as a key in z.BaseURL (and that the value is
non-empty), then either choose a clear default region (e.g., z.DefaultRegion) or
return a descriptive error indicating an unknown region before formatting the
URL; reference apiConfig.Region, z.BaseURL, and z.URLSuffix.Models to locate
where to add this guard and error/fallback logic.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 05035650-6742-4612-bb86-9335c7bc679e
📒 Files selected for processing (2)
conf/models/zhipu-ai.jsoninternal/entity/models/zhipu-ai.go
|
Thanks for the review @coderabbitai. Addressed in d441867: |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 19348
The fix looks good! 🎉 If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14886 +/- ##
=======================================
Coverage 94.16% 94.16%
=======================================
Files 10 10
Lines 703 703
Branches 112 112
=======================================
Hits 662 662
Misses 25 25
Partials 16 16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
### What problem does this PR solve? Fixes infiniflow#14884 The ZhipuAI Go driver in `internal/entity/models/zhipu-ai.go` had a stub `ListModels` method that always returned `"zhipu-ai, no such method"`. The DeepSeek, Gitee, NVIDIA, OpenAI, SiliconFlow, and OpenRouter drivers in the same package already implement `ListModels` against the OpenAI-compatible `/models` endpoint, and the model picker UI relies on it. This PR brings ZhipuAI in line with that pattern. ### Changes - `internal/entity/models/zhipu-ai.go`: implement `ZhipuAIModel.ListModels`. - Resolve region with default fallback. - GET `${BaseURL[region]}/${URLSuffix.Models}` (resolves to `https://open.bigmodel.cn/api/paas/v4/models` with the default region). - Send `Authorization: Bearer <api_key>` when an API key is configured. Omit the header when the key is empty, so an unauthenticated caller gets a clear `401` from upstream. - Surface non-200 responses with the upstream status line and body, matching the other Go drivers. - Parse the response via the package-level `DSModelList` / `DSModel` types already used by DeepSeek, Gitee, and SiliconFlow. - When the response includes `owned_by`, render the entry as `id@owned_by`, matching the convention of Gitee and SiliconFlow. - `conf/models/zhipu-ai.json`: add `"models": "models"` to `url_suffix`. ### Type of change - [x] New Feature (non-breaking change which adds functionality)
What problem does this PR solve?
Fixes #14884
The ZhipuAI Go driver in
internal/entity/models/zhipu-ai.gohad a stubListModelsmethod that always returned"zhipu-ai, no such method". The DeepSeek, Gitee, NVIDIA, OpenAI, SiliconFlow, and OpenRouter drivers in the same package already implementListModelsagainst the OpenAI-compatible/modelsendpoint, and the model picker UI relies on it. This PR brings ZhipuAI in line with that pattern.Changes
internal/entity/models/zhipu-ai.go: implementZhipuAIModel.ListModels.${BaseURL[region]}/${URLSuffix.Models}(resolves tohttps://open.bigmodel.cn/api/paas/v4/modelswith the default region).Authorization: Bearer <api_key>when an API key is configured. Omit the header when the key is empty, so an unauthenticated caller gets a clear401from upstream.DSModelList/DSModeltypes already used by DeepSeek, Gitee, and SiliconFlow.owned_by, render the entry asid@owned_by, matching the convention of Gitee and SiliconFlow.conf/models/zhipu-ai.json: add"models": "models"tourl_suffix.Type of change