> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-wbdocs-1882.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

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

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

Serverless RL でモデルをトレーニングすると、そのモデルは自動的に推論で使用できるようになります。

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

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

モデルのエンドポイントは、次のスキーマを使用します。

```
wandb-artifact:///<entity>/<project>/<model-name>:<step>
```

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

* W\&B entity (team) の名
* モデルに関連付けられているプロジェクトの名
* トレーニング済みモデルの名
* デプロイしたいモデルのトレーニング step (通常、これはモデルが評価で最も高い性能を示した step です)

たとえば、W\&B の team 名が `email-specialists`、プロジェクト名が `mail-search`、トレーニング済みモデル名が `agent-001` で、step 25 をデプロイしたい場合、エンドポイントは次のようになります。

```
wandb-artifact:///email-specialists/mail-search/agent-001:step25
```

エンドポイントを用意したら、通常の推論ワークフローに組み込めます。以下の例では、cURL リクエストまたは [Python OpenAI SDK](https://github.com/openai/openai-python) を使用して、トレーニング済みモデルに推論リクエストを送信する方法を示します.

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

```shell 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)
```
