Skip to content

Commit 6d9d9f8

Browse files
authored
feat: support glm-4.7 model (#56)
1 parent 84d48d4 commit 6d9d9f8

File tree

13 files changed

+42
-161
lines changed

13 files changed

+42
-161
lines changed

README.md

Lines changed: 6 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
## ✨ Core Features
1212

1313
### 🤖 **Chat Completions**
14-
- **Standard Chat**: Create chat completions with various models including `glm-4`, `charglm-3`
14+
- **Standard Chat**: Create chat completions with various models including `glm-4.7`
1515
- **Streaming Support**: Real-time streaming responses for interactive applications
1616
- **Tool Calling**: Function calling capabilities for enhanced AI interactions
1717
- **Character Role-Playing**: Support for character-based conversations with `charglm-3` model
@@ -105,7 +105,7 @@ client = ZhipuAiClient(api_key="your-api-key")
105105

106106
# Create chat completion
107107
response = client.chat.completions.create(
108-
model="glm-4",
108+
model="glm-4.7",
109109
messages=[
110110
{"role": "user", "content": "Hello, Z.ai!"}
111111
]
@@ -169,7 +169,7 @@ client = ZaiClient(api_key="your-api-key")
169169

170170
# Create chat completion
171171
response = client.chat.completions.create(
172-
model='glm-4.6',
172+
model='glm-4.7',
173173
messages=[
174174
{'role': 'system', 'content': 'You are a helpful assistant.'},
175175
{'role': 'user', 'content': 'Tell me a story about AI.'},
@@ -192,7 +192,7 @@ client = ZaiClient(api_key="your-api-key")
192192

193193
# Create chat completion
194194
response = client.chat.completions.create(
195-
model='glm-4.6',
195+
model='glm-4.7',
196196
messages=[
197197
{'role': 'system', 'content': 'You are a helpful assistant.'},
198198
{'role': 'user', 'content': 'What is artificial intelligence?'},
@@ -244,65 +244,6 @@ response = client.chat.completions.create(
244244
print(response)
245245
```
246246

247-
### Character Role-Playing
248-
249-
```python
250-
from zai import ZaiClient
251-
252-
# Initialize client
253-
client = ZaiClient(api_key="your-api-key")
254-
255-
# Create chat completion
256-
response = client.chat.completions.create(
257-
model='charglm-3',
258-
messages=[{'role': 'user', 'content': 'Hello, how are you doing lately?'}],
259-
meta={
260-
'user_info': 'I am a film director who specializes in music-themed movies.',
261-
'bot_info': 'You are a popular domestic female singer and actress with outstanding musical talent.',
262-
'bot_name': 'Alice',
263-
'user_name': 'Director',
264-
},
265-
)
266-
print(response)
267-
```
268-
269-
### Assistant Conversation
270-
271-
```python
272-
from zai import ZaiClient
273-
274-
# Initialize client
275-
client = ZaiClient(api_key="your-api-key")
276-
277-
# Create assistant conversation
278-
response = client.assistant.conversation(
279-
# You can use 65940acff94777010aa6b796 for testing
280-
# or you can create your own assistant_id in Z.ai console
281-
assistant_id='your own assistant_id',
282-
model='glm-4-assistant',
283-
messages=[
284-
{
285-
'role': 'user',
286-
'content': [
287-
{
288-
'type': 'text',
289-
'text': 'Help me search for the latest Z.ai product information',
290-
}
291-
],
292-
}
293-
],
294-
stream=True,
295-
attachments=None,
296-
metadata=None,
297-
request_id='request_1790291013237211136',
298-
user_id='12345678',
299-
)
300-
301-
for chunk in response:
302-
if chunk.choices[0].delta.type == 'content':
303-
print(chunk.choices[0].delta.content, end='')
304-
```
305-
306247
### Video Generation
307248

308249
```python
@@ -311,7 +252,7 @@ client = ZaiClient(api_key="your-api-key")
311252

312253
# Generate video
313254
response = client.videos.generations(
314-
model="cogvideox-2",
255+
model="cogvideox-3",
315256
prompt="A cat is playing with a ball.",
316257
quality="quality", # Output mode, "quality" for quality priority, "speed" for speed priority
317258
with_audio=True, # Whether to include audio
@@ -338,7 +279,7 @@ client = ZaiClient(api_key="your-api-key")
338279

339280
try:
340281
response = client.chat.completions.create(
341-
model="glm-4.6",
282+
model="glm-4.7",
342283
messages=[
343284
{"role": "user", "content": "Hello, Z.ai!"}
344285
]

README_CN.md

Lines changed: 5 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
[English Readme](README.md)
88

9-
[Z.ai 开放平台](https://docs.z.ai/)官方 Python SDK,帮助开发者快速集成 Z.ai 强大的人工智能能力到Python应用中
9+
[智谱开放平台](https://docs.bigmodel.cn/)官方 Python SDK,帮助开发者快速集成智谱强大的人工智能能力到Python应用中
1010

1111
## ✨ 核心功能
1212

1313
### 🤖 **对话补全**
14-
- **标准对话**: 支持 `glm-4``charglm-3` 等多种模型的对话补全
14+
- **标准对话**: 支持 `glm-4.7` 等多种模型的对话补全
1515
- **流式支持**: 实时流式响应,适用于交互式应用
1616
- **工具调用**: 函数调用能力,增强 AI 交互体验
1717
- **角色扮演**: 支持基于 `charglm-3` 模型的角色对话
@@ -107,7 +107,7 @@ client = ZhipuAiClient(api_key="your-api-key")
107107

108108
# Create chat completion
109109
response = client.chat.completions.create(
110-
model="glm-4.6",
110+
model="glm-4.7",
111111
messages=[
112112
{"role": "user", "content": "Hello, Z.ai!"}
113113
]
@@ -250,64 +250,6 @@ response = client.chat.completions.create(
250250
print(response)
251251
```
252252

253-
### 角色扮演
254-
255-
```python
256-
from zai import ZaiClient
257-
258-
# 初始化客户端
259-
client = ZaiClient(api_key="your-api-key")
260-
261-
# 创建对话
262-
response = client.chat.completions.create(
263-
model='charglm-3',
264-
messages=[{'role': 'user', 'content': 'Hello, how are you doing lately?'}],
265-
meta={
266-
'user_info': 'I am a film director who specializes in music-themed movies.',
267-
'bot_info': 'You are a popular domestic female singer and actress with outstanding musical talent.',
268-
'bot_name': 'Alice',
269-
'user_name': 'Director',
270-
},
271-
)
272-
print(response)
273-
```
274-
275-
### 智能体对话
276-
277-
```python
278-
from zai import ZaiClient
279-
280-
# Initialize client
281-
client = ZaiClient(api_key="your-api-key")
282-
283-
# Create assistant conversation
284-
response = client.assistant.conversation(
285-
# 你可使用 65940acff94777010aa6b796 作为测试ID
286-
assistant_id='你的assistant_id',
287-
model='glm-4-assistant',
288-
messages=[
289-
{
290-
'role': 'user',
291-
'content': [
292-
{
293-
'type': 'text',
294-
'text': 'Help me search for the latest Z.ai product information',
295-
}
296-
],
297-
}
298-
],
299-
stream=True,
300-
attachments=None,
301-
metadata=None,
302-
request_id='request_1790291013237211136',
303-
user_id='12345678',
304-
)
305-
306-
for chunk in response:
307-
if chunk.choices[0].delta.type == 'content':
308-
print(chunk.choices[0].delta.content, end='')
309-
```
310-
311253
### 视频生成
312254

313255
```python
@@ -317,7 +259,7 @@ client = ZaiClient() # 请填写您自己的APIKey
317259

318260
# 提交生成任务
319261
response = client.videos.generations(
320-
model="cogvideox-2", # 使用的视频生成模型
262+
model="cogvideox-3", # 使用的视频生成模型
321263
image_url=image_url, # 提供的图片URL地址或者 Base64 编码
322264
prompt="让画面动起来",
323265
quality="speed", # 输出模式,"quality"为质量优先,"speed"为速度优先
@@ -344,7 +286,7 @@ client = ZaiClient(api_key="your-api-key") # 请填写您自己的APIKey
344286

345287
try:
346288
response = client.chat.completions.create(
347-
model="glm-4.6",
289+
model="glm-4.7",
348290
messages=[
349291
{"role": "user", "content": "你好, Z.ai !"}
350292
]

examples/basic_usage.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def completion():
66

77
# Create chat completion
88
response = client.chat.completions.create(
9-
model='glm-4.6',
9+
model='glm-4.7',
1010
messages=[{'role': 'user', 'content': 'Hello, Z.ai!'}],
1111
temperature=1.0,
1212
)
@@ -19,7 +19,7 @@ def completion_with_stream():
1919

2020
# Create chat completion
2121
response = client.chat.completions.create(
22-
model='glm-4.6',
22+
model='glm-4.7',
2323
messages=[
2424
{'role': 'system', 'content': 'You are a helpful assistant.'},
2525
{'role': 'user', 'content': 'Tell me a story about AI.'},
@@ -38,7 +38,7 @@ def completion_with_websearch():
3838

3939
# Create chat completion
4040
response = client.chat.completions.create(
41-
model='glm-4.6',
41+
model='glm-4.7',
4242
messages=[
4343
{'role': 'system', 'content': 'You are a helpful assistant.'},
4444
{'role': 'user', 'content': 'What is artificial intelligence?'},
@@ -66,7 +66,7 @@ def completion_with_mcp_server_url():
6666

6767
# Create chat completion with MCP server URL
6868
response = client.chat.completions.create(
69-
model='glm-4',
69+
model='glm-4.7',
7070
stream=False,
7171
messages=[{'role': 'user', 'content': 'Hello, please introduce GPT?'}],
7272
tools=[
@@ -95,7 +95,7 @@ def completion_with_mcp_server_label():
9595

9696
# Create chat completion with MCP server label
9797
response = client.chat.completions.create(
98-
model='glm-4',
98+
model='glm-4.7',
9999
stream=False,
100100
messages=[{'role': 'user', 'content': 'Hello, please introduce GPT?'}],
101101
tools=[
@@ -208,7 +208,7 @@ def audio_transcription():
208208

209209
# Create audio transcription
210210
response = client.audio.transcriptions.create(
211-
model='glm-4',
211+
model='glm-asr-2512',
212212
file='audio.mp3',
213213
)
214214
print(response.text)
@@ -217,7 +217,7 @@ def ofZai():
217217
client = ZaiClient()
218218
print(client.base_url)
219219
response = client.chat.completions.create(
220-
model='glm-4',
220+
model='glm-4.7',
221221
messages=[{'role': 'user', 'content': 'Hello, Z.ai!'}],
222222
temperature=0.7,
223223
)
@@ -227,7 +227,7 @@ def ofZhipu():
227227
client = ZhipuAiClient()
228228
print(client.base_url)
229229
response = client.chat.completions.create(
230-
model='glm-4',
230+
model='glm-4.7',
231231
messages=[{'role': 'user', 'content': 'Hello, Z.ai!'}],
232232
temperature=0.7,
233233
)

examples/function_call_example.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def parse_function_call(model_response, messages):
3636
"tool_call_id": tool_call.id
3737
})
3838
response = client.chat.completions.create(
39-
model="glm-4", # Specify the model name to use
39+
model="glm-4.7", # Specify the model name to use
4040
messages=messages,
4141
tools=tools,
4242
)
@@ -99,7 +99,7 @@ def parse_function_call(model_response, messages):
9999
messages.append({"role": "user", "content": "Help me check the flights from Beijing to Guangzhou on January 23."})
100100

101101
response = client.chat.completions.create(
102-
model="glm-4", # Specify the model name to use
102+
model="glm-4.7", # Specify the model name to use
103103
messages=messages,
104104
tools=tools,
105105
)
@@ -110,7 +110,7 @@ def parse_function_call(model_response, messages):
110110

111111
messages.append({"role": "user", "content": "What is the price of flight 8321?"})
112112
response = client.chat.completions.create(
113-
model="glm-4", # Specify the model name to use
113+
model="glm-4.7", # Specify the model name to use
114114
messages=messages,
115115
tools=tools,
116116
)

examples/glm4_example.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def stream_web_search_example():
2323
}]
2424
client = ZaiClient()
2525
response = client.chat.completions.create(
26-
model="glm-4-air",
26+
model="glm-4.7",
2727
messages=messages,
2828
tools=tools,
2929
stream=True
@@ -35,7 +35,7 @@ def sync_example():
3535
print("=== GLM-4 Synchronous Example ===")
3636
client = ZaiClient()
3737
response = client.chat.completions.create(
38-
model="glm-4-plus",
38+
model="glm-4.7",
3939
messages=[
4040
{"role": "system", "content": "You are a helpful assistant who provides professional, accurate, and insightful advice."},
4141
{"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():
4747
print("=== GLM-4 Async Example ===")
4848
client = ZaiClient()
4949
response = client.chat.asyncCompletions.create(
50-
model="glm-4-plus",
50+
model="glm-4.7",
5151
messages=[
5252
{
5353
"role": "user",
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import os
22
import sys
33
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
4-
import time
54
import traceback
65
from typing import Optional
76

@@ -16,7 +15,7 @@ class ZaiSampler(SamplerBase):
1615

1716
def __init__(
1817
self,
19-
model: str = "glm-4.5",
18+
model: str = "glm-4.7",
2019
api_key: str = '',
2120
system_message: Optional[str] = None,
2221
temperature: float = 0.0,

examples/stream_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def main():
44
client = ZhipuAiClient()
55
# create chat completion with tool calls and streaming
66
response = client.chat.completions.create(
7-
model="glm-4.6",
7+
model="glm-4.7",
88
messages=[
99
{"role": "user", "content": "How is the weather in Beijing and Shanghai? Please provide the answer in Celsius."},
1010
],

examples/voice_clone.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from zai import ZaiClient, ZhipuAiClient
22
import time
3-
import os
43

54
def voice_clone():
65
# Initialize client

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "zai-sdk"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
description = "A SDK library for accessing big model apis from Z.ai"
55
authors = ["Z.ai"]
66
readme = "README.md"

src/zai/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
__title__ = 'Z.ai'
2-
__version__ = '0.1.0'
2+
__version__ = '0.2.0'

0 commit comments

Comments
 (0)