diff --git a/README.md b/README.md index eac4888..cd03ecc 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-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 @@ -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!"} ] @@ -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.'}, @@ -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?'}, @@ -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 @@ -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 @@ -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!"} ] diff --git a/README_CN.md b/README_CN.md index 1347e63..0c4d08b 100644 --- a/README_CN.md +++ b/README_CN.md @@ -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` 模型的角色对话 @@ -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!"} ] @@ -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 @@ -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"为速度优先 @@ -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 !"} ] diff --git a/examples/basic_usage.py b/examples/basic_usage.py index 493e5de..e0b6a4b 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-4.6', + model='glm-4.7', 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-4.6', + model='glm-4.7', 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-4.6', + model='glm-4.7', 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-4', + model='glm-4.7', 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-4', + model='glm-4.7', stream=False, messages=[{'role': 'user', 'content': 'Hello, please introduce GPT?'}], tools=[ @@ -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) @@ -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, ) @@ -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, ) diff --git a/examples/function_call_example.py b/examples/function_call_example.py index 72247b5..0e01c03 100644 --- a/examples/function_call_example.py +++ b/examples/function_call_example.py @@ -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, ) @@ -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, ) @@ -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, ) diff --git a/examples/glm4_example.py b/examples/glm4_example.py index e0dabc5..cf16278 100644 --- a/examples/glm4_example.py +++ b/examples/glm4_example.py @@ -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 @@ -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."}, @@ -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", diff --git a/examples/glm4_5_thinking.py b/examples/glm_thinking.py similarity index 98% rename from examples/glm4_5_thinking.py rename to examples/glm_thinking.py index e1df7ae..f081935 100644 --- a/examples/glm4_5_thinking.py +++ b/examples/glm_thinking.py @@ -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 @@ -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, diff --git a/examples/stream_tools.py b/examples/stream_tools.py index a479bc1..37b3a2d 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-4.6", + model="glm-4.7", messages=[ {"role": "user", "content": "How is the weather in Beijing and Shanghai? Please provide the answer in Celsius."}, ], diff --git a/examples/voice_clone.py b/examples/voice_clone.py index ac253b1..75967df 100644 --- a/examples/voice_clone.py +++ b/examples/voice_clone.py @@ -1,6 +1,5 @@ from zai import ZaiClient, ZhipuAiClient import time -import os def voice_clone(): # Initialize client diff --git a/pyproject.toml b/pyproject.toml index 8cac675..6d2e581 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/src/zai/_version.py b/src/zai/_version.py index 61516e7..67e5fb6 100644 --- a/src/zai/_version.py +++ b/src/zai/_version.py @@ -1,2 +1,2 @@ __title__ = 'Z.ai' -__version__ = '0.1.0' +__version__ = '0.2.0' diff --git a/tests/integration_tests/test_chat.py b/tests/integration_tests/test_chat.py index d2b6ea4..e448349 100644 --- a/tests/integration_tests/test_chat.py +++ b/tests/integration_tests/test_chat.py @@ -16,7 +16,7 @@ def test_completions_temp0(logging_conf): print(f'request_id:{request_id}') response = client.chat.completions.create( request_id=request_id, - model='glm-4', + model='glm-4.7', messages=[{'role': 'user', 'content': 'tell me a joke'}], top_p=0.7, temperature=0, @@ -42,7 +42,7 @@ def test_completions_temp1(logging_conf): print(f'request_id:{request_id}') response = client.chat.completions.create( request_id=request_id, - model='glm-4', + model='glm-4.7', messages=[{'role': 'user', 'content': 'tell me a joke'}], top_p=0.7, temperature=1, @@ -68,7 +68,7 @@ def test_completions_top0(logging_conf): print(f'request_id:{request_id}') response = client.chat.completions.create( request_id=request_id, - model='glm-4', + model='glm-4.7', messages=[{'role': 'user', 'content': 'tell me a joke'}], top_p=0, temperature=0.9, @@ -94,7 +94,7 @@ def test_completions_top1(logging_conf): print(f'request_id:{request_id}') response = client.chat.completions.create( request_id=request_id, - model='glm-4', + model='glm-4.7', messages=[{'role': 'user', 'content': 'tell me a joke'}], top_p=1, temperature=0.9, @@ -120,7 +120,7 @@ def test_completions(logging_conf): print(f'request_id:{request_id}') response = client.chat.completions.create( request_id=request_id, - model='glm-4', # Fill in the model name to call + model='glm-4.7', # Fill in the model name to call messages=[ { 'role': 'user', @@ -170,7 +170,7 @@ def test_completions_disenable_web_search(logging_conf): print(f'request_id:{request_id}') response = client.chat.completions.create( request_id=request_id, - model='glm-4', # Fill in the model name to call + model='glm-4.7', # Fill in the model name to call messages=[ { 'role': 'user', @@ -221,7 +221,7 @@ def test_completions_enable_web_search(logging_conf): print(f'request_id:{request_id}') response = client.chat.completions.create( request_id=request_id, - model='glm-4', # Fill in the model name to call + model='glm-4.7', # Fill in the model name to call messages=[ { 'role': 'user', @@ -272,7 +272,7 @@ def test_completions_sensitive_word_check(logging_conf): print(f'request_id:{request_id}') response = client.chat.completions.create( request_id=request_id, - model='glm-4', # Fill in the model name to call + model='glm-4.7', # Fill in the model name to call stream=True, messages=[ { @@ -467,7 +467,7 @@ def test_completions_vis(logging_conf): print(f'request_id:{request_id}') response = client.chat.completions.create( request_id=request_id, - model='glm-4', + model='glm-4.7', messages=[{'role': 'user', 'content': 'tell me a joke'}], top_p=1, temperature=0.9, diff --git a/tests/integration_tests/test_thinking.py b/tests/integration_tests/test_thinking.py index 65cebe2..d0170a2 100644 --- a/tests/integration_tests/test_thinking.py +++ b/tests/integration_tests/test_thinking.py @@ -15,7 +15,7 @@ def test_chat_completion_with_thinking(logging_conf): print(f'request_id:{request_id}') response = client.chat.completions.create( request_id=request_id, - model='glm-4.5', + model='glm-4.7', messages=[{'role': 'user', 'content': '请介绍一下Agent的原理,并给出详细的推理过程'}], top_p=0.7, temperature=0.9, @@ -39,7 +39,7 @@ def test_chat_completion_without_thinking(logging_conf): print(f'request_id:{request_id}') response = client.chat.completions.create( request_id=request_id, - model='glm-4.5', + model='glm-4.7', messages=[{'role': 'user', 'content': '请介绍一下Agent的原理'}], top_p=0.7, temperature=0.9, diff --git a/tests/integration_tests/test_vlm_thinking.py b/tests/integration_tests/test_vlm_thinking.py index 3c252cb..1d3ba19 100644 --- a/tests/integration_tests/test_vlm_thinking.py +++ b/tests/integration_tests/test_vlm_thinking.py @@ -15,7 +15,7 @@ def test_completions_vlm_thinking(logging_conf): print(f'request_id:{request_id}') response = client.chat.completions.create( request_id=request_id, - model='glm-4.1v-thinking-flash', # Fill in the model name to call + model='glm-4.6v', # Fill in the model name to call messages=[ { 'role': 'user', @@ -53,7 +53,7 @@ def test_completions_vlm_thinking_stream(logging_conf): print(f'request_id:{request_id}') response = client.chat.completions.create( request_id=request_id, - model='glm-4.1v-thinking-flash', # Fill in the model name to call + model='glm-4.6v', # Fill in the model name to call messages=[ { 'role': 'user',