सोचने की क्षमता वाले मॉडल एक thinking फ़ील्ड उत्पन्न करते हैं जो उनके तर्क के ट्रेस को अंतिम उत्तर से अलग करता है।
इस क्षमता का उपयोग मॉडल के चरणों का ऑडिट करने, UI में मॉडल के थिंकिंग को एनिमेट करने, या तब ट्रेस को पूरी तरह से छिपाने के लिए करें जब आपको केवल अंतिम प्रतिक्रिया की आवश्यकता हो।
समर्थित मॉडल
- Qwen 3
- GPT-OSS (उपयोग करें
thinkस्तर:low,medium,high— ट्रेस को पूरी तरह से अक्षम नहीं किया जा सकता) - DeepSeek-v3.1
- DeepSeek R1
- थिंकिंग मॉडल के तहत नवीनतम जोड़े देखें
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 चंक का पता लगाकर एक "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"(आवश्यकतानुसारlowकोmediumयाhighसे बदलें)。
नोट
समर्थित मॉडल के लिए CLI और API में थिंकिंग डिफ़ॉल्ट रूप से सक्षम होती है।