Skip to content

feat(provider): add zhipu ai#78

Merged
bzp2010 merged 1 commit into
mainfrom
bzp/feat-zhipuai-provider
May 3, 2026
Merged

feat(provider): add zhipu ai#78
bzp2010 merged 1 commit into
mainfrom
bzp/feat-zhipuai-provider

Conversation

@bzp2010
Copy link
Copy Markdown
Collaborator

@bzp2010 bzp2010 commented May 3, 2026

Summary by CodeRabbit

  • New Features
    • Added support for ZhipuAI as a new AI provider, enabling users to integrate ZhipuAI's chat and embedding services.
    • Supports custom API base URL configuration for ZhipuAI deployments.
    • Added localization support for ZhipuAI in English and Chinese interfaces.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 3, 2026

📝 Walkthrough

Walkthrough

This PR adds support for the ZhipuAI provider across the backend and frontend. Changes extend the provider schema and configuration enum to recognize zhipuai, implement the ZhipuAI gateway provider with authentication and request/response transformations, register it in the provider registry, update proxy authentication handling, and add UI translations and type definitions.

Changes

ZhipuAI Provider Integration

Layer / File(s) Summary
Schema & Configuration
src/config/entities/providers-schema.json, src/config/entities/providers.rs
Provider schema enum extended to include zhipuai; ProviderConfig enum gains ZhipuAi variant tagged "zhipuai"; schema conditional routes zhipuai to openai_compatible config definitions.
Provider Implementation
src/gateway/providers/zhipuai.rs
Implements ZhipuAI provider with IDENTIFIER, config struct (api_key, optional api_base), ProviderMeta for base URL and auth headers, ChatTransform with temperature validation (0, 1], and EmbedTransform with dimension validation and removal of OpenAI-only fields.
Registry & Module Wiring
src/gateway/providers/mod.rs
Declares zhipuai module, re-exports ZhipuAi, adds ZHIPUAI identifier constant, and registers ZhipuAi in default_provider_registry().
Proxy Authentication
src/proxy/provider.rs
provider_auth_and_base_url handles ProviderConfig::ZhipuAi by extracting api_key as ProviderAuth::ApiKey and optional api_base as URL override.
UI & Localization
ui/src/i18n/locales/en.json, ui/src/i18n/locales/zh-CN.json, ui/src/lib/api/types.ts
Adds zhipuai to provider type enum, translations ("ZhipuAI" / "智谱"), and extends Provider union with { type: 'zhipuai'; config: ApiBaseProviderConfig } variant.
Tests & Validation
src/config/entities/providers.rs, src/gateway/providers/zhipuai.rs, src/proxy/provider.rs
Schema validation, provider metadata, auth header, temperature rejection, embedding dimension validation, and proxy auth tests added for zhipuai.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • feat(provider): add fireworks ai #76 — Adds another OpenAI-compatible provider using the same code-level pattern (schema enum, ProviderConfig variant, provider module/registry, implementation, proxy auth, UI types).
  • feat(provider): add mistral #72 — Adds a different new provider (Mistral) by modifying the same code surfaces (schema, ProviderConfig enum, providers registry/module, provider impl, proxy handling, UI i18n/types).
  • feat(provider): add cohere #75 — Adds a new provider type through parallel, identical structural changes to schema, ProviderConfig, gateway provider registration, auth handling, and UI definitions.

Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 1 warning)

Check name Status Explanation Resolution
Security Check ❌ Error ZhipuAiProviderConfig exposes plaintext api_key in HTTP responses without redaction mechanism, unlike Bedrock implementation. Implement custom Debug trait redacting api_key field and add custom Serialize implementation to prevent credential exposure in API responses and logs.
E2e Test Quality Review ⚠️ Warning PR introduces zhipuai provider with only unit tests; lacks E2E tests covering complete request-response flow through gateway integration. Add E2E tests verifying full provider lifecycle: request routing, authentication, API integration, error handling, and response transformations.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(provider): add zhipu ai' clearly summarizes the main change: adding support for the ZhipuAI provider across the entire codebase.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bzp/feat-zhipuai-provider

Review rate limit: 4/5 reviews remaining, refill in 12 minutes.

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/proxy/provider.rs (1)

357-371: ⚡ Quick win

Add an explicit api_base: None assertion for ZhipuAI in tests.

Current test only checks the override-present path. Adding the None path guards regression for optional base URL handling on this new variant.

Proposed test addition
@@
     fn provider_auth_and_base_url_returns_zhipuai_api_key_and_optional_base_url() {
@@
         assert_eq!(
             base_url_override.as_ref().map(Url::as_str),
             Some("https://open.bigmodel.cn/api/paas/v4")
         );
     }
+
+    #[test]
+    fn provider_auth_and_base_url_returns_zhipuai_api_key_without_base_url_override() {
+        let config = ProviderConfig::ZhipuAi(ZhipuAiProviderConfig {
+            api_key: "zhipu-key".into(),
+            api_base: None,
+        });
+
+        let (auth, base_url_override) = provider_auth_and_base_url(&config).unwrap();
+
+        assert_eq!(auth.api_key_for("zhipuai").unwrap(), "zhipu-key");
+        assert_eq!(base_url_override, None);
+    }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/proxy/provider.rs` around lines 357 - 371, Add a test verifying the
ZhipuAi variant when api_base is None: create a ProviderConfig::ZhipuAi with
ZhipuAiProviderConfig { api_key: "zhipu-key".into(), api_base: None }, call
provider_auth_and_base_url(&config).unwrap(), assert
auth.api_key_for("zhipuai").unwrap() == "zhipu-key" and assert
base_url_override.is_none(); this complements the existing test that covers the
Some(api_base) path and prevents regressions in provider_auth_and_base_url
handling of optional api_base.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/proxy/provider.rs`:
- Around line 357-371: Add a test verifying the ZhipuAi variant when api_base is
None: create a ProviderConfig::ZhipuAi with ZhipuAiProviderConfig { api_key:
"zhipu-key".into(), api_base: None }, call
provider_auth_and_base_url(&config).unwrap(), assert
auth.api_key_for("zhipuai").unwrap() == "zhipu-key" and assert
base_url_override.is_none(); this complements the existing test that covers the
Some(api_base) path and prevents regressions in provider_auth_and_base_url
handling of optional api_base.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2a4f55b2-a67d-4aaf-a9e9-2acc95f45ef4

📥 Commits

Reviewing files that changed from the base of the PR and between 72d76ff and 05e94f2.

📒 Files selected for processing (8)
  • src/config/entities/providers-schema.json
  • src/config/entities/providers.rs
  • src/gateway/providers/mod.rs
  • src/gateway/providers/zhipuai.rs
  • src/proxy/provider.rs
  • ui/src/i18n/locales/en.json
  • ui/src/i18n/locales/zh-CN.json
  • ui/src/lib/api/types.ts

@bzp2010 bzp2010 merged commit da2e1e0 into main May 3, 2026
3 checks passed
@bzp2010 bzp2010 deleted the bzp/feat-zhipuai-provider branch May 3, 2026 11:54
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.

1 participant