Skip to content

사고 기능을 지원하는 모델은 thinking 필드를 반환하여, 자신의 추론 과정을 최종 답변과 분리합니다.

이 기능을 사용해 모델의 추론 단계를 검증하거나, UI에서 모델의 사고 과정을 애니메이션으로 표현하거나, 최종 응답만 필요할 때 추론 과정을 완전히 숨길 수 있습니다.

지원 모델

API 호출에서 사고 기능 활성화하기

채팅 또는 생성 요청에서 think 필드를 설정하세요. 대부분의 모델은 부울 값(true/false) 또는 레벨(low, medium, high, max)을 지원하며, max는 가장 높은 사고 레벨을 요청합니다.

GPT-OSS는 추론 과정 길이를 조정하기 위해 low, medium, high 중 하나를 사용합니다.

message.thinking(채팅 엔드포인트) 또는 thinking(생성 엔드포인트) 필드에는 추론 과정이 포함되며, message.content / response에는 최종 답변이 저장됩니다.

cURL

```shell
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

```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

```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

```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

```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" (필요에 따라 lowmedium 또는 high로 변경하세요.)

참고

지원되는 모델의 경우 CLI와 API에서 기본적으로 사고 기능이 활성화되어 있습니다.