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
d0cf6c82
Unverified
Commit
d0cf6c82
authored
Aug 12, 2025
by
Michael Yang
Committed by
GitHub
Aug 12, 2025
Browse files
fix(openai): handle reasoning_effort (#11868)
parent
8f4ec9ab
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
20 deletions
+23
-20
api/types.go
api/types.go
+4
-4
openai/openai.go
openai/openai.go
+7
-4
server/prompt.go
server/prompt.go
+4
-4
server/routes.go
server/routes.go
+8
-8
No files found.
api/types.go
View file @
d0cf6c82
...
...
@@ -769,8 +769,8 @@ func (t *ThinkValue) IsString() bool {
return
ok
}
//
As
Bool returns the value as a bool (true if enabled in any way)
func
(
t
*
ThinkValue
)
As
Bool
()
bool
{
// Bool returns the value as a bool (true if enabled in any way)
func
(
t
*
ThinkValue
)
Bool
()
bool
{
if
t
==
nil
||
t
.
Value
==
nil
{
return
false
}
...
...
@@ -786,8 +786,8 @@ func (t *ThinkValue) AsBool() bool {
}
}
//
As
String returns the value as a string
func
(
t
*
ThinkValue
)
As
String
()
string
{
// String returns the value as a string
func
(
t
*
ThinkValue
)
String
()
string
{
if
t
==
nil
||
t
.
Value
==
nil
{
return
""
}
...
...
openai/openai.go
View file @
d0cf6c82
...
...
@@ -103,6 +103,7 @@ type ChatCompletionRequest struct {
ResponseFormat
*
ResponseFormat
`json:"response_format"`
Tools
[]
api
.
Tool
`json:"tools"`
Reasoning
*
Reasoning
`json:"reasoning,omitempty"`
ReasoningEffort
*
string
`json:"reasoning_effort,omitempty"`
}
type
ChatCompletion
struct
{
...
...
@@ -541,10 +542,6 @@ func fromChatRequest(r ChatCompletionRequest) (*api.ChatRequest, error) {
options
[
"top_p"
]
=
1.0
}
if
r
.
Reasoning
!=
nil
{
options
[
"reasoning"
]
=
*
r
.
Reasoning
.
Effort
}
var
format
json
.
RawMessage
if
r
.
ResponseFormat
!=
nil
{
switch
strings
.
ToLower
(
strings
.
TrimSpace
(
r
.
ResponseFormat
.
Type
))
{
...
...
@@ -560,9 +557,15 @@ func fromChatRequest(r ChatCompletionRequest) (*api.ChatRequest, error) {
var
think
*
api
.
ThinkValue
if
r
.
Reasoning
!=
nil
{
options
[
"reasoning"
]
=
*
r
.
Reasoning
.
Effort
think
=
&
api
.
ThinkValue
{
Value
:
*
r
.
Reasoning
.
Effort
,
}
}
else
if
r
.
ReasoningEffort
!=
nil
{
options
[
"reasoning"
]
=
*
r
.
ReasoningEffort
think
=
&
api
.
ThinkValue
{
Value
:
*
r
.
ReasoningEffort
,
}
}
return
&
api
.
ChatRequest
{
...
...
server/prompt.go
View file @
d0cf6c82
...
...
@@ -44,8 +44,8 @@ func chatPrompt(ctx context.Context, m *Model, tokenize tokenizeFunc, opts *api.
thinkVal
:=
false
thinkLevel
:=
""
if
think
!=
nil
{
thinkVal
=
think
.
As
Bool
()
thinkLevel
=
think
.
As
String
()
thinkVal
=
think
.
Bool
()
thinkLevel
=
think
.
String
()
}
var
b
bytes
.
Buffer
if
err
:=
m
.
Template
.
Execute
(
&
b
,
template
.
Values
{
Messages
:
append
(
system
,
msgs
[
i
:
]
...
),
Tools
:
tools
,
Think
:
thinkVal
,
ThinkLevel
:
thinkLevel
,
IsThinkSet
:
think
!=
nil
});
err
!=
nil
{
...
...
@@ -105,8 +105,8 @@ func chatPrompt(ctx context.Context, m *Model, tokenize tokenizeFunc, opts *api.
thinkVal
:=
false
thinkLevel
:=
""
if
think
!=
nil
{
thinkVal
=
think
.
As
Bool
()
thinkLevel
=
think
.
As
String
()
thinkVal
=
think
.
Bool
()
thinkLevel
=
think
.
String
()
}
if
err
:=
m
.
Template
.
Execute
(
&
b
,
template
.
Values
{
Messages
:
append
(
system
,
msgs
[
currMsgIdx
:
]
...
),
Tools
:
tools
,
Think
:
thinkVal
,
ThinkLevel
:
thinkLevel
,
IsThinkSet
:
think
!=
nil
});
err
!=
nil
{
return
""
,
nil
,
err
...
...
server/routes.go
View file @
d0cf6c82
...
...
@@ -205,7 +205,7 @@ func (s *Server) GenerateHandler(c *gin.Context) {
// Validate Think value: string values currently only allowed for gptoss models
if
req
.
Think
!=
nil
&&
req
.
Think
.
IsString
()
&&
!
useHarmony
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
fmt
.
Sprintf
(
"think value %q is not supported for this model"
,
req
.
Think
.
As
String
())})
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
fmt
.
Sprintf
(
"think value %q is not supported for this model"
,
req
.
Think
.
String
())})
return
}
...
...
@@ -213,7 +213,7 @@ func (s *Server) GenerateHandler(c *gin.Context) {
if
req
.
Suffix
!=
""
{
caps
=
append
(
caps
,
model
.
CapabilityInsert
)
}
if
req
.
Think
!=
nil
&&
req
.
Think
.
As
Bool
()
{
if
req
.
Think
!=
nil
&&
req
.
Think
.
Bool
()
{
caps
=
append
(
caps
,
model
.
CapabilityThinking
)
// TODO(drifkin): consider adding a warning if it's false and the model
// doesn't support thinking. It's not strictly required, but it can be a
...
...
@@ -288,10 +288,10 @@ func (s *Server) GenerateHandler(c *gin.Context) {
values
.
Messages
=
append
(
msgs
,
api
.
Message
{
Role
:
"user"
,
Content
:
req
.
Prompt
})
}
values
.
Think
=
req
.
Think
!=
nil
&&
req
.
Think
.
As
Bool
()
values
.
Think
=
req
.
Think
!=
nil
&&
req
.
Think
.
Bool
()
values
.
ThinkLevel
=
""
if
req
.
Think
!=
nil
{
values
.
ThinkLevel
=
req
.
Think
.
As
String
()
values
.
ThinkLevel
=
req
.
Think
.
String
()
}
values
.
IsThinkSet
=
req
.
Think
!=
nil
...
...
@@ -317,7 +317,7 @@ func (s *Server) GenerateHandler(c *gin.Context) {
var
thinkingState
*
thinking
.
Parser
if
!
useHarmony
{
openingTag
,
closingTag
:=
thinking
.
InferTags
(
m
.
Template
.
Template
)
if
req
.
Think
!=
nil
&&
req
.
Think
.
As
Bool
()
&&
openingTag
!=
""
&&
closingTag
!=
""
{
if
req
.
Think
!=
nil
&&
req
.
Think
.
Bool
()
&&
openingTag
!=
""
&&
closingTag
!=
""
{
thinkingState
=
&
thinking
.
Parser
{
OpeningTag
:
openingTag
,
ClosingTag
:
closingTag
,
...
...
@@ -1547,7 +1547,7 @@ func (s *Server) ChatHandler(c *gin.Context) {
if
len
(
req
.
Tools
)
>
0
{
caps
=
append
(
caps
,
model
.
CapabilityTools
)
}
if
req
.
Think
!=
nil
&&
req
.
Think
.
As
Bool
()
{
if
req
.
Think
!=
nil
&&
req
.
Think
.
Bool
()
{
caps
=
append
(
caps
,
model
.
CapabilityThinking
)
}
...
...
@@ -1601,7 +1601,7 @@ func (s *Server) ChatHandler(c *gin.Context) {
// Validate Think value: string values currently only allowed for gptoss models
if
req
.
Think
!=
nil
&&
req
.
Think
.
IsString
()
&&
!
useHarmony
{
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
fmt
.
Sprintf
(
"think value %q is not supported for this model"
,
req
.
Think
.
As
String
())})
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
fmt
.
Sprintf
(
"think value %q is not supported for this model"
,
req
.
Think
.
String
())})
return
}
...
...
@@ -1620,7 +1620,7 @@ func (s *Server) ChatHandler(c *gin.Context) {
var
thinkingState
*
thinking
.
Parser
openingTag
,
closingTag
:=
thinking
.
InferTags
(
m
.
Template
.
Template
)
if
req
.
Think
!=
nil
&&
req
.
Think
.
As
Bool
()
&&
openingTag
!=
""
&&
closingTag
!=
""
{
if
req
.
Think
!=
nil
&&
req
.
Think
.
Bool
()
&&
openingTag
!=
""
&&
closingTag
!=
""
{
thinkingState
=
&
thinking
.
Parser
{
OpeningTag
:
openingTag
,
ClosingTag
:
closingTag
,
...
...
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