Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 6 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
## ✨ Core Features

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

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

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

# Create chat completion
response = client.chat.completions.create(
model='glm-4.6',
model='glm-4.7',
messages=[
{'role': 'system', 'content': 'You are a helpful assistant.'},
{'role': 'user', 'content': 'What is artificial intelligence?'},
Expand Down Expand Up @@ -244,65 +244,6 @@ response = client.chat.completions.create(
print(response)
```

### Character Role-Playing

```python
from zai import ZaiClient

# Initialize client
client = ZaiClient(api_key="your-api-key")

# Create chat completion
response = client.chat.completions.create(
model='charglm-3',
messages=[{'role': 'user', 'content': 'Hello, how are you doing lately?'}],
meta={
'user_info': 'I am a film director who specializes in music-themed movies.',
'bot_info': 'You are a popular domestic female singer and actress with outstanding musical talent.',
'bot_name': 'Alice',
'user_name': 'Director',
},
)
print(response)
```

### Assistant Conversation

```python
from zai import ZaiClient

# Initialize client
client = ZaiClient(api_key="your-api-key")

# Create assistant conversation
response = client.assistant.conversation(
# You can use 65940acff94777010aa6b796 for testing
# or you can create your own assistant_id in Z.ai console
assistant_id='your own assistant_id',
model='glm-4-assistant',
messages=[
{
'role': 'user',
'content': [
{
'type': 'text',
'text': 'Help me search for the latest Z.ai product information',
}
],
}
],
stream=True,
attachments=None,
metadata=None,
request_id='request_1790291013237211136',
user_id='12345678',
)

for chunk in response:
if chunk.choices[0].delta.type == 'content':
print(chunk.choices[0].delta.content, end='')
```

### Video Generation

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

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

try:
response = client.chat.completions.create(
model="glm-4.6",
model="glm-4.7",
messages=[
{"role": "user", "content": "Hello, Z.ai!"}
]
Expand Down
68 changes: 5 additions & 63 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

[English Readme](README.md)

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

## ✨ 核心功能

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

# Create chat completion
response = client.chat.completions.create(
model="glm-4.6",
model="glm-4.7",
messages=[
{"role": "user", "content": "Hello, Z.ai!"}
]
Expand Down Expand Up @@ -250,64 +250,6 @@ response = client.chat.completions.create(
print(response)
```

### 角色扮演

```python
from zai import ZaiClient

# 初始化客户端
client = ZaiClient(api_key="your-api-key")

# 创建对话
response = client.chat.completions.create(
model='charglm-3',
messages=[{'role': 'user', 'content': 'Hello, how are you doing lately?'}],
meta={
'user_info': 'I am a film director who specializes in music-themed movies.',
'bot_info': 'You are a popular domestic female singer and actress with outstanding musical talent.',
'bot_name': 'Alice',
'user_name': 'Director',
},
)
print(response)
```

### 智能体对话

```python
from zai import ZaiClient

# Initialize client
client = ZaiClient(api_key="your-api-key")

# Create assistant conversation
response = client.assistant.conversation(
# 你可使用 65940acff94777010aa6b796 作为测试ID
assistant_id='你的assistant_id',
model='glm-4-assistant',
messages=[
{
'role': 'user',
'content': [
{
'type': 'text',
'text': 'Help me search for the latest Z.ai product information',
}
],
}
],
stream=True,
attachments=None,
metadata=None,
request_id='request_1790291013237211136',
user_id='12345678',
)

for chunk in response:
if chunk.choices[0].delta.type == 'content':
print(chunk.choices[0].delta.content, end='')
```

### 视频生成

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

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

try:
response = client.chat.completions.create(
model="glm-4.6",
model="glm-4.7",
messages=[
{"role": "user", "content": "你好, Z.ai !"}
]
Expand Down
16 changes: 8 additions & 8 deletions examples/basic_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def completion():

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

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

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

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

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

# Create audio transcription
response = client.audio.transcriptions.create(
model='glm-4',
model='glm-asr-2512',
file='audio.mp3',
)
print(response.text)
Expand All @@ -217,7 +217,7 @@ def ofZai():
client = ZaiClient()
print(client.base_url)
response = client.chat.completions.create(
model='glm-4',
model='glm-4.7',
messages=[{'role': 'user', 'content': 'Hello, Z.ai!'}],
temperature=0.7,
)
Expand All @@ -227,7 +227,7 @@ def ofZhipu():
client = ZhipuAiClient()
print(client.base_url)
response = client.chat.completions.create(
model='glm-4',
model='glm-4.7',
messages=[{'role': 'user', 'content': 'Hello, Z.ai!'}],
temperature=0.7,
)
Expand Down
6 changes: 3 additions & 3 deletions examples/function_call_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def parse_function_call(model_response, messages):
"tool_call_id": tool_call.id
})
response = client.chat.completions.create(
model="glm-4", # Specify the model name to use
model="glm-4.7", # Specify the model name to use
messages=messages,
tools=tools,
)
Expand Down Expand Up @@ -99,7 +99,7 @@ def parse_function_call(model_response, messages):
messages.append({"role": "user", "content": "Help me check the flights from Beijing to Guangzhou on January 23."})

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

messages.append({"role": "user", "content": "What is the price of flight 8321?"})
response = client.chat.completions.create(
model="glm-4", # Specify the model name to use
model="glm-4.7", # Specify the model name to use
messages=messages,
tools=tools,
)
Expand Down
6 changes: 3 additions & 3 deletions examples/glm4_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def stream_web_search_example():
}]
client = ZaiClient()
response = client.chat.completions.create(
model="glm-4-air",
model="glm-4.7",
messages=messages,
tools=tools,
stream=True
Expand All @@ -35,7 +35,7 @@ def sync_example():
print("=== GLM-4 Synchronous Example ===")
client = ZaiClient()
response = client.chat.completions.create(
model="glm-4-plus",
model="glm-4.7",
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."},
Expand All @@ -47,7 +47,7 @@ def async_example():
print("=== GLM-4 Async Example ===")
client = ZaiClient()
response = client.chat.asyncCompletions.create(
model="glm-4-plus",
model="glm-4.7",
messages=[
{
"role": "user",
Expand Down
3 changes: 1 addition & 2 deletions examples/glm4_5_thinking.py → examples/glm_thinking.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import time
import traceback
from typing import Optional

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

def __init__(
self,
model: str = "glm-4.5",
model: str = "glm-4.7",
api_key: str = '',
system_message: Optional[str] = None,
temperature: float = 0.0,
Expand Down
2 changes: 1 addition & 1 deletion examples/stream_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def main():
client = ZhipuAiClient()
# create chat completion with tool calls and streaming
response = client.chat.completions.create(
model="glm-4.6",
model="glm-4.7",
messages=[
{"role": "user", "content": "How is the weather in Beijing and Shanghai? Please provide the answer in Celsius."},
],
Expand Down
1 change: 0 additions & 1 deletion examples/voice_clone.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from zai import ZaiClient, ZhipuAiClient
import time
import os

def voice_clone():
# Initialize client
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "zai-sdk"
version = "0.1.0"
version = "0.2.0"
description = "A SDK library for accessing big model apis from Z.ai"
authors = ["Z.ai"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion src/zai/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__title__ = 'Z.ai'
__version__ = '0.1.0'
__version__ = '0.2.0'
Loading