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

# 推論モデル

export const ReasoningModels = () => {
  if (typeof document === "undefined") {
    return null;
  } else {
    let attempts = 0;
    const maxAttempts = 50;
    const INIT_DISPLAY_COUNT = 3;
    const interval = setInterval(() => {
      const clientComponent = document.getElementById("reasoning-models");
      if (clientComponent && window.novitaRemoteData.llmModels.status === 'loaded') {
        const modelList = window.novitaRemoteData.llmModels.data.filter(model => {
          return (model.features || []).includes('reasoning');
        });
        let displayModels = modelList.slice(0, INIT_DISPLAY_COUNT).map(model => {
          return `<li><span class="model-id-item">${model.id}</span></li>`;
        }).join('');
        let showMoreButton = '';
        if (modelList.length > INIT_DISPLAY_COUNT) {
          showMoreButton = `<button id="show-more-reasoning-model-btn" style="margin-left: 32px; color: rgb(40 116 255)">View More</button>`;
        }
        clientComponent.innerHTML = `
          <ul>${displayModels}</ul>
          ${showMoreButton}
        `;
        document.getElementById('show-more-reasoning-model-btn')?.addEventListener('click', () => {
          clientComponent.innerHTML = `
            <ul>${modelList.map(model => {
            return `<li><span class="model-id-item">${model.id}</span></li>`;
          }).join('')}</ul>
          `;
        });
        clearInterval(interval);
      }
      attempts++;
      if (attempts >= maxAttempts) {
        clearInterval(interval);
      }
    }, 200);
    return <div id="reasoning-models"></div>;
  }
};

## 概要

推論モデルは、複雑な問題解決タスクに最適化された高度な言語モデルです。詳細な推論ステップ（chain-of-thought）を生成することで、分析的なシナリオにおける回答の精度を向上させます。

### 典型的なユースケース

* **複雑な問題解決**: 数学や科学的推論など、段階的なロジックを必要とするタスクに適しています。
* **意思決定支援システム**: 詳細な推論プロセスを提供することで、結論に至るロジックの説明に役立ちます。
* **教育とトレーニング**: 導出プロセスを明確に提示することで、学習者が複雑な概念を理解するのを支援します。

***

## インストールとセットアップ

推論モデルを使用する前に、最新の OpenAI SDK がインストールされていることを確認してください。

```bash theme={"system"}
pip install -U openai
```

***

## API の使用方法

推論モデルを呼び出すには、`/chat/completions` エンドポイントを使用します。

### リクエストパラメータ

* `max_tokens`: モデルが返すことのできるトークンの最大数を設定します。
* `temperature`: 創造性と論理性のバランスを取るため、0.5 から 0.7 の間を推奨します（推奨値: 0.6）。
* `top_p`: 推奨値は 0.95 です。

***

### サンプルコード

#### ストリーミングレスポンス

```python theme={"system"}
from openai import OpenAI

client = OpenAI(api_key="YOUR_API_KEY", base_url="https://api.novita.ai/openai")
messages = [
    {"role": "user", "content": "Explain Newton's Second Law."}
]

response = client.chat.completions.create(
    model="deepseek/deepseek-r1",
    messages=messages,
    stream=True,
    max_tokens=4096
)

content = ""
reasoning_content = ""
for chunk in response:
    if chunk.choices[0].delta.content:
        content += chunk.choices[0].delta.content
    if chunk.choices[0].delta.reasoning_content:
        reasoning_content += chunk.choices[0].delta.reasoning_content

print("Final Answer:", content)
print("Reasoning Steps:", reasoning_content)
```

#### 非ストリーミングレスポンス

```python theme={"system"}
response = client.chat.completions.create(
    model="deepseek/deepseek-r1",
    messages=[
        {"role": "user", "content": "What is the greenhouse effect? How can it be mitigated?"}
    ],
    stream=False,
    max_tokens=4096
)

content = response.choices[0].message.content
reasoning_content = response.choices[0].message.reasoning_content

print("Final Answer:", content)
print("Reasoning Steps:", reasoning_content)
```

***

## コンテキスト管理

推論出力は、次の対話ラウンドに自動的に引き継がれません。メッセージ履歴を手動で維持する必要があります。

```python theme={"system"}
messages.append({"role": "assistant", "content": content})
messages.append({"role": "user", "content": "Please continue explaining the solution."})
```

***

## サポートされているモデル

現在、Novita プラットフォームでは以下の推論モデルがサポートされています。

<ReasoningModels />

***

## 料金

* 料金は、入力と出力の両方のトークン数に基づいて計算されます。
* 具体的な課金ルールとトークン換算の詳細については、各モデルの料金ページを参照してください。

***

## 注意事項とベストプラクティス

* 推論に関する指示を `system` メッセージに含めることは避けてください。代わりに、`user` メッセージで意図を明確にしてください。
* 数学タスクでは、たとえば「ステップごとに推論し、最終回答を提示してください」のように、モデルへ明確に指示してください。
* モデルが推論ステップを省略するのを防ぐため、最終回答の前に改行を入れるよう依頼することを検討してください。
