From a9a06ae511048dd6a122f8dddbdff2d96911fd10 Mon Sep 17 00:00:00 2001 From: tomsun28 Date: Wed, 3 Jun 2026 17:59:18 +0800 Subject: [PATCH 1/4] feat: update new models glm-5.1 and support reasoning_effort --- README.md | 6 +++--- README_CN.md | 6 +++--- examples/basic_usage.py | 14 +++++++------- examples/glm_example.py | 6 +++--- examples/glm_thinking.py | 2 +- examples/stream_tools.py | 2 +- src/zai/api_resource/chat/completions.py | 3 +++ 7 files changed, 21 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 6a4480f..b2a768a 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ ## ✨ Core Features ### 🤖 **Chat Completions** -- **Standard Chat**: Create chat completions with various models including `glm-5.1` +- **Standard Chat**: Create chat completions with various models including `glm-5.2` - **Streaming Support**: Real-time streaming responses for interactive applications - **Tool Calling**: Function calling capabilities for enhanced AI interactions - **Multimodal Chat**: Image understanding capabilities with vision models @@ -104,7 +104,7 @@ client = ZhipuAiClient(api_key="your-api-key") # Create chat completion response = client.chat.completions.create( - model="glm-5.1", + model="glm-5.2", messages=[ {"role": "user", "content": "Hello, Z.ai!"} ] @@ -278,7 +278,7 @@ client = ZaiClient(api_key="your-api-key") try: response = client.chat.completions.create( - model="glm-5.1", + model="glm-5.2", messages=[ {"role": "user", "content": "Hello, Z.ai!"} ] diff --git a/README_CN.md b/README_CN.md index 1d953cd..91ae99f 100644 --- a/README_CN.md +++ b/README_CN.md @@ -11,7 +11,7 @@ ## ✨ 核心功能 ### 🤖 **对话补全** -- **标准对话**: 支持 `glm-5.1` 等多种模型的对话补全 +- **标准对话**: 支持 `glm-5.2` 等多种模型的对话补全 - **流式支持**: 实时流式响应,适用于交互式应用 - **工具调用**: 函数调用能力,增强 AI 交互体验 - **多模态对话**: 支持图像理解的视觉模型 @@ -106,7 +106,7 @@ client = ZhipuAiClient(api_key="your-api-key") # Create chat completion response = client.chat.completions.create( - model="glm-5.1", + model="glm-5.2", messages=[ {"role": "user", "content": "Hello, Z.ai!"} ] @@ -285,7 +285,7 @@ client = ZaiClient(api_key="your-api-key") # 请填写您自己的APIKey try: response = client.chat.completions.create( - model="glm-5.1", + model="glm-5.2", messages=[ {"role": "user", "content": "你好, Z.ai !"} ] diff --git a/examples/basic_usage.py b/examples/basic_usage.py index d774363..cce716a 100644 --- a/examples/basic_usage.py +++ b/examples/basic_usage.py @@ -6,7 +6,7 @@ def completion(): # Create chat completion response = client.chat.completions.create( - model='glm-5.1', + model='glm-5.2', messages=[{'role': 'user', 'content': 'Hello, Z.ai!'}], temperature=1.0, ) @@ -19,7 +19,7 @@ def completion_with_stream(): # Create chat completion response = client.chat.completions.create( - model='glm-5.1', + model='glm-5.2', messages=[ {'role': 'system', 'content': 'You are a helpful assistant.'}, {'role': 'user', 'content': 'Tell me a story about AI.'}, @@ -38,7 +38,7 @@ def completion_with_websearch(): # Create chat completion response = client.chat.completions.create( - model='glm-5.1', + model='glm-5.2', messages=[ {'role': 'system', 'content': 'You are a helpful assistant.'}, {'role': 'user', 'content': 'What is artificial intelligence?'}, @@ -66,7 +66,7 @@ def completion_with_mcp_server_url(): # Create chat completion with MCP server URL response = client.chat.completions.create( - model='glm-5.1', + model='glm-5.2', stream=False, messages=[{'role': 'user', 'content': 'Hello, please introduce GPT?'}], tools=[ @@ -95,7 +95,7 @@ def completion_with_mcp_server_label(): # Create chat completion with MCP server label response = client.chat.completions.create( - model='glm-5.1', + model='glm-5.2', stream=False, messages=[{'role': 'user', 'content': 'Hello, please introduce GPT?'}], tools=[ @@ -217,7 +217,7 @@ def ofZai(): client = ZaiClient() print(client.base_url) response = client.chat.completions.create( - model='glm-5.1', + model='glm-5.2', messages=[{'role': 'user', 'content': 'Hello, Z.ai!'}], temperature=0.7, ) @@ -227,7 +227,7 @@ def ofZhipu(): client = ZhipuAiClient() print(client.base_url) response = client.chat.completions.create( - model='glm-5.1', + model='glm-5.2', messages=[{'role': 'user', 'content': 'Hello, Z.ai!'}], temperature=0.7, ) diff --git a/examples/glm_example.py b/examples/glm_example.py index 59f7b99..28f26e5 100644 --- a/examples/glm_example.py +++ b/examples/glm_example.py @@ -23,7 +23,7 @@ def stream_web_search_example(): }] client = ZaiClient() response = client.chat.completions.create( - model="glm-5.1", + model="glm-5.2", messages=messages, tools=tools, stream=True @@ -35,7 +35,7 @@ def sync_example(): print("=== GLM-4 Synchronous Example ===") client = ZaiClient() response = client.chat.completions.create( - model="glm-5.1", + model="glm-5.2", messages=[ {"role": "system", "content": "You are a helpful assistant who provides professional, accurate, and insightful advice."}, {"role": "user", "content": "I'm very interested in the planets of the solar system, especially Saturn. Please provide basic information about Saturn, including its size, composition, ring system, and any unique astronomical phenomena."}, @@ -47,7 +47,7 @@ def async_example(): print("=== GLM-4 Async Example ===") client = ZaiClient() response = client.chat.asyncCompletions.create( - model="glm-5.1", + model="glm-5.2", messages=[ { "role": "user", diff --git a/examples/glm_thinking.py b/examples/glm_thinking.py index 09918e5..61239fe 100644 --- a/examples/glm_thinking.py +++ b/examples/glm_thinking.py @@ -15,7 +15,7 @@ class ZaiSampler(SamplerBase): def __init__( self, - model: str = "glm-5", + model: str = "glm-5.2", api_key: str = '', system_message: Optional[str] = None, temperature: float = 0.0, diff --git a/examples/stream_tools.py b/examples/stream_tools.py index b821969..68dafcb 100644 --- a/examples/stream_tools.py +++ b/examples/stream_tools.py @@ -4,7 +4,7 @@ def main(): client = ZhipuAiClient() # create chat completion with tool calls and streaming response = client.chat.completions.create( - model="glm-5.1", + model="glm-5.2", messages=[ {"role": "user", "content": "How is the weather in Beijing and Shanghai? Please provide the answer in Celsius."}, ], diff --git a/src/zai/api_resource/chat/completions.py b/src/zai/api_resource/chat/completions.py index 7c8f6c6..16d5f99 100644 --- a/src/zai/api_resource/chat/completions.py +++ b/src/zai/api_resource/chat/completions.py @@ -67,6 +67,7 @@ def create( thinking: object | None = None, watermark_enabled: Optional[bool] | NotGiven = NOT_GIVEN, tool_stream: bool | NotGiven = NOT_GIVEN, + reasoning_effort: Optional[str] | NotGiven = NOT_GIVEN, ) -> Completion | StreamResponse[ChatCompletionChunk]: """ Create a chat completion @@ -95,6 +96,7 @@ def create( thinking (Optional[object]): Configuration parameters for model reasoning watermark_enabled (Optional[bool]): Whether to enable watermark on generated audio tool_stream (Optional[bool]): Whether to enable tool streaming + reasoning_effort (Optional[str]): Reasoning effort level, supports none, minimal, low, medium, high, xhigh, max. Defaults to max when not set. Effective for glm-5.2 and above models. """ logger.debug(f'temperature:{temperature}, top_p:{top_p}') if temperature is not None and temperature != NOT_GIVEN: @@ -144,6 +146,7 @@ def create( 'thinking': thinking, 'watermark_enabled': watermark_enabled, 'tool_stream': tool_stream, + 'reasoning_effort': reasoning_effort, } ) return self._post( From 7fddb8cdc187df0a0077cce5ec33aa1f023a9c4a Mon Sep 17 00:00:00 2001 From: tomsun28 Date: Tue, 16 Jun 2026 10:41:37 +0800 Subject: [PATCH 2/4] feat: update new models glm-5.1 and support reasoning_effort --- pyproject.toml | 2 +- src/zai/_version.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a539fd6..eadc37e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "zai-sdk" -version = "0.2.2" +version = "0.2.3" description = "A SDK library for accessing big model apis from Z.ai" authors = ["Z.ai"] readme = "README.md" diff --git a/src/zai/_version.py b/src/zai/_version.py index 3acae28..87d2b4b 100644 --- a/src/zai/_version.py +++ b/src/zai/_version.py @@ -1,2 +1,2 @@ __title__ = 'Z.ai' -__version__ = '0.2.2' +__version__ = '0.2.3' From 132e61f0eafabb34eec3380d1be66b5e09a9d086 Mon Sep 17 00:00:00 2001 From: tomsun28 Date: Tue, 16 Jun 2026 10:46:34 +0800 Subject: [PATCH 3/4] feat: update new models glm-5.1 and support reasoning_effort --- src/zai/api_resource/chat/completions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zai/api_resource/chat/completions.py b/src/zai/api_resource/chat/completions.py index 16d5f99..2186c16 100644 --- a/src/zai/api_resource/chat/completions.py +++ b/src/zai/api_resource/chat/completions.py @@ -96,7 +96,7 @@ def create( thinking (Optional[object]): Configuration parameters for model reasoning watermark_enabled (Optional[bool]): Whether to enable watermark on generated audio tool_stream (Optional[bool]): Whether to enable tool streaming - reasoning_effort (Optional[str]): Reasoning effort level, supports none, minimal, low, medium, high, xhigh, max. Defaults to max when not set. Effective for glm-5.2 and above models. + reasoning_effort (Optional[str]): Reasoning effort level, supports none, minimal, low, medium, high, xhigh, max. Effective for glm-5.2 and above models. """ logger.debug(f'temperature:{temperature}, top_p:{top_p}') if temperature is not None and temperature != NOT_GIVEN: From 4a9e6ef79355f0ea06393518e2c0e460f32516d0 Mon Sep 17 00:00:00 2001 From: tomsun28 Date: Tue, 16 Jun 2026 10:51:42 +0800 Subject: [PATCH 4/4] fix: correct indentation from spaces to tabs in completions.py --- src/zai/api_resource/chat/completions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/zai/api_resource/chat/completions.py b/src/zai/api_resource/chat/completions.py index 2186c16..770a0b8 100644 --- a/src/zai/api_resource/chat/completions.py +++ b/src/zai/api_resource/chat/completions.py @@ -66,7 +66,7 @@ def create( response_format: object | None = None, thinking: object | None = None, watermark_enabled: Optional[bool] | NotGiven = NOT_GIVEN, - tool_stream: bool | NotGiven = NOT_GIVEN, + tool_stream: bool | NotGiven = NOT_GIVEN, reasoning_effort: Optional[str] | NotGiven = NOT_GIVEN, ) -> Completion | StreamResponse[ChatCompletionChunk]: """ @@ -145,8 +145,8 @@ def create( 'response_format': response_format, 'thinking': thinking, 'watermark_enabled': watermark_enabled, - 'tool_stream': tool_stream, - 'reasoning_effort': reasoning_effort, + 'tool_stream': tool_stream, + 'reasoning_effort': reasoning_effort, } ) return self._post(