Skip to content

feat: 获取模型列表按钮白名单 - #1885

Merged
Calcium-Ion merged 2 commits into
QuantumNous:mainfrom
RedwindA:fix/hide-unavailable-fetch-model-button
Sep 27, 2025
Merged

Calcium-Ion merged 2 commits into
QuantumNous:mainfrom
RedwindA:fix/hide-unavailable-fetch-model-button

Conversation

@RedwindA

@RedwindA RedwindA commented Sep 26, 2025 •

Copy link
Copy Markdown
Contributor

PR 类型

  • Bug 修复
  • 新功能
  • 文档更新
  • 其他

PR 是否包含破坏性更新?

  • 是
  • 否

仅为适当的渠道渲染获取模型列表按钮,新的渠道类型如果需要获取模型列表的功能,需要手动在web/src/components/table/channels/modals/EditChannelModal.jsx中加入白名单

PR 描述

  • 仅为白名单渠道渲染获取模型列表按钮
  • 适配了智谱的模型列表获取

智谱
image

火山
image

@coderabbitai

coderabbitai Bot commented Sep 26, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds support for fetching upstream models for ChannelTypeZhipu_v4 in the backend. Updates the frontend modal to show the “获取模型列表” button only for specific channel types via a new MODEL_FETCHABLE_TYPES set. No exported signatures changed; existing fetch logic remains.

Changes

Cohort / File(s) Summary
Backend: Upstream model fetch
controller/channel.go
Adds a case for ChannelTypeZhipu_v4 in FetchUpstreamModels to use baseURL/api/paas/v4/models. Other cases unchanged.
Frontend: Conditional model list button
web/src/components/table/channels/modals/EditChannelModal.jsx
Introduces MODEL_FETCHABLE_TYPES (Set) and conditionally renders the “获取模型列表” button when inputs.type is in the set. Fetch logic unchanged; minor comment added.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant M as EditChannelModal (UI)
  participant S as Server API
  participant Z as Zhipu v4 Upstream

  rect rgb(240,248,255)
    note over M: Render form
    M->>M: Check inputs.type ∈ MODEL_FETCHABLE_TYPES
    alt Supported type
      M->>U: Show “获取模型列表” button
      U->>M: Click fetch
      M->>S: GET /channels/:id/models
      alt ChannelTypeZhipu_v4
        S->>Z: GET {baseURL}/api/paas/v4/models
        Z-->>S: 200 Model list
      else Other supported types
        S->>S: Route to respective upstream
      end
      S-->>M: Model list
      M-->>U: Display models
    else Unsupported type
      M->>U: Button hidden
    end
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I thump my paws at version four,
New paths to models—Zhipu’s door.
A button peeks for types that fit,
Otherwise I hide a bit.
Backend whispers, “v4, this way,”
Carrots cached, we fetch today. 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly describes the primary feature addition—whitelisting the “获取模型列表” button—using a clear and concise phrasing that maps directly to the main change in the pull request.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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.

@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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d2defa1 and c25f487.

📒 Files selected for processing (2)
  • controller/channel.go (1 hunks)
  • web/src/components/table/channels/modals/EditChannelModal.jsx (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-08-27T02:15:25.448Z
Learnt from: AAEE86
PR: QuantumNous/new-api#1658
File: web/src/components/table/channels/modals/EditChannelModal.jsx:555-569
Timestamp: 2025-08-27T02:15:25.448Z
Learning: In EditChannelModal.jsx, the applyModelMapping function transforms the models list by replacing original model names (mapping values) with display names (mapping keys). The database stores this transformed list containing mapped keys. On channel load, data.models contains these mapped display names, making the initialization filter if (data.models.includes(key)) correct.

Applied to files:

  • web/src/components/table/channels/modals/EditChannelModal.jsx
📚 Learning: 2025-08-27T02:15:25.448Z
Learnt from: AAEE86
PR: QuantumNous/new-api#1658
File: web/src/components/table/channels/modals/EditChannelModal.jsx:555-569
Timestamp: 2025-08-27T02:15:25.448Z
Learning: In EditChannelModal.jsx, the database stores mapped keys (display names) in the models field after applying model mapping transformations. When loading a channel, data.models contains the mapped keys, not the original model names. The filtering logic if (data.models.includes(key)) in the initialization is correct.

Applied to files:

  • web/src/components/table/channels/modals/EditChannelModal.jsx
🧬 Code graph analysis (1)
controller/channel.go (1)
constant/channel.go (1)
  • ChannelTypeZhipu_v4 (30-30)
🔇 Additional comments (2)
web/src/components/table/channels/modals/EditChannelModal.jsx (2)

88-106: Keeping fetch support explicit looks good

Thanks for centralizing the fetchable channel types in a single Set; having the whitelist up top makes the support surface easy to audit and keeps the UI aligned with backend capabilities.


1895-1903: Conditional render matches the new whitelist

Scoping the button render with MODEL_FETCHABLE_TYPES.has(inputs.type) cleanly prevents unsupported channels from triggering the upstream fetch flow. This keeps the UX consistent with the backend restriction.

Comment thread controller/channel.go Resolved
@Calcium-Ion
Calcium-Ion merged commit bf99ead into QuantumNous:main Sep 27, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Jan 9, 2026
2 of 6 tasks
x22x22 pushed a commit to x22x22/new-api that referenced this pull request Apr 24, 2026
…e-fetch-model-button

feat: `获取模型列表`按钮白名单
@RedwindA
RedwindA deleted the fix/hide-unavailable-fetch-model-button branch July 23, 2026 07:04
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
…e-fetch-model-button

feat: `获取模型列表`按钮白名单
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
…e-fetch-model-button

feat: `获取模型列表`按钮白名单
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants