5. チャット補完(Chat Completions)#
POST /v1/chat/completions — 最も中心的なエンドポイントで、OpenAI Chat Completions と互換性があります。
リクエストパラメータ#
| パラメータ | 型 | 必須 | 説明 |
|---|---|---|---|
model | string | はい | モデル名。例:gpt-4o、claude-3-5-sonnet-20241022 |
messages | array | はい | メッセージ配列。各要素は role(system/user/assistant)と content を含みます |
stream | boolean | いいえ | ストリーミングで返すかどうか。デフォルトは false |
temperature | number | いいえ | サンプリング温度。高いほどランダムになります |
max_tokens | integer | いいえ | 生成する最大トークン数 |
その他の OpenAI 標準パラメータ(
top_p、presence_penaltyなど)は、上流のモデルにそのまま渡されます。
非ストリーミングリクエスト#
cURL
curl http://183.240.79.21:52099/v1/chat/completions \
-H "Authorization: Bearer sk-你的YiTuoToken-Key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [
{ "role": "system", "content": "你是一个乐于助人的助手。" },
{ "role": "user", "content": "你好,请介绍一下你自己" }
],
"temperature": 0.7
}'
ストリーミングリクエスト(SSE)#
リクエストボディに "stream": true を追加すると、レスポンスは Server-Sent Events としてチャンク単位で返ります。各チャンクは chat.completion.chunk で、最後は data: [DONE] で終了します。
cURL
curl http://183.240.79.21:52099/v1/chat/completions \
-H "Authorization: Bearer sk-你的YiTuoToken-Key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [{ "role": "user", "content": "写一首关于秋天的短诗" }],
"stream": true
}'
マルチターン会話#
履歴メッセージを messages 配列に順に含めるだけで、コンテキストを維持できます:
JSON
{
"model": "gpt-4o",
"messages": [
{ "role": "user", "content": "推荐一部科幻电影" },
{ "role": "assistant", "content": "推荐《星际穿越》。" },
{ "role": "user", "content": "它的导演是谁?" }
]
}