llm-api-adapter-zai 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- llm_api_adapter_zai-0.1.0/LICENSE +21 -0
- llm_api_adapter_zai-0.1.0/MANIFEST.in +10 -0
- llm_api_adapter_zai-0.1.0/PKG-INFO +123 -0
- llm_api_adapter_zai-0.1.0/README.md +75 -0
- llm_api_adapter_zai-0.1.0/pyproject.toml +58 -0
- llm_api_adapter_zai-0.1.0/setup.cfg +4 -0
- llm_api_adapter_zai-0.1.0/src/llm_api_adapter_zai/__init__.py +3 -0
- llm_api_adapter_zai-0.1.0/src/llm_api_adapter_zai/adapter.py +777 -0
- llm_api_adapter_zai-0.1.0/src/llm_api_adapter_zai/clients/__init__.py +18 -0
- llm_api_adapter_zai-0.1.0/src/llm_api_adapter_zai/clients/async_client.py +70 -0
- llm_api_adapter_zai-0.1.0/src/llm_api_adapter_zai/clients/sync_client.py +212 -0
- llm_api_adapter_zai-0.1.0/src/llm_api_adapter_zai/plugin.py +27 -0
- llm_api_adapter_zai-0.1.0/src/llm_api_adapter_zai/py.typed +1 -0
- llm_api_adapter_zai-0.1.0/src/llm_api_adapter_zai/registry/__init__.py +38 -0
- llm_api_adapter_zai-0.1.0/src/llm_api_adapter_zai/registry/cache_pricing.py +95 -0
- llm_api_adapter_zai-0.1.0/src/llm_api_adapter_zai/registry/organizations/zai.json +27 -0
- llm_api_adapter_zai-0.1.0/src/llm_api_adapter_zai/request_rules.py +19 -0
- llm_api_adapter_zai-0.1.0/src/llm_api_adapter_zai/streaming.py +234 -0
- llm_api_adapter_zai-0.1.0/src/llm_api_adapter_zai.egg-info/SOURCES.txt +19 -0
- llm_api_adapter_zai-0.1.0/tests/test_capability_discovery.py +119 -0
- llm_api_adapter_zai-0.1.0/tests/test_package_scaffold.py +76 -0
- llm_api_adapter_zai-0.1.0/tests/test_zai_adapter.py +1054 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sergey Inozemtsev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
include README.md
|
|
2
|
+
include LICENSE
|
|
3
|
+
include src/llm_api_adapter_zai/py.typed
|
|
4
|
+
recursive-include src/llm_api_adapter_zai/registry/organizations *.json
|
|
5
|
+
|
|
6
|
+
global-exclude *.py[cod]
|
|
7
|
+
prune **/__pycache__
|
|
8
|
+
prune **/.pytest_cache
|
|
9
|
+
global-exclude *.egg-info
|
|
10
|
+
prune **/*.egg-info
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: llm-api-adapter-zai
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Z.ai GLM API package for llm-api-adapter
|
|
5
|
+
Author: Sergey Inozemtsev
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 Sergey Inozemtsev
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Repository, https://github.com/Inozem/llm_api_adapter/
|
|
29
|
+
Keywords: llm,zai,glm,adapter,api
|
|
30
|
+
Classifier: Programming Language :: Python :: 3
|
|
31
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
32
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
33
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
34
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
36
|
+
Classifier: Typing :: Typed
|
|
37
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
38
|
+
Classifier: Operating System :: OS Independent
|
|
39
|
+
Requires-Python: >=3.10
|
|
40
|
+
Description-Content-Type: text/markdown
|
|
41
|
+
License-File: LICENSE
|
|
42
|
+
Requires-Dist: llm-api-adapter<1.0.0,>=0.9.7
|
|
43
|
+
Provides-Extra: async
|
|
44
|
+
Requires-Dist: llm-api-adapter[async]<1.0.0,>=0.9.7; extra == "async"
|
|
45
|
+
Provides-Extra: httpx
|
|
46
|
+
Requires-Dist: llm-api-adapter[httpx]<1.0.0,>=0.9.7; extra == "httpx"
|
|
47
|
+
Dynamic: license-file
|
|
48
|
+
|
|
49
|
+
# llm-api-adapter-zai
|
|
50
|
+
|
|
51
|
+
Official direct Z.ai / GLM Chat Completions API support for
|
|
52
|
+
[llm-api-adapter](https://github.com/Inozem/llm_api_adapter/). The package
|
|
53
|
+
targets Core `>=0.9.7,<1.0.0` and does not install a provider SDK.
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
Install through the Core package extra:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install "llm-api-adapter[zai]"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Direct installation is also supported when Core is managed separately:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install llm-api-adapter-zai
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Async requests need HTTPX:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install "llm-api-adapter[zai,async]"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Synchronous requests use `requests` by default. To opt into HTTPX for sync
|
|
76
|
+
`chat()` and `stream_chat()`, install `"llm-api-adapter[zai,httpx]"` and pass
|
|
77
|
+
`transport="httpx"`.
|
|
78
|
+
|
|
79
|
+
## Quick start
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
import os
|
|
83
|
+
|
|
84
|
+
from llm_api_adapter.models.messages.chat_message import UserMessage
|
|
85
|
+
from llm_api_adapter.universal_adapter import UniversalLLMAPIAdapter
|
|
86
|
+
|
|
87
|
+
adapter = UniversalLLMAPIAdapter(
|
|
88
|
+
organization="zai",
|
|
89
|
+
model="glm-5.3-flash",
|
|
90
|
+
api_key=os.environ["ZAI_API_KEY"],
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
response = adapter.chat(
|
|
94
|
+
messages=[UserMessage("Explain retrieval-augmented generation.")],
|
|
95
|
+
max_tokens=128,
|
|
96
|
+
)
|
|
97
|
+
print(response.content)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Supported model and capabilities
|
|
101
|
+
|
|
102
|
+
The package deliberately exposes one exact, verified model ID:
|
|
103
|
+
`glm-5.3-flash`.
|
|
104
|
+
|
|
105
|
+
| Capability | `glm-5.3-flash` |
|
|
106
|
+
| --- | --- |
|
|
107
|
+
| Text chat; sync/async streaming | Supported through the official Chat Completions endpoint |
|
|
108
|
+
| Application function tools | `tool_choice="auto"` only; at most 128 declarations |
|
|
109
|
+
| Reasoning | Core `reasoning_level` is mapped to Z.ai effort; kept separate from visible text |
|
|
110
|
+
| Image input | User-message URL, bytes, and data-URL forms |
|
|
111
|
+
| Usage | Valid provider usage only; missing or malformed usage is unavailable |
|
|
112
|
+
| Portable JSON Schema / Pydantic output | Unsupported; rejected before HTTP |
|
|
113
|
+
| Documents and generic files | Unsupported; rejected before HTTP |
|
|
114
|
+
| Deployments, uploads, OCR, retries, continuation, and video | Unsupported |
|
|
115
|
+
|
|
116
|
+
Unknown, retired, aliased, or unverified model IDs are not inferred. Unsupported
|
|
117
|
+
tool choices, parallel-tool control, provider-built-in tools, and every
|
|
118
|
+
`DocumentPart` URL or byte form fail locally before the transport is called.
|
|
119
|
+
The adapter accepts only the official endpoint and the `ZAI_API_KEY` bearer
|
|
120
|
+
credential.
|
|
121
|
+
|
|
122
|
+
See the main [llm-api-adapter README](https://github.com/Inozem/llm_api_adapter/#readme)
|
|
123
|
+
for the shared API contract and transport behavior.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# llm-api-adapter-zai
|
|
2
|
+
|
|
3
|
+
Official direct Z.ai / GLM Chat Completions API support for
|
|
4
|
+
[llm-api-adapter](https://github.com/Inozem/llm_api_adapter/). The package
|
|
5
|
+
targets Core `>=0.9.7,<1.0.0` and does not install a provider SDK.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Install through the Core package extra:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install "llm-api-adapter[zai]"
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Direct installation is also supported when Core is managed separately:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install llm-api-adapter-zai
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Async requests need HTTPX:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install "llm-api-adapter[zai,async]"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Synchronous requests use `requests` by default. To opt into HTTPX for sync
|
|
28
|
+
`chat()` and `stream_chat()`, install `"llm-api-adapter[zai,httpx]"` and pass
|
|
29
|
+
`transport="httpx"`.
|
|
30
|
+
|
|
31
|
+
## Quick start
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
import os
|
|
35
|
+
|
|
36
|
+
from llm_api_adapter.models.messages.chat_message import UserMessage
|
|
37
|
+
from llm_api_adapter.universal_adapter import UniversalLLMAPIAdapter
|
|
38
|
+
|
|
39
|
+
adapter = UniversalLLMAPIAdapter(
|
|
40
|
+
organization="zai",
|
|
41
|
+
model="glm-5.3-flash",
|
|
42
|
+
api_key=os.environ["ZAI_API_KEY"],
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
response = adapter.chat(
|
|
46
|
+
messages=[UserMessage("Explain retrieval-augmented generation.")],
|
|
47
|
+
max_tokens=128,
|
|
48
|
+
)
|
|
49
|
+
print(response.content)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Supported model and capabilities
|
|
53
|
+
|
|
54
|
+
The package deliberately exposes one exact, verified model ID:
|
|
55
|
+
`glm-5.3-flash`.
|
|
56
|
+
|
|
57
|
+
| Capability | `glm-5.3-flash` |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| Text chat; sync/async streaming | Supported through the official Chat Completions endpoint |
|
|
60
|
+
| Application function tools | `tool_choice="auto"` only; at most 128 declarations |
|
|
61
|
+
| Reasoning | Core `reasoning_level` is mapped to Z.ai effort; kept separate from visible text |
|
|
62
|
+
| Image input | User-message URL, bytes, and data-URL forms |
|
|
63
|
+
| Usage | Valid provider usage only; missing or malformed usage is unavailable |
|
|
64
|
+
| Portable JSON Schema / Pydantic output | Unsupported; rejected before HTTP |
|
|
65
|
+
| Documents and generic files | Unsupported; rejected before HTTP |
|
|
66
|
+
| Deployments, uploads, OCR, retries, continuation, and video | Unsupported |
|
|
67
|
+
|
|
68
|
+
Unknown, retired, aliased, or unverified model IDs are not inferred. Unsupported
|
|
69
|
+
tool choices, parallel-tool control, provider-built-in tools, and every
|
|
70
|
+
`DocumentPart` URL or byte form fail locally before the transport is called.
|
|
71
|
+
The adapter accepts only the official endpoint and the `ZAI_API_KEY` bearer
|
|
72
|
+
credential.
|
|
73
|
+
|
|
74
|
+
See the main [llm-api-adapter README](https://github.com/Inozem/llm_api_adapter/#readme)
|
|
75
|
+
for the shared API contract and transport behavior.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=69", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "llm-api-adapter-zai"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Official Z.ai GLM API package for llm-api-adapter"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = {file = "LICENSE"}
|
|
12
|
+
authors = [{name = "Sergey Inozemtsev"}]
|
|
13
|
+
keywords = ["llm", "zai", "glm", "adapter", "api"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Programming Language :: Python :: 3.10",
|
|
17
|
+
"Programming Language :: Python :: 3.11",
|
|
18
|
+
"Programming Language :: Python :: 3.12",
|
|
19
|
+
"Programming Language :: Python :: 3.13",
|
|
20
|
+
"Programming Language :: Python :: 3.14",
|
|
21
|
+
"Typing :: Typed",
|
|
22
|
+
"License :: OSI Approved :: MIT License",
|
|
23
|
+
"Operating System :: OS Independent",
|
|
24
|
+
]
|
|
25
|
+
dependencies = ["llm-api-adapter>=0.9.7,<1.0.0"]
|
|
26
|
+
|
|
27
|
+
[project.optional-dependencies]
|
|
28
|
+
async = ["llm-api-adapter[async]>=0.9.7,<1.0.0"]
|
|
29
|
+
httpx = ["llm-api-adapter[httpx]>=0.9.7,<1.0.0"]
|
|
30
|
+
|
|
31
|
+
[project.entry-points."llm_api_adapter.organizations"]
|
|
32
|
+
zai = "llm_api_adapter_zai.plugin:PLUGIN"
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
Repository = "https://github.com/Inozem/llm_api_adapter/"
|
|
36
|
+
|
|
37
|
+
[tool.setuptools.package-dir]
|
|
38
|
+
"" = "src"
|
|
39
|
+
|
|
40
|
+
[tool.setuptools.packages.find]
|
|
41
|
+
where = ["src"]
|
|
42
|
+
include = ["llm_api_adapter_zai*"]
|
|
43
|
+
exclude = ["tests*", "*/tests*"]
|
|
44
|
+
|
|
45
|
+
[tool.setuptools]
|
|
46
|
+
include-package-data = true
|
|
47
|
+
|
|
48
|
+
[tool.setuptools.package-data]
|
|
49
|
+
"llm_api_adapter_zai" = ["py.typed", "registry/organizations/*.json"]
|
|
50
|
+
|
|
51
|
+
[tool.pytest.ini_options]
|
|
52
|
+
markers = [
|
|
53
|
+
"unit: unit tests (no network, pure logic, mocks)",
|
|
54
|
+
"integration: integration tests (mocked HTTP, no real organizations)",
|
|
55
|
+
"e2e: end-to-end tests (real LLM organizations)",
|
|
56
|
+
"e2e_zai: end-to-end tests for the external Z.ai organization package",
|
|
57
|
+
"e2e_feature(name): capability required by a parametrized Core E2E scenario",
|
|
58
|
+
]
|