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
90d429f5
Unverified
Commit
90d429f5
authored
Oct 08, 2025
by
Patrick Devine
Committed by
GitHub
Oct 08, 2025
Browse files
thinking: turn on thinking mode for all reasoning models (#12533)
parent
1fc35f12
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
20 deletions
+30
-20
api/types.go
api/types.go
+1
-1
openai/openai.go
openai/openai.go
+11
-6
server/routes.go
server/routes.go
+18
-6
server/routes_generate_test.go
server/routes_generate_test.go
+0
-7
No files found.
api/types.go
View file @
90d429f5
...
@@ -936,7 +936,7 @@ func (t *ThinkValue) UnmarshalJSON(data []byte) error {
...
@@ -936,7 +936,7 @@ func (t *ThinkValue) UnmarshalJSON(data []byte) error {
return
nil
return
nil
}
}
return
fmt
.
Errorf
(
"think must be a boolean or string (
\"
high
\"
,
\"
medium
\"
,
\"
low
\"
)"
)
return
fmt
.
Errorf
(
"think must be a boolean or string (
\"
high
\"
,
\"
medium
\"
,
\"
low
\"
, true, or false
)"
)
}
}
// MarshalJSON implements json.Marshaler
// MarshalJSON implements json.Marshaler
...
...
openai/openai.go
View file @
90d429f5
...
@@ -9,6 +9,7 @@ import (
...
@@ -9,6 +9,7 @@ import (
"log/slog"
"log/slog"
"math/rand"
"math/rand"
"net/http"
"net/http"
"slices"
"strings"
"strings"
"time"
"time"
...
@@ -82,7 +83,7 @@ type StreamOptions struct {
...
@@ -82,7 +83,7 @@ type StreamOptions struct {
}
}
type
Reasoning
struct
{
type
Reasoning
struct
{
Effort
*
string
`json:"effort,omitempty"`
Effort
string
`json:"effort,omitempty"`
}
}
type
ChatCompletionRequest
struct
{
type
ChatCompletionRequest
struct
{
...
@@ -567,13 +568,17 @@ func FromChatRequest(r ChatCompletionRequest) (*api.ChatRequest, error) {
...
@@ -567,13 +568,17 @@ func FromChatRequest(r ChatCompletionRequest) (*api.ChatRequest, error) {
var
think
*
api
.
ThinkValue
var
think
*
api
.
ThinkValue
if
r
.
Reasoning
!=
nil
{
if
r
.
Reasoning
!=
nil
{
think
=
&
api
.
ThinkValue
{
if
!
slices
.
Contains
([]
string
{
"high"
,
"medium"
,
"low"
,
"none"
},
r
.
Reasoning
.
Effort
)
{
Value
:
*
r
.
Reasoning
.
Effort
,
return
nil
,
fmt
.
Errorf
(
"invalid reasoning value: '%s' (must be
\"
high
\"
,
\"
medium
\"
,
\"
low
\"
, or
\"
none
\"
)"
,
r
.
Reasoning
.
Effort
)
}
}
}
else
if
r
.
ReasoningEffort
!=
nil
{
think
=
&
api
.
ThinkValue
{
if
r
.
Reasoning
.
Effort
==
"none"
{
Value
:
*
r
.
ReasoningEffort
,
think
=
&
api
.
ThinkValue
{
Value
:
false
}
}
else
{
think
=
&
api
.
ThinkValue
{
Value
:
r
.
Reasoning
.
Effort
}
}
}
}
else
if
r
.
ReasoningEffort
!=
nil
{
think
=
&
api
.
ThinkValue
{
Value
:
*
r
.
ReasoningEffort
}
}
}
return
&
api
.
ChatRequest
{
return
&
api
.
ChatRequest
{
...
...
server/routes.go
View file @
90d429f5
...
@@ -330,12 +330,16 @@ func (s *Server) GenerateHandler(c *gin.Context) {
...
@@ -330,12 +330,16 @@ func (s *Server) GenerateHandler(c *gin.Context) {
if
req
.
Suffix
!=
""
{
if
req
.
Suffix
!=
""
{
caps
=
append
(
caps
,
model
.
CapabilityInsert
)
caps
=
append
(
caps
,
model
.
CapabilityInsert
)
}
}
if
req
.
Think
!=
nil
&&
req
.
Think
.
Bool
()
{
modelCaps
:=
m
.
Capabilities
()
if
req
.
Think
!=
nil
{
caps
=
append
(
caps
,
model
.
CapabilityThinking
)
caps
=
append
(
caps
,
model
.
CapabilityThinking
)
// TODO(drifkin): consider adding a warning if it's false and the model
}
else
{
// doesn't support thinking. It's not strictly required, but it can be a
// add thinking if the model supports it
// hint that the user is on an older qwen3/r1 model that doesn't have an
if
slices
.
Contains
(
modelCaps
,
model
.
CapabilityThinking
)
{
// updated template supporting thinking
caps
=
append
(
caps
,
model
.
CapabilityThinking
)
req
.
Think
=
&
api
.
ThinkValue
{
Value
:
true
}
}
}
}
r
,
m
,
opts
,
err
:=
s
.
scheduleRunner
(
c
.
Request
.
Context
(),
name
.
String
(),
caps
,
req
.
Options
,
req
.
KeepAlive
)
r
,
m
,
opts
,
err
:=
s
.
scheduleRunner
(
c
.
Request
.
Context
(),
name
.
String
(),
caps
,
req
.
Options
,
req
.
KeepAlive
)
...
@@ -1871,8 +1875,16 @@ func (s *Server) ChatHandler(c *gin.Context) {
...
@@ -1871,8 +1875,16 @@ func (s *Server) ChatHandler(c *gin.Context) {
if
len
(
req
.
Tools
)
>
0
{
if
len
(
req
.
Tools
)
>
0
{
caps
=
append
(
caps
,
model
.
CapabilityTools
)
caps
=
append
(
caps
,
model
.
CapabilityTools
)
}
}
if
req
.
Think
!=
nil
&&
req
.
Think
.
Bool
()
{
modelCaps
:=
m
.
Capabilities
()
if
req
.
Think
!=
nil
{
caps
=
append
(
caps
,
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
)
req
.
Think
=
&
api
.
ThinkValue
{
Value
:
true
}
}
}
}
r
,
m
,
opts
,
err
:=
s
.
scheduleRunner
(
c
.
Request
.
Context
(),
name
.
String
(),
caps
,
req
.
Options
,
req
.
KeepAlive
)
r
,
m
,
opts
,
err
:=
s
.
scheduleRunner
(
c
.
Request
.
Context
(),
name
.
String
(),
caps
,
req
.
Options
,
req
.
KeepAlive
)
...
...
server/routes_generate_test.go
View file @
90d429f5
...
@@ -1120,13 +1120,6 @@ func TestChatWithPromptEndingInThinkTag(t *testing.T) {
...
@@ -1120,13 +1120,6 @@ func TestChatWithPromptEndingInThinkTag(t *testing.T) {
"The answer is 4."
,
"The answer is 4."
,
true
)
true
)
testChatRequest
(
t
,
"thinking disabled but template still adds think tag"
,
"Simple question"
,
" My thoughts </think> The answer."
,
""
,
" My thoughts </think> The answer."
,
false
)
// Test streaming response with template-added <think>
// Test streaming response with template-added <think>
t
.
Run
(
"streaming with thinking"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"streaming with thinking"
,
func
(
t
*
testing
.
T
)
{
var
wg
sync
.
WaitGroup
var
wg
sync
.
WaitGroup
...
...
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