> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wandb.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# トレーニング済みモデルを使用する

> トレーニングしたモデルに推論リクエストを送信する

Serverless RL でモデルをトレーニングすると、そのモデルは自動的に推論に利用できるようになります。このページでは、トレーニング済みモデルのエンドポイントを組み立て、そのエンドポイントに推論リクエストを送信する方法を説明します。このエンドポイントを使用して、モデルをアプリケーションや評価ワークフローに統合できます。

トレーニング済みモデルにリクエストを送信するには、以下が必要です。

* [W\&B APIキー](https://wandb.ai/settings)
* [Serverless Training API](/ja/serverless-training/api-reference) のベース URL `https://api.training.wandb.ai/v1/`
* モデルのエンドポイント

モデルのエンドポイントは、次のスキーマに従います。

```text theme={null}
wandb-artifact:///[ENTITY]/[PROJECT]/[MODEL-NAME]:[STEP]
```

このスキーマは、次の要素で構成されます。

* W\&B エンティティ (チーム) 名
* モデルに関連付けられた project 名
* 学習済みモデルの名
* デプロイするモデルのトレーニング ステップ。通常、これは評価でモデルのパフォーマンスが最も高かったステップです。

たとえば、W\&B チーム名が `email-specialists`、project 名が `mail-search`、学習済みモデル名が `agent-001` で、ステップ 25 でデプロイしたい場合、エンドポイントは次のようになります。

```text theme={null}
wandb-artifact:///email-specialists/mail-search/agent-001:step25
```

エンドポイントを取得したら、通常の推論ワークフローに統合できます。以下の例では、cURL リクエストまたは [Python OpenAI SDK](https://github.com/openai/openai-python) を使用して、学習済みモデルに推論リクエストを送信する方法を示します。ご利用の環境に合った例を選択してください。

<div id="curl">
  ## cURL
</div>

```bash theme={null}
curl https://api.training.wandb.ai/v1/chat/completions \
    -H "Authorization: Bearer $WANDB_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
            "model": "wandb-artifact://[ENTITY]/[PROJECT]/[MODEL-NAME]:[STEP]",
            "messages": [
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": "Summarize our training run."}
            ],
            "temperature": 0.7,
            "top_p": 0.95
        }'
```

<div id="openai-sdk">
  ## OpenAI SDK
</div>

```python theme={null}
from openai import OpenAI

WANDB_API_KEY = "your-wandb-api-key"
ENTITY = "my-entity"
PROJECT = "my-project"

client = OpenAI(
    base_url="https://api.training.wandb.ai/v1",
    api_key=WANDB_API_KEY
)

response = client.chat.completions.create(
    model=f"wandb-artifact:///{ENTITY}/{PROJECT}/my-model:step100",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Summarize our training run."},
    ],
    temperature=0.7,
    top_p=0.95,
)

print(response.choices[0].message.content)
```
