生成对话式 AI 响应。
POST https://api.atdak.com/v1/chat/completions
{
"model": "atdak-gpt-4",
"messages": [
{"role": "system", "content": "你是一个有帮助的助手"},
{"role": "user", "content": "你好"}
],
"temperature": 0.7,
"max_tokens": 2048,
"stream": false
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | 是 | 模型名称 |
| messages | array | 是 | 对话消息列表 |
| temperature | number | 否 | 采样温度,0-2,默认 1 |
| max_tokens | integer | 否 | 最大生成 token 数 |
| stream | boolean | 否 | 是否流式输出 |
| top_p | number | 否 | 核采样参数 |
| frequency_penalty | number | 否 | 频率惩罚,-2 到 2 |
| presence_penalty | number | 否 | 存在惩罚,-2 到 2 |
| 字段 | 类型 | 说明 |
|---|---|---|
| role | string | 角色:system, user, assistant |
| content | string | 消息内容 |
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1701234567,
"model": "atdak-gpt-4",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好!有什么可以帮助你的吗?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 15,
"completion_tokens": 12,
"total_tokens": 27
}
}
| 模型 | 上下文长度 | 说明 |
|---|---|---|
| atdak-gpt-4 | 128K | 最强综合能力 |
| atdak-gpt-4-mini | 128K | 高性价比 |
| atdak-claude-3 | 200K | 超长上下文 |
| atdak-llama-70b | 32K | 开源模型 |
设置 stream: true 开启流式输出:
curl https://api.atdak.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "atdak-gpt-4",
"messages": [{"role": "user", "content": "你好"}],
"stream": true
}'
流式响应格式:
data: {"id":"chatcmpl-abc","choices":[{"delta":{"content":"你"}}]}
data: {"id":"chatcmpl-abc","choices":[{"delta":{"content":"好"}}]}
data: [DONE]
from atdak import AtdakClient
client = AtdakClient()
# 普通调用
response = client.chat.completions.create(
model="atdak-gpt-4",
messages=[
{"role": "user", "content": "写一首关于春天的诗"}
]
)
print(response.choices[0].message.content)
# 流式调用
stream = client.chat.completions.create(
model="atdak-gpt-4",
messages=[{"role": "user", "content": "你好"}],
stream=True
)
for chunk in stream:
print(chunk.choices[0].delta.content, end="")