Skip to content

Go: implement ListModels in ZhipuAI driver - #14886

Merged
JinHai-CN merged 2 commits into
infiniflow:mainfrom
pandadev66:feat/go-zhipu-listmodels
May 13, 2026
Merged

JinHai-CN merged 2 commits into
infiniflow:mainfrom
pandadev66:feat/go-zhipu-listmodels

Conversation

@pandadev66

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Fixes #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

  • New Feature (non-breaking change which adds functionality)

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label May 13, 2026
@coderabbitai

coderabbitai Bot commented May 13, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 842323b1-caeb-46c4-b7bd-b84c38f37012

📥 Commits

Reviewing files that changed from the base of the PR and between eb4313b and d441867.

📒 Files selected for processing (1)
  • internal/entity/models/zhipu-ai.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/entity/models/zhipu-ai.go

📝 Walkthrough

Walkthrough

Adds a models URL suffix to Zhipu-AI config and implements ZhipuAIModel.ListModels to GET the region-aware models endpoint, optionally send a Bearer API key, parse the DSModelList response, and return model identifiers (with @OwnedBy when present).

Changes

Zhipu-AI Model Listing Feature

Layer / File(s) Summary
Models endpoint configuration
conf/models/zhipu-ai.json
Added "models": "models" to the url_suffix mapping to enable resolving the models endpoint.
ListModels implementation
internal/entity/models/zhipu-ai.go
Implements ListModels to perform a region-aware GET to URLSuffix.Models, set Authorization: Bearer <apiKey> when present, validate HTTP 200, unmarshal into DSModelList, and return ID or ID@OwnedBy per model.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • infiniflow/ragflow#14702: Adds models URL suffix and implements ListModels for a provider using the same model-listing pattern.

Suggested labels

💞 feature

Suggested reviewers

  • Haruko386

Poem

🐰 I hopped through configs, sniffed the air,
A models suffix found with careful care.
I called the endpoint, listed each name,
IDs and owners brought into frame.
Hooray — the picker now plays the game!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: implementing ListModels in the ZhipuAI Go driver.
Description check ✅ Passed The description covers all required template sections with sufficient detail on the problem, changes, and type of change.
Linked Issues check ✅ Passed The PR fully addresses all coding requirements from issue #14884: region resolution, correct API endpoint construction, authentication handling, error surfacing, response parsing, and config file update.
Out of Scope Changes check ✅ Passed All changes are within scope and directly address the linked issue. The two modified files are exactly those specified in the requirements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pandadev66

Copy link
Copy Markdown
Contributor Author

Hi @Magicbook1108, gentle ping for review when you have a moment. This follows the same OpenAI-compatible /models shape that the merged DeepSeek, Gitee, NVIDIA, OpenAI, SiliconFlow, and OpenRouter drivers already use, scope is two files (one config, one driver), and it closes #14884. Thanks!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between d63d3bb and eb4313b.

📒 Files selected for processing (2)
  • conf/models/zhipu-ai.json
  • internal/entity/models/zhipu-ai.go

Comment thread internal/entity/models/zhipu-ai.go Resolved
@pandadev66

Copy link
Copy Markdown
Contributor Author

Thanks for the review @coderabbitai. Addressed in d441867: ListModels now falls back to the "default" region when apiConfig.Region is set to a value not present in z.BaseURL, and returns a descriptive error if neither has a configured URL. Matches the pattern in the SiliconFlow and DeepSeek Balance methods.

@coderabbitai

coderabbitai Bot commented May 13, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Read the current state of the ZhipuAI driver
cat internal/entity/models/zhipu-ai.go

Length of output: 19348


@pandadev66 Thanks for the update! I've verified the fix in the current file. The ListModels implementation now correctly:

  1. Falls back to "default" region — baseURL is seeded from z.BaseURL["default"] first, and the region-specific URL is only used when the key exists and is non-empty in z.BaseURL.
  2. Returns a descriptive error — if even the default URL is empty, it returns "zhipu-ai: no base URL configured for default region".
  3. Consistent pattern — this mirrors the guard used in the Rerank method (if !ok || baseURL == ""), keeping the driver internally consistent.

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!

@Haruko386 Haruko386 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Haruko386 Haruko386 added the ci Continue Integration label May 13, 2026
@JinHai-CN
JinHai-CN marked this pull request as draft May 13, 2026 08:05
@JinHai-CN
JinHai-CN marked this pull request as ready for review May 13, 2026 08:05
@codecov

codecov Bot commented May 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.16%. Comparing base (d63d3bb) to head (d441867).
⚠️ Report is 2 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN
JinHai-CN merged commit bf90c89 into infiniflow:main May 13, 2026
2 checks passed
Ricardo-M-L pushed a commit to Ricardo-M-L/ragflow that referenced this pull request Aug 17, 2026
### 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Implement ListModels in the ZhipuAI Go driver

3 participants