Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
d681cd7c
Unverified
Commit
d681cd7c
authored
Oct 09, 2025
by
Patrick Devine
Committed by
GitHub
Oct 09, 2025
Browse files
thinking: allow `"think": false` for non-thinking models (#12555)
parent
47298fce
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
11 deletions
+30
-11
server/routes.go
server/routes.go
+14
-10
server/routes_generate_test.go
server/routes_generate_test.go
+16
-1
No files found.
server/routes.go
View file @
d681cd7c
...
...
@@ -332,14 +332,16 @@ func (s *Server) GenerateHandler(c *gin.Context) {
}
modelCaps
:=
m
.
Capabilities
()
if
req
.
Think
!=
nil
{
if
slices
.
Contains
(
modelCaps
,
model
.
CapabilityThinking
)
{
caps
=
append
(
caps
,
model
.
CapabilityThinking
)
}
else
{
// add thinking if the model supports it
if
slices
.
Contains
(
modelCaps
,
model
.
CapabilityThinking
)
{
caps
=
append
(
caps
,
model
.
CapabilityThinking
)
if
req
.
Think
==
nil
{
req
.
Think
=
&
api
.
ThinkValue
{
Value
:
true
}
}
}
else
{
if
req
.
Think
!=
nil
&&
req
.
Think
.
Bool
()
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
fmt
.
Sprintf
(
"%q does not support thinking"
,
req
.
Model
)})
return
}
}
r
,
m
,
opts
,
err
:=
s
.
scheduleRunner
(
c
.
Request
.
Context
(),
name
.
String
(),
caps
,
req
.
Options
,
req
.
KeepAlive
)
...
...
@@ -1877,14 +1879,16 @@ func (s *Server) ChatHandler(c *gin.Context) {
}
modelCaps
:=
m
.
Capabilities
()
if
req
.
Think
!=
nil
{
if
slices
.
Contains
(
modelCaps
,
model
.
CapabilityThinking
)
{
caps
=
append
(
caps
,
model
.
CapabilityThinking
)
}
else
{
// add thinking if the model supports it
if
slices
.
Contains
(
modelCaps
,
model
.
CapabilityThinking
)
{
caps
=
append
(
caps
,
model
.
CapabilityThinking
)
if
req
.
Think
==
nil
{
req
.
Think
=
&
api
.
ThinkValue
{
Value
:
true
}
}
}
else
{
if
req
.
Think
!=
nil
&&
req
.
Think
.
Bool
()
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
fmt
.
Sprintf
(
"%q does not support thinking"
,
req
.
Model
)})
return
}
}
r
,
m
,
opts
,
err
:=
s
.
scheduleRunner
(
c
.
Request
.
Context
(),
name
.
String
(),
caps
,
req
.
Options
,
req
.
KeepAlive
)
...
...
server/routes_generate_test.go
View file @
d681cd7c
...
...
@@ -158,11 +158,26 @@ func TestGenerateChat(t *testing.T) {
t
.
Errorf
(
"expected status 400, got %d"
,
w
.
Code
)
}
if
diff
:=
cmp
.
Diff
(
w
.
Body
.
String
(),
`{"error":"
registry.ollama.ai/library/test:latest
does not support thinking"}`
);
diff
!=
""
{
if
diff
:=
cmp
.
Diff
(
w
.
Body
.
String
(),
`{"error":"
\"test\"
does not support thinking"}`
);
diff
!=
""
{
t
.
Errorf
(
"mismatch (-got +want):
\n
%s"
,
diff
)
}
})
t
.
Run
(
"model can't think but think set false"
,
func
(
t
*
testing
.
T
)
{
think
:=
false
w
:=
createRequest
(
t
,
s
.
ChatHandler
,
api
.
ChatRequest
{
Model
:
"test"
,
Messages
:
[]
api
.
Message
{
{
Role
:
"user"
,
Content
:
"Hello!"
},
},
Think
:
&
api
.
ThinkValue
{
Value
:
think
},
})
if
w
.
Code
!=
http
.
StatusOK
{
t
.
Errorf
(
"expected status 200, got %d"
,
w
.
Code
)
}
})
t
.
Run
(
"missing model"
,
func
(
t
*
testing
.
T
)
{
w
:=
createRequest
(
t
,
s
.
ChatHandler
,
api
.
ChatRequest
{})
if
w
.
Code
!=
http
.
StatusBadRequest
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment