씽킹(Thinking)

씽킹(Thinking)

추론이 가능한 모델은 최종 답과 분리된 thinking 필드를 내보냅니다. 이 필드에는 모델이 답을 만들기까지 거친 추론 과정이 담겨 있어요. 모델의 단계를 감사하거나, UI에서 모델이 '생각'하는 모습을 애니메이션으로 보여주거나, 최종 답만 필요할 때는 추론 과정을 완전히 숨기는 용도로 쓸 수 있습니다.

출처: 공식문서

지원 모델

API 호출에서 씽킹 켜기

채팅이나 생성 요청에 think 필드를 설정하면 됩니다. 대부분의 모델은 boolean(true/false)이나 단계(low, medium, high, max)를 받아들이며, max는 가장 높은 씽킹 단계를 요청합니다.

GPT-OSS는 그 대신 low, medium, high 중 하나를 받아 추론 과정의 길이를 조절합니다.

채팅 엔드포인트의 message.thinking(또는 생성 엔드포인트의 thinking) 필드에 추론 과정이 들어 있고, message.content / response에 최종 답이 들어 있습니다.

cURL:

curl http://localhost:11434/api/chat -d '{
  "model": "qwen3",
  "messages": [{
    "role": "user",
    "content": "How many letter r are in strawberry?"
  }],
  "think": true,
  "stream": false
}'

Python:

from ollama import chat

response = chat(
  model='qwen3',
  messages=[{'role': 'user', 'content': 'How many letter r are in strawberry?'}],
  think=True,
  stream=False,
)

print('Thinking:\n', response.message.thinking)
print('Answer:\n', response.message.content)

JavaScript:

import ollama from 'ollama'

const response = await ollama.chat({
  model: 'deepseek-r1',
  messages: [{ role: 'user', content: 'How many letter r are in strawberry?' }],
  think: true,
  stream: false,
})

console.log('Thinking:\n', response.message.thinking)
console.log('Answer:\n', response.message.content)

GPT-OSS는 think"low", "medium", "high" 중 하나로 설정해야 합니다. 그 모델에 true/false를 넘기면 무시됩니다.

추론 과정 스트리밍

씽킹 스트리밍은 답 토큰보다 먼저 추론 토큰을 내보냅니다. 첫 thinking 청크를 감지해 '생각 중' 섹션을 그리고, message.content가 도착하기 시작하면 최종 답으로 전환하면 됩니다.

Python 예시:

from ollama import chat

stream = chat(
  model='qwen3',
  messages=[{'role': 'user', 'content': 'What is 17 × 23?'}],
  think=True,
  stream=True,
)

in_thinking = False

for chunk in stream:
  if chunk.message.thinking and not in_thinking:
    in_thinking = True
    print('Thinking:\n', end='')

  if chunk.message.thinking:
    print(chunk.message.thinking, end='')
  elif chunk.message.content:
    if in_thinking:
      print('\n\nAnswer:\n', end='')
      in_thinking = False
    print(chunk.message.content, end='')

JavaScript 예시:

import ollama from 'ollama'

async function main() {
  const stream = await ollama.chat({
    model: 'qwen3',
    messages: [{ role: 'user', content: 'What is 17 × 23?' }],
    think: true,
    stream: true,
  })

  let inThinking = false

  for await (const chunk of stream) {
    if (chunk.message.thinking && !inThinking) {
      inThinking = true
      process.stdout.write('Thinking:\n')
    }

    if (chunk.message.thinking) {
      process.stdout.write(chunk.message.thinking)
    } else if (chunk.message.content) {
      if (inThinking) {
        process.stdout.write('\n\nAnswer:\n')
        inThinking = false
      }
      process.stdout.write(chunk.message.content)
    }
  }
}

main()

CLI 빠른 참조

  • 단일 실행에서 씽킹 켜기: ollama run deepseek-r1 --think "Where should I visit in Lisbon?"
  • 씽킹 끄기: ollama run deepseek-r1 --think=false "Summarize this article"
  • 씽킹 모델을 쓰되 추론 과정은 숨기기: ollama run deepseek-r1 --hidethinking "Is 9.9 bigger or 9.11?"
  • 대화형 세션에서는 /set think 또는 /set nothink로 토글합니다.
  • GPT-OSS는 단계만 받아요: ollama run gpt-oss --think=low "Draft a headline" (low 대신 medium이나 high 사용)

지원 모델에서는 CLI와 API 모두 씽킹이 기본적으로 켜져 있습니다.

더 알아보기 (Learn more)

  • Streaming — 씽킹 필드와 함께 청크 처리하기