Skip to content

feat(zai): add Z.AI GLM model integration - #441

Open
petems wants to merge 13 commits into
BeehiveInnovations:mainfrom
petems:feat/add-zai-api-model-integration
Open

feat(zai): add Z.AI GLM model integration#441
petems wants to merge 13 commits into
BeehiveInnovations:mainfrom
petems:feat/add-zai-api-model-integration

Conversation

@petems

@petems petems commented May 5, 2026

Copy link
Copy Markdown

Description

Adds first-class support for the Z.AI provider so users can use the glm-4.6 model (200K context, 128K output, text-only, intelligence_score 12) directly through PAL.

The provider is built on the project's modern RegistryBackedProviderMixin pattern with a JSON-driven model registry, so new GLM models can be registered without code changes. ZAI_API_KEY is wired through every surface that already supports the other API keys (server bootstrap, listmodels, version, base tool, model restrictions, Docker compose, deploy/healthcheck scripts, integration test runners).

Refs:

Changes Made

  • Add ZAIModelProvider hitting the standard /api/paas/v4 endpoint (providers/zai.py, providers/registries/zai.py)
  • Define glm-4.6 in conf/zai_models.json with field_descriptions and verification_sources
  • Register the provider through providers/__init__.py, providers/registry.py, providers/shared/provider_type.py, server.py, tools/listmodels.py, tools/version.py, tools/shared/base_tool.py, utils/model_restrictions.py, pyproject.toml
  • Pass ZAI_API_KEY through docker-compose.yml, docker/scripts/deploy.{sh,ps1}, docker/scripts/healthcheck.py, run_integration_tests.{sh,ps1}
  • Add tests/test_zai_provider.py with full provider unit coverage matching the XAI suite (init, capabilities, alias resolution, friendly name, MODEL_CAPABILITIES, restrictions, generate_content) plus integration smoke tests
  • Extend shared fixtures and Docker tests so the new provider has parity with existing ones (tests/conftest.py, tests/test_custom_provider.py, tests/test_listmodels.py, tests/test_server.py, tests/test_docker_*.py)
  • Document the provider in .env.example, README.md, docs/getting-started.md, docs/advanced-usage.md, docs/custom_models.md, docs/configuration.md, docker/README.md, docs/docker-deployment.md
  • No breaking changes
  • No new dependencies (provider reuses the OpenAI-compatible client already in the project)

Testing

Run all linting and tests (required):

# Activate virtual environment first
source venv/bin/activate

# Run comprehensive code quality checks (recommended)
./code_quality_checks.sh

# If you made tool changes, also run simulator tests
python communication_simulator_test.py
  • All linting passes (ruff, black, isort)
  • All unit tests pass
  • For new features: Unit tests added in `tests/test_zai_provider.py`
  • For tool changes: Simulator tests added in `simulator_tests/` — N/A, this is a provider change, no new tools
  • For bug fixes: N/A — this is a feature
  • Simulator tests pass (existing tests unaffected)
  • Manual testing completed against the live Z.AI API with a valid `ZAI_API_KEY`

Related Issues

N/A — net-new provider integration.

Checklist

  • PR title follows the format guidelines above (`feat(zai): ...` → MINOR bump)
  • Activated venv and ran code quality checks: `source venv/bin/activate && ./code_quality_checks.sh`
  • Self-review completed
  • Tests added for ALL changes (provider unit + integration tests, Docker parity tests, fixture/listmodels/server registration tests)
  • Documentation updated as needed (env example, README, getting started, advanced usage, custom models, configuration, Docker docs)
  • All unit tests passing
  • Relevant simulator tests passing — provider-only change, no tool surface area touched
  • Ready for review

Additional Notes

  • The provider follows the same pattern as the recently-added providers (registry-backed mixin + JSON model definitions), so reviewers familiar with those changes should find this straightforward.
  • Docker builds will trigger automatically — this PR modifies `*.py`, `pyproject.toml`, and `docker-compose.yml`.
  • Opened as a draft so maintainers can flag any naming/registration conventions before final review.

petems and others added 3 commits May 5, 2026 01:16
Add a Z.AI GLM provider built on RegistryBackedProviderMixin and a
JSON-driven model registry, following the project's modern provider
pattern, and wire ZAI_API_KEY through the rest of the stack.

* Add ZAIModelProvider hitting the standard /api/paas/v4 endpoint
* Define GLM-4.6 in conf/zai_models.json (200K ctx, 128K output,
  text-only, intelligence_score 12) with field_descriptions and
  verification_sources
* Wire the provider through providers/__init__, registry, server,
  listmodels, version, base_tool, model_restrictions, pyproject.toml
* Pass ZAI_API_KEY through docker-compose, docker deploy/healthcheck
  scripts, and run_integration_tests entrypoints

Refs:
- https://docs.z.ai/guides/llm/glm-4.6
- https://docs.z.ai/api-reference/llm/chat-completion

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Add unit + integration smoke tests for the Z.AI provider, extend shared
test fixtures and listmodels/server/custom-provider tests to cover the
new provider, and extend the Docker test suite so ZAI_API_KEY reaches
parity with the other API keys.

* tests/test_zai_provider.py: provider unit tests (init, capabilities,
  alias resolution, friendly name, MODEL_CAPABILITIES, restrictions,
  generate_content) matching XAI test coverage; integration smoke tests
  for auth failure and basic completion
* tests/conftest.py, tests/test_custom_provider.py,
  tests/test_listmodels.py, tests/test_server.py: register and assert
  the Z.AI provider in shared fixtures and surfaces
* tests/test_docker_*.py: assert ZAI_API_KEY parity across Docker
  config, healthcheck, implementation, MCP validation, and security

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Document the new Z.AI provider across user-facing docs and config
examples, with the GLM-4.6 200K context window noted where relevant.

* .env.example: add ZAI_API_KEY entry and note GLM-4.6's 200K context
* README.md, docs/getting-started.md, docs/advanced-usage.md,
  docs/custom_models.md: add Z.AI to provider lists and user guides
* docs/configuration.md: add Z.AI to API keys section, model table,
  config files list, allowed-models examples, and the manifest
  override path
* docker/README.md, docs/docker-deployment.md: document ZAI_API_KEY
  for Docker deployments

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces support for the Z.AI (GLM) model provider. It includes the implementation of the ZAIModelProvider and ZAIModelRegistry, updates to the environment configuration, Docker setup, and comprehensive documentation. Additionally, it adds unit and integration tests to ensure the new provider functions correctly and integrates seamlessly with existing tools like listmodels and version. I have no feedback to provide.

@petems
petems marked this pull request as ready for review May 5, 2026 04:49
The CI test failure on test_alias_allowlist_resolution happened because
``model_restrictions.is_allowed`` only resolves an allowed alias to its
canonical target by looking the provider up via ``ModelProviderRegistry``.
The test called ``reset_for_testing()`` and then never re-registered the
ZAI provider, so the lookup returned None and ``glm-4.6`` validation fell
through to ``return False``.

* tests/test_zai_provider.py: re-register ZAI after reset_for_testing so
  is_allowed can resolve "glm" -> "glm-4.6"
* tests/conftest.py: add ZAI_API_KEY to the dummy-key list so
  ``ModelProviderRegistry.get_provider(ZAI)`` returns an instance during
  tests (matches existing XAI_API_KEY behaviour)
* requirements-dev.txt: pin ``black<26.0.0`` — black 26.x changed
  triple-quoted-string formatting for several upstream files that this PR
  doesn't touch (``simulator_tests/test_*``, ``test_directory_expansion_tracking``,
  ``test_prompt_regression``); pinning restores stable formatting for all
  contributors without dragging unrelated reformatting into this PR

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 23d9257a22

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread conf/zai_models.json Outdated
petems added 2 commits May 15, 2026 23:39
* add explicit JSON-backed range constraints

* set GLM temperature max to Z.AI API limit

* cover outbound temperature clamping
* clear Z.AI env in restricted-provider listing test

* avoid CI leaking GLM aliases into expected allowlist

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bf3debf7ca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/test_zai_provider.py Outdated
* treat test placeholder Z.AI keys as absent

* cover placeholder detection and dummy-key skip behavior

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f7a873005b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread providers/zai.py
* map PAL thinking levels to Z.AI thinking payload

* pass extra_body through OpenAI-compatible requests

* cover thinking payload forwarding

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c4c8c3d572

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread server.py Outdated
* centralize Z.AI placeholder credential detection

* reject both underscore and hyphenated docs placeholders

* cover provider-registration placeholder checks

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 559db217eb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/test_zai_provider.py
* include documented Z.AI placeholder spellings in smoke-test guard

* verify both placeholders skip integration completion

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 03a3836846

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .env.example
* add Z.AI to run-server env replacement checks

* cover first-run .env population from exported ZAI_API_KEY

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 22c3fc7e97

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .env.example
* include Z.AI in Windows env templates and API-key checks

* propagate ZAI_API_KEY into generated client env maps

* cover PowerShell Z.AI setup wiring

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 496329e77a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread run-server.ps1
* include ZAI_ALLOWED_MODELS in PowerShell Qwen env fallback

* cover Z.AI allowlist propagation wiring
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