Skip to content

Commit 60bfed1

Browse files
authored
Merge pull request #239 from ollama/drifkin/thinking-levels
add support for thinking levels
2 parents 45d2e01 + c84c15b commit 60bfed1

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ ollama.chat(request)
6666
- `tool_name` `<string>`: (Optional) Add the name of the tool that was executed to inform the model of the result
6767
- `format` `<string>`: (Optional) Set the expected format of the response (`json`).
6868
- `stream` `<boolean>`: (Optional) When true an `AsyncGenerator` is returned.
69-
- `think` `<boolean>`: (Optional) When true, the model will think about the response before responding. Requires thinking support from the model.
69+
- `think` `<boolean | "high" | "medium" | "low">`: (Optional) Enable model thinking. Use `true`/`false` or specify a level. Requires model support.
7070
- `keep_alive` `<string | number>`: (Optional) How long to keep the model loaded. A number (seconds) or a string with a duration unit suffix ("300ms", "1.5h", "2h45m", etc.)
7171
- `tools` `<Tool[]>`: (Optional) A list of tool calls the model may make.
7272
- `options` `<Options>`: (Optional) Options to configure the runtime.
@@ -89,7 +89,7 @@ ollama.generate(request)
8989
- `images` `<Uint8Array[] | string[]>`: (Optional) Images to be included, either as Uint8Array or base64 encoded strings.
9090
- `format` `<string>`: (Optional) Set the expected format of the response (`json`).
9191
- `stream` `<boolean>`: (Optional) When true an `AsyncGenerator` is returned.
92-
- `think` `<boolean>`: (Optional) When true, the model will think about the response before responding. Requires thinking support from the model.
92+
- `think` `<boolean | "high" | "medium" | "low">`: (Optional) Enable model thinking. Use `true`/`false` or specify a level. Requires model support.
9393
- `keep_alive` `<string | number>`: (Optional) How long to keep the model loaded. A number (seconds) or a string with a duration unit suffix ("300ms", "1.5h", "2h45m", etc.)
9494
- `options` `<Options>`: (Optional) Options to configure the runtime.
9595
- Returns: `<GenerateResponse>`

examples/thinking/thinking-levels.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import ollama from 'ollama'
2+
3+
function printHeading(text: string) {
4+
console.log(text)
5+
console.log('='.repeat(text.length))
6+
}
7+
8+
async function main() {
9+
const messages = [{ role: 'user', content: 'What is 10 + 23?' }]
10+
11+
// gpt-oss supports 'low', 'medium', 'high'
12+
const thinkingLevels = ['low', 'medium', 'high'] as const
13+
14+
for (const [index, level] of thinkingLevels.entries()) {
15+
const response = await ollama.chat({
16+
model: 'gpt-oss:20b',
17+
messages,
18+
think: level,
19+
})
20+
21+
printHeading(`Thinking (${level})`)
22+
console.log(response.message.thinking ?? '')
23+
console.log('\n')
24+
25+
printHeading('Response')
26+
console.log(response.message.content)
27+
console.log('\n')
28+
29+
if (index < thinkingLevels.length - 1) {
30+
console.log('-'.repeat(20))
31+
console.log('\n')
32+
}
33+
}
34+
}
35+
36+
main()

src/interfaces.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export interface GenerateRequest {
5656
format?: string | object
5757
images?: Uint8Array[] | string[]
5858
keep_alive?: string | number // a number (seconds) or a string with a duration unit suffix ("300ms", "1.5h", "2h45m", etc)
59-
think?: boolean
59+
think?: boolean | 'high' | 'medium' | 'low'
6060

6161
options?: Partial<Options>
6262
}
@@ -109,7 +109,7 @@ export interface ChatRequest {
109109
format?: string | object
110110
keep_alive?: string | number // a number (seconds) or a string with a duration unit suffix ("300ms", "1.5h", "2h45m", etc)
111111
tools?: Tool[]
112-
think?: boolean
112+
think?: boolean | 'high' | 'medium' | 'low'
113113

114114
options?: Partial<Options>
115115
}

0 commit comments

Comments
 (0)