Qwen Thinking: 모델이 단계별로 추론하게 하기
Qwen Thinking: 모델이 단계별로 추론하게 하기
여러 단계의 수학·디버깅·정책 분석처럼 정밀한 사고가 필요한 작업은, 답을 바로 내기보다 먼저 추론을 거치는 편이 훨씬 정확해요. Qwen의 thinking 모드는 모델이 답변 전에 추론 과정을 생성하게 해요. 하이브리드 모델은 요청마다 켜고 끌 수 있고, thinking 전용 모델은 항상 추론하죠. 이 문서는 thinking을 켜는 법과 깊이를 조절하는 파라미터를 다룹니다.
추론 결과가 어디에 담기나
Thinking(추론) 모델은 답하기 전에 먼저 추론해요. 결과는 API 스타일에 따라 달라집니다.
- Chat Completions / DashScope:
reasoning_content필드 - Responses API:
reasoning_text이벤트
모드는 두 가지예요.
- 하이브리드:
enable_thinking으로 요청마다 추론을 켜고 끌 수 있음 - Thinking 전용: 항상 추론하며 끌 수 없음
thinking 켜기
Chat Completions API 기준 예시예요. 스트리밍으로 reasoning_content(1단계: 추론)와 content(2단계: 답변)를 구분해 출력합니다.
import os
from openai import OpenAI
client = OpenAI(api_key=os.getenv("DASHSCOPE_API_KEY"), base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1")
completion = client.chat.completions.create(
model="qwen3.8-max",
messages=[{"role": "user", "content": "If 3x + 7 = 22, what is x?"}],
extra_body={"enable_thinking": True}, # ← thinking 켜기
stream=True,
)
for chunk in completion:
if not chunk.choices:
continue
delta = chunk.choices[0].delta
if hasattr(delta, "reasoning_content") and delta.reasoning_content:
print(delta.reasoning_content, end="", flush=True) # ← 1단계: 추론
if hasattr(delta, "content") and delta.content:
print(delta.content, end="", flush=True) # ← 2단계: 답변
⚠️ enable_thinking은 OpenAI 표준 파라미터가 아니에요. Python SDK에서는 extra_body로 전달해야 합니다.
Responses API에서는 추론이 response.reasoning_text.delta 이벤트로, 답변은 response.output_text.delta로 도착해요.
추론 깊이 조절하기
토큰 예산 - thinking_budget
thinking_budget으로 추론 토큰 수를 제한해요. 한도에 닿으면 즉시 추론을 멈추고 답변을 냅니다. Qwen3.8 / Qwen3.7 / Qwen3.6 / Qwen3.5 / Qwen3-VL / Qwen3, GLM, Kimi 계열과 Qwen3.8 오픈소스 계열에서 지원돼요. Chat Completions와 DashScope 전용이고, Responses API에서는 지원하지 않아요.
extra_body={"enable_thinking": True, "thinking_budget": 500}
추론 강도 - reasoning_effort
reasoning_effort는 토큰 수 대신 단계(low, medium, xhigh ...)로 추론 강도를 정해요. 모델별 지원값·기본값이 달라요. 예를 들어 qwen3.8-max는 low, medium, xhigh(기본 xhigh)를 지원합니다.
extra_body={"enable_thinking": True, "reasoning_effort": "medium"}
⚠️ qwen3.8-max는 reasoning_effort와 thinking_budget을 동시에 설정하면 오류를 반환해요. 둘 다 설정하지 않으면 모델 기본값을 씁니다.
프롬프트 단위 제어와 멀티턴 보존
enable_thinking: true상태에서/no_think를 붙이면 한 턴만 추론을 건너뛰고,/think가 이를 복원해요. 마지막 지시가 우선합니다.- 기본적으로 모델은 멀티턴에서
messages배열의reasoning_content를 읽지 않아요.preserve_thinking을true로 두면 assistant 메시지의reasoning_content를 다음 입력에 이어붙여 이전 추론을 참고하게 합니다(지원 모델:qwen3.8-max,qwen3.8-flash,qwen3.7-max,qwen3.7-plus,qwen3.7-flash,qwen3.6-max-preview,qwen3.6-plus등).
알아두면 좋은 참고사항
- 일부 모델은 스트리밍이 필수: Qwen3.7 Max/Plus, Qwen3.6 Plus, Qwen3.5 Plus/Flash, Qwen3 Max, Qwen Plus/Flash/Turbo(상용), Qwen3.5 오픈소스는 비스트리밍을 지원하지만, Qwen3 오픈소스와 Qwen3.8 오픈소스 계열(
qwen3.8-2.4t-a95b)은 스트리밍을 요구해요. - latency FAQ:
qwen3.7-plus는 기본적으로 thinking이 켜져 있어 응답이 느리게 느껴질 수 있어요. 측정상 추론 토큰이 전체 출력의 60% 이상을 차지하거든요. 추론이 필요 없으면enable_thinking을false로, 추론을 유지하면서 빨리 봐야 하면 스트리밍을 쓰세요.
더 알아보기
- 첫 추론 호출: Generate text
- 구조화 출력: Structured output
- 스트리밍: Streaming output