Qwen3 モデルは推論時に「思考プロセス」を出力する Thinking モードを備えている。
- デフォルト: 有効(Thinking モード)
- 出力形式: レスポンスに
<think>...</think>タグで思考プロセスが含まれる - 対応バックエンド: TensorRT-LLM, vLLM(Qwen3 系モデル)
デフォルトの動作。モデルは回答前に思考プロセスを出力する。
curl -X POST http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "nvidia/Qwen3-30B-A3B-FP4",
"messages": [{"role": "user", "content": "What is 2+2?"}],
"max_tokens": 256
}'<think>
The user is asking for a simple arithmetic calculation.
2 + 2 = 4
</think>
The answer is 4.
システムプロンプトに /no_think を追加すると、思考プロセスを出力せずに回答のみを返す。
curl -X POST http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "nvidia/Qwen3-30B-A3B-FP4",
"messages": [
{"role": "system", "content": "/no_think"},
{"role": "user", "content": "What is 2+2?"}
],
"max_tokens": 128
}'The answer is 4.
Thinking モード使用時は、クライアント側でレスポンスから <think>...</think> タグを除去する必要がある。
import re
def remove_thinking(response: str) -> str:
"""Remove <think>...</think> tags from response."""
return re.sub(r'<think>.*?</think>\s*', '', response, flags=re.DOTALL)function removeThinking(response) {
return response.replace(/<think>[\s\S]*?<\/think>\s*/g, '');
}- Nemotron:
--reasoning_parser deepseek-r1で思考過程がreasoning_contentフィールドに分離される - Qwen3: Thinking タグの除去はクライアント側で実装が必要