展示在 Claude Code 中集成智谱 GLM 4.5 模型的方法,拓展 AI 编程工具的模型选择范围。
最大输出 Token 数
我们最强大的推理模型,拥有 3550 亿参数
高性价比、轻量、性能强劲
高性能、推理能力强、响应速度极快
轻量、性能强劲、响应速度极快
免费、性能强劲,尤其适合推理、编程与 Agent 场景
参数效率更高
成本低、速度快
真实场景评测
智能问答
复杂文本翻译
支持 Python、JavaScript 和 Java 等主流编程语言。
能够根据自然语言指令,生成结构清晰、可扩展的高质量代码。
聚焦真实开发需求,避免输出模板化或泛泛而谈的内容。
自动将复杂任务拆解为清晰、可执行的分步计划。
灵活调用开发工具,在一站式工作流中完成编码、调试和验证。
根据实时反馈动态调整策略,快速适应任务变化,并持续优化执行路径。
按主题扩展内容:根据单个标题或核心概念,生成多页 PPT 内容。
组织逻辑结构:自动将内容划分为引言、正文和结论等模块,形成条理清晰的语义脉络。
幻灯片布局建议:配合模板系统,为生成的内容推荐最合适的演示样式。
深度自然语言理解——准确理解自然语言指令、提取关键意图,并将其转换为可执行任务。
复杂多轮推理——支持多步逻辑推理链,能够高效处理包含跨步骤依赖和多个变量的复合问题。
领域知识融合——将特定领域的专业知识与上下文信息相结合,提升推理准确性和输出稳定性。
复杂长句翻译:保持语义连贯和结构准确,尤其适合政策与学术材料。
风格保留与适配:翻译过程中保留原文语气,或适配目标语言的常用表达风格。
支持低资源语言与非正式语境:初步覆盖 26 种语言,具备翻译社交文本和非正式文本的能力。
根据给定的主题、人物或世界观,生成叙事脉络清晰、内容连贯的文学文本。
结合受众画像和产品特征,创作富有情感感染力的文案。
支持创作符合抖音、小红书等平台特点的短视频与新媒体脚本,并融合情绪控制和叙事节奏。
角色扮演对话系统:在多轮对话中保持指定角色的语气和行为一致。
情感丰富的文案创作:提供温暖、易引发共鸣的表达,适合打造“人格化”品牌或陪伴型用户产品。
虚拟人设内容创作:支持生成符合虚拟主播或角色 IP 设定的内容,包括社交动态和粉丝互动。
API 文档:了解如何调用 API。
简单任务(无需思考):对于不需要复杂推理的直接请求,例如事实检索或分类,无需启用思考。示例包括:Z.AI 是什么时候成立的?把“I love you”翻译成中文。
Z.AI 是什么时候成立的?
把“I love you”翻译成中文。
中等难度任务(默认需要一定思考):许多常见请求需要分步处理或更深入的理解。GLM-4.5 系列可以灵活运用思考能力,处理以下任务:尽管土星体积更大,为什么木星的卫星却比土星更多?比较从北京到上海乘飞机和乘高铁各自的优缺点。
尽管土星体积更大,为什么木星的卫星却比土星更多?
比较从北京到上海乘飞机和乘高铁各自的优缺点。
详细解释 Mixture-of-Experts(MoE)模型中的不同专家如何协同工作。
根据最近一周上证指数的波动和当前政治信息,我是否应该投资股票指数 ETF?为什么?
curl -X POST "https://api.z.ai/api/paas/v4/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key" \
-d '{
"model": "glm-4.5",
"messages": [
{
"role": "user",
"content": "As a marketing expert, please create an attractive slogan for my product."
},
{
"role": "assistant",
"content": "Sure, to craft a compelling slogan, please tell me more about your product."
},
{
"role": "user",
"content": "Z.AI Open Platform"
}
],
"thinking": {
"type": "enabled"
},
"max_tokens": 4096,
"temperature": 0.6
}'
curl -X POST "https://api.z.ai/api/paas/v4/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key" \
-d '{
"model": "glm-4.5",
"messages": [
{
"role": "user",
"content": "As a marketing expert, please create an attractive slogan for my product."
},
{
"role": "assistant",
"content": "Sure, to craft a compelling slogan, please tell me more about your product."
},
{
"role": "user",
"content": "Z.AI Open Platform"
}
],
"thinking": {
"type": "enabled"
},
"stream": true,
"max_tokens": 4096,
"temperature": 0.6
}'
# Install latest version
pip install zai-sdk
# Or specify version
pip install zai-sdk==0.2.3
import zai
print(zai.__version__)
from zai import ZaiClient
client = ZaiClient(api_key="your-api-key") # Your API Key
response = client.chat.completions.create(
model="glm-4.5",
messages=[
{"role": "user", "content": "As a marketing expert, please create an attractive slogan for my product."},
{"role": "assistant", "content": "Sure, to craft a compelling slogan, please tell me more about your product."},
{"role": "user", "content": "Z.AI Open Platform"}
],
thinking={
"type": "enabled",
},
max_tokens=4096,
temperature=0.6
)
# Get complete response
print(response.choices[0].message)
from zai import ZaiClient
client = ZaiClient(api_key="your-api-key") # Your API Key
response = client.chat.completions.create(
model="glm-4.5",
messages=[
{"role": "user", "content": "As a marketing expert, please create an attractive slogan for my product."},
{"role": "assistant", "content": "Sure, to craft a compelling slogan, please tell me more about your product."},
{"role": "user", "content": "Z.AI Open Platform"}
],
thinking={
"type": "enabled", # Optional: "disabled" or "enabled", default is "enabled"
},
stream=True,
max_tokens=4096,
temperature=0.6
)
# Stream response
for chunk in response:
if chunk.choices[0].delta.reasoning_content:
print(chunk.choices[0].delta.reasoning_content, end='', flush=True)
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end='', flush=True)
<dependency>
<groupId>ai.z.openapi</groupId>
<artifactId>zai-sdk</artifactId>
<version>0.3.5</version>
</dependency>
implementation 'ai.z.openapi:zai-sdk:0.3.5'
import ai.z.openapi.ZaiClient;
import ai.z.openapi.service.model.ChatCompletionCreateParams;
import ai.z.openapi.service.model.ChatCompletionResponse;
import ai.z.openapi.service.model.ChatMessage;
import ai.z.openapi.service.model.ChatMessageRole;
import ai.z.openapi.service.model.ChatThinking;
import java.util.Arrays;
public class BasicChat {
public static void main(String[] args) {
// Initialize client
ZaiClient client = ZaiClient.builder().ofZAI()
.apiKey("your-api-key")
.build();
// Create chat completion request
ChatCompletionCreateParams request = ChatCompletionCreateParams.builder()
.model("glm-4.5")
.messages(Arrays.asList(
ChatMessage.builder()
.role(ChatMessageRole.USER.value())
.content("As a marketing expert, please create an attractive slogan for my product.")
.build(),
ChatMessage.builder()
.role(ChatMessageRole.ASSISTANT.value())
.content("Sure, to craft a compelling slogan, please tell me more about your product.")
.build(),
ChatMessage.builder()
.role(ChatMessageRole.USER.value())
.content("Z.AI Open Platform")
.build()
))
.thinking(ChatThinking.builder().type("enabled").build())
.maxTokens(4096)
.temperature(0.6f)
.build();
// Send request
ChatCompletionResponse response = client.chat().createChatCompletion(request);
// Get response
if (response.isSuccess()) {
Object reply = response.getData().getChoices().get(0).getMessage();
System.out.println("AI Response: " + reply);
} else {
System.err.println("Error: " + response.getMsg());
}
}
}
import ai.z.openapi.ZaiClient;
import ai.z.openapi.service.model.ChatCompletionCreateParams;
import ai.z.openapi.service.model.ChatCompletionResponse;
import ai.z.openapi.service.model.ChatMessage;
import ai.z.openapi.service.model.ChatMessageRole;
import ai.z.openapi.service.model.ChatThinking;
import ai.z.openapi.service.model.Delta;
import java.util.Arrays;
public class StreamingChat {
public static void main(String[] args) {
// Initialize client
ZaiClient client = ZaiClient.builder().ofZAI()
.apiKey("your-api-key")
.build();
// Create streaming chat completion request
ChatCompletionCreateParams request = ChatCompletionCreateParams.builder()
.model("glm-4.5")
.messages(Arrays.asList(
ChatMessage.builder()
.role(ChatMessageRole.USER.value())
.content("As a marketing expert, please create an attractive slogan for my product.")
.build(),
ChatMessage.builder()
.role(ChatMessageRole.ASSISTANT.value())
.content("Sure, to craft a compelling slogan, please tell me more about your product.")
.build(),
ChatMessage.builder()
.role(ChatMessageRole.USER.value())
.content("Z.AI Open Platform")
.build()
))
.thinking(ChatThinking.builder().type("enabled").build())
.stream(true) // Enable streaming output
.maxTokens(4096)
.temperature(0.6f)
.build();
ChatCompletionResponse response = client.chat().createChatCompletion(request);
if (response.isSuccess()) {
response.getFlowable().subscribe(
// Process streaming message data
data -> {
if (data.getChoices() != null && !data.getChoices().isEmpty()) {
Delta delta = data.getChoices().get(0).getDelta();
System.out.print(delta + "\n");
}},
// Process streaming response error
error -> System.err.println("\nStream error: " + error.getMessage()),
// Process streaming response completion event
() -> System.out.println("\nStreaming response completed")
);
} else {
System.err.println("Error: " + response.getMsg());
}
}
}
# Install or upgrade to latest version
pip install --upgrade 'openai>=1.0'
python -c "import openai; print(openai.__version__)"
from openai import OpenAI
client = OpenAI(
api_key="your-Z.AI-api-key",
base_url="https://api.z.ai/api/paas/v4/"
)
completion = client.chat.completions.create(
model="glm-4.5",
messages=[
{"role": "system", "content": "You are a smart and creative novelist"},
{"role": "user", "content": "Please write a short fairy tale story as a fairy tale master"}
]
)
print(completion.choices[0].message.content)
这个页面对你有帮助吗?