メインコンテンツまでスキップ

推論モデル(Reasoning)

複雑な数学・コーディング・論理問題には、思考過程を伴う推論モデルが有効です。

  • DeepSeek: deepseek-reasonerdeepseek-v4-pro の別名)。思考内容は reasoning_content に入ります。
  • Qwen: thinking パラメータで思考モードを有効化できます(対応モデルのみ)。
import os
from openai import OpenAI

client = OpenAI(
api_key=os.environ["LYKURO_API_KEY"],
base_url="https://api.lykuro.ai/deepseek/v1",
)

resp = client.chat.completions.create(
model="deepseek-reasoner",
messages=[{"role": "user", "content": "1から100までの素数はいくつ?数えて。"}],
)

msg = resp.choices[0].message
# 思考過程(モデルが対応している場合)
reasoning = getattr(msg, "reasoning_content", None)
if reasoning:
print("=== 思考過程 ===")
print(reasoning)
print("=== 回答 ===")
print(msg.content)

Qwen の thinking モード

curl https://api.lykuro.ai/alibaba/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $LYKURO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3-max",
"messages": [{"role": "user", "content": "難しい論理パズルを解いて。"}],
"thinking": {"type": "enabled", "budget_tokens": 5000}
}'

:::warning コストに注意 推論モデルは思考トークンも出力トークンとして課金されます。 簡単なタスクには deepseek-chat / qwen-turbo など通常モデルの方が高速・低コストです。 :::