Skip to content

feat(provider): 支持智谱 GLM Coding Plan - #9852

Open
RhoninSeiei wants to merge 1 commit into
AstrBotDevs:masterfrom
RhoninSeiei:feat/zhipu-coding-plan
Open

feat(provider): 支持智谱 GLM Coding Plan#9852
RhoninSeiei wants to merge 1 commit into
AstrBotDevs:masterfrom
RhoninSeiei:feat/zhipu-coding-plan

Conversation

@RhoninSeiei

@RhoninSeiei RhoninSeiei commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

现有智谱 Provider 使用通用 API。GLM Coding Plan 的套餐额度只通过专用 Coding API 提供,手工替换地址后还会遇到模型列表接口不可用、推理参数与模型版本不匹配等问题。

关联 #7109

Modifications / 改动点

  • 新增独立的 zhipu_coding_plan_chat_completion Provider,保留现有智谱通用 API Provider。
  • 默认使用国内 Coding API,同时允许配置全球 Coding API。
  • 使用固定模型目录,包含 GLM-5.3、GLM-5.2、GLM-5-Turbo、GLM-5V-Turbo、GLM-5.1 与 GLM-4.7 等模型,避免依赖套餐端点的模型列表接口。
  • 参考 OpenClaw 当前实现,按每次请求的实际模型处理推理强度;请求级设置优先于 Provider 配置,旧模型不会收到其协议范围外的 reasoning_effort
  • GLM-5.3 支持 lowhighmax,默认 max;GLM-5.2 保留 offhighmax 语义,并保留显式 thinking.enabled 设置。
  • 流式工具调用默认发送 tool_stream=true,并覆盖工具参数分片组装测试。
  • 未设置 OpenClaw 客户端标识,也未修改普通智谱 Provider 的鉴权方式。
  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

python -m pytest tests/test_zhipu_coding_plan_source.py tests/test_openai_source.py tests/test_fastapi_v1_dashboard.py -q
191 passed, 1 warning in 69.96s

ruff check astrbot/core/provider/sources/zhipu_coding_plan_source.py astrbot/core/provider/manager.py astrbot/core/config/default.py
All checks passed!

ruff format --check astrbot/core/provider/sources/zhipu_coding_plan_source.py tests/test_zhipu_coding_plan_source.py
2 files already formatted

另使用现有 Coding Plan 密钥执行了实际 Provider 最小请求:国内 Coding API 返回 HTTP 200,AstrBot 成功解析响应并取得 token usage;请求未配置 OpenClaw 标识。密钥和响应正文均未写入测试日志。


Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”
  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。
  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Add a separate Zhipu GLM Coding Plan provider with model-aware request handling and streaming tool support without changing the existing Zhipu integration.

New Features:

  • Add a dedicated Zhipu GLM Coding Plan provider with domestic and configurable global Coding API endpoints.
  • Expose a static Coding Plan model catalog and configure GLM-5.3 as the default model.
  • Support model-aware reasoning controls and streaming tool-call handling for Coding Plan requests.

Enhancements:

  • Preserve the existing general Zhipu provider and authentication behavior while applying request-level reasoning settings appropriately across supported model versions.

Tests:

  • Add comprehensive coverage for provider registration, endpoint and model defaults, reasoning policies, request overrides, streaming behavior, and tool-call argument assembly.

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. labels Aug 27, 2026
@RhoninSeiei RhoninSeiei mentioned this pull request Aug 27, 2026
2 tasks

@sourcery-ai sourcery-ai 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.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="astrbot/core/provider/sources/zhipu_coding_plan_source.py" line_range="81-82" />
<code_context>
+        provider_settings: dict,
+    ) -> None:
+        merged_provider_config = dict(provider_config)
+        merged_provider_config.setdefault("api_base", ZHIPU_CODING_PLAN_API_BASE)
+        merged_provider_config.setdefault("model", ZHIPU_CODING_PLAN_DEFAULT_MODEL)
+
+        configured_extra_body = merged_provider_config.get("custom_extra_body")
</code_context>
<issue_to_address>
**issue (bug_risk):** The Coding API defaults are applied with `setdefault`, so an explicitly present empty `api_base` or `model` is preserved. An empty `api_base` makes `AsyncOpenAI` target its ordinary OpenAI default endpoint rather than the Coding API, and an empty model produces an invalid Coding API request.

**Triggers:** When an existing or manually edited provider configuration contains `api_base: ""` or `model: ""`.

**Suggested fix:** Apply the Coding defaults when the values are missing or blank, for example with `if not merged_provider_config.get("api_base")` and the equivalent model check.

```suggestion
        if not merged_provider_config.get("api_base"):
            merged_provider_config["api_base"] = ZHIPU_CODING_PLAN_API_BASE
        if not merged_provider_config.get("model"):
            merged_provider_config["model"] = ZHIPU_CODING_PLAN_DEFAULT_MODEL
```
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: astrbot/core/provider/sources/zhipu_coding_plan_source.py:82


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +81 to +82
merged_provider_config.setdefault("api_base", ZHIPU_CODING_PLAN_API_BASE)
merged_provider_config.setdefault("model", ZHIPU_CODING_PLAN_DEFAULT_MODEL)

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.

issue (bug_risk): The Coding API defaults are applied with setdefault, so an explicitly present empty api_base or model is preserved. An empty api_base makes AsyncOpenAI target its ordinary OpenAI default endpoint rather than the Coding API, and an empty model produces an invalid Coding API request.

Triggers: When an existing or manually edited provider configuration contains api_base: "" or model: "".

Suggested fix: Apply the Coding defaults when the values are missing or blank, for example with if not merged_provider_config.get("api_base") and the equivalent model check.

Suggested change
merged_provider_config.setdefault("api_base", ZHIPU_CODING_PLAN_API_BASE)
merged_provider_config.setdefault("model", ZHIPU_CODING_PLAN_DEFAULT_MODEL)
if not merged_provider_config.get("api_base"):
merged_provider_config["api_base"] = ZHIPU_CODING_PLAN_API_BASE
if not merged_provider_config.get("model"):
merged_provider_config["model"] = ZHIPU_CODING_PLAN_DEFAULT_MODEL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant