GLM

复制成功!
立即体验加入对比
文本生成推理

概述

文本生成推理

GLM-5.2是智谱AI推出的面向长程任务(Long Horizon Task)设计的最新旗舰模型,支持1M超长上下文。拥有强大逻辑推理、长文本理解与代码生成能力、兼顾性能与推理效率;在多任务基准中表现优异,适用于智能交互、企业应用、开发辅助等场景。

输入

文本

输出

文本

功能

前缀补全

函数调用

缓存

结构化输出

批量任务

联网搜索

微调

定价

  • 输入
    ¥8/M tokens
  • 输出
    ¥28/M tokens
  • 输入(缓存命中)
    ¥2/M tokens

上下文

上下文
1.04M
最大输入
1.04M
最大输出
131.07K

速率限制

  • RPM每分钟请求数
    500
  • TPM每分钟 Token 数
    2M

API 参考

获取 API Key
复制成功!
12345678910111213141516171819202122232425262728293031323334353637
import os
from dashscope import Generation
import dashscope
dashscope.base_http_api_url = "https://dashscope.aliyuncs.com/api/v1/"

messages = [{"role": "user", "content": "你是谁?"}]

completion = Generation.call(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    model="glm-5.2",
    messages=messages,
    result_format="message", 
    stream=True,
    incremental_output=True, 
)

is_answering = False

print("=" * 20 + "思考过程" + "=" * 20)

for chunk in completion:
    if (
        chunk.output.choices[0].message.content == ""
        and chunk.output.choices[0].message.reasoning_content == ""
    ):
        pass
    else:
        if (
            chunk.output.choices[0].message.reasoning_content != ""
            and chunk.output.choices[0].message.content == ""
        ):
            print(chunk.output.choices[0].message.reasoning_content, end="", flush=True)
        elif chunk.output.choices[0].message.content != "":
            if not is_answering:
                print("\n" + "=" * 20 + "完整回复" + "=" * 20)
                is_answering = True
            print(chunk.output.choices[0].message.content, end="", flush=True)