Kimi
复制成功!
立即体验加入对比
文本生成推理
概述
文本生成推理
kimi-k2-thinking模型是月之暗面提供的具有通用 Agentic能力和推理能力的思考模型,它擅长深度推理,并可通过多步工具调用,帮助解决各类难题。
输入
文本
输出
文本
功能
定价
- 输入¥4/M tokens
- 输出¥16/M tokens
- 输入(缓存命中)¥0.8/M tokens
速率限制与上下文
- 最大输入229.37K
- 最大输出16.38K
- RPM每分钟请求数500
- TPM每分钟 Token 数1M
- 上下文262.14K
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="kimi-k2-thinking",
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)