Documentation Index
Fetch the complete documentation index at: https://wb-21fd5541-update-training-api-25.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
/chat/completions エンドポイントを使用してチャットの補完(chat completion)を作成します。このエンドポイントは、メッセージの送信とレスポンスの受信に OpenAI フォーマットを採用しています。
チャットの補完を作成するには、以下を提供してください:
- Inference サービスのベース URL:
https://api.inference.wandb.ai/v1
- W&B APIキー:
<your-api-key>
- オプション: W&B の Teams と Projects:
<your-team>/<your-project>
- 利用可能な Models リストにあるモデル ID
リクエストの例
import openai
client = openai.OpenAI(
# カスタムベース URL は W&B Inference を指します
base_url='https://api.inference.wandb.ai/v1',
# https://wandb.ai/settings で APIキーを作成してください
# 安全のため、環境変数 OPENAI_API_KEY に設定することを検討してください
api_key="<your-api-key>",
# オプション: 使用状況を追跡するための Team と Project
project="<your-team>/<your-project>",
)
# <model-id> を利用可能なモデルリストの任意のモデル ID に置き換えてください
response = client.chat.completions.create(
model="<model-id>",
messages=[
{"role": "system", "content": "<your-system-prompt>"},
{"role": "user", "content": "<your-prompt>"}
],
)
print(response.choices[0].message.content)
curl https://api.inference.wandb.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <your-api-key>" \
-H "OpenAI-Project: <your-team>/<your-project>" \
-d '{
"model": "<model-id>",
"messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": "Tell me a joke." }
]
}'
レスポンス形式
API は OpenAI 互換の形式でレスポンスを返します:
{
"id": "chatcmpl-...",
"object": "chat.completion",
"created": 1234567890,
"model": "meta-llama/Llama-3.1-8B-Instruct",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Here's a joke for you..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 50,
"total_tokens": 75
}
}