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
change
sglang
Commits
3fd1431d
Unverified
Commit
3fd1431d
authored
Aug 29, 2025
by
gongwei-130
Committed by
GitHub
Aug 29, 2025
Browse files
support enable in the reasoning field to enable thingking for thinkin… (#9715)
parent
161e9dc5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
0 deletions
+42
-0
python/sglang/srt/entrypoints/openai/protocol.py
python/sglang/srt/entrypoints/openai/protocol.py
+28
-0
test/srt/openai_server/basic/test_protocol.py
test/srt/openai_server/basic/test_protocol.py
+14
-0
No files found.
python/sglang/srt/entrypoints/openai/protocol.py
View file @
3fd1431d
...
@@ -460,6 +460,34 @@ class ChatCompletionRequest(BaseModel):
...
@@ -460,6 +460,34 @@ class ChatCompletionRequest(BaseModel):
values
[
"tool_choice"
]
=
"auto"
values
[
"tool_choice"
]
=
"auto"
return
values
return
values
@
model_validator
(
mode
=
"before"
)
@
classmethod
def
normalize_reasoning_inputs
(
cls
,
values
:
Dict
):
r
=
values
.
get
(
"reasoning"
)
if
r
is
None
:
return
values
if
isinstance
(
r
,
dict
):
effort
=
r
.
get
(
"effort"
)
or
r
.
get
(
"reasoning_effort"
)
if
effort
in
{
"low"
,
"medium"
,
"high"
}:
values
[
"reasoning_effort"
]
=
effort
enabled
=
(
r
.
get
(
"enabled"
)
if
r
.
get
(
"enabled"
)
is
not
None
else
r
.
get
(
"enable"
,
False
)
)
if
isinstance
(
enabled
,
str
):
enabled
=
enabled
.
strip
().
lower
()
in
{
"1"
,
"true"
,
"yes"
,
"y"
,
"on"
}
if
enabled
:
ctk
=
values
.
get
(
"chat_template_kwargs"
)
if
not
isinstance
(
ctk
,
dict
):
ctk
=
{}
ctk
.
setdefault
(
"thinking"
,
True
)
values
[
"chat_template_kwargs"
]
=
ctk
return
values
@
model_validator
(
mode
=
"before"
)
@
model_validator
(
mode
=
"before"
)
@
classmethod
@
classmethod
def
set_json_schema
(
cls
,
values
):
def
set_json_schema
(
cls
,
values
):
...
...
test/srt/openai_server/basic/test_protocol.py
View file @
3fd1431d
...
@@ -192,6 +192,20 @@ class TestChatCompletionRequest(unittest.TestCase):
...
@@ -192,6 +192,20 @@ class TestChatCompletionRequest(unittest.TestCase):
self
.
assertFalse
(
request
.
stream_reasoning
)
self
.
assertFalse
(
request
.
stream_reasoning
)
self
.
assertEqual
(
request
.
chat_template_kwargs
,
{
"custom_param"
:
"value"
})
self
.
assertEqual
(
request
.
chat_template_kwargs
,
{
"custom_param"
:
"value"
})
def
test_chat_completion_reasoning_effort
(
self
):
"""Test chat completion with reasoning effort"""
messages
=
[{
"role"
:
"user"
,
"content"
:
"Hello"
}]
request
=
ChatCompletionRequest
(
model
=
"test-model"
,
messages
=
messages
,
reasoning
=
{
"enabled"
:
True
,
"reasoning_effort"
:
"high"
,
},
)
self
.
assertEqual
(
request
.
reasoning_effort
,
"high"
)
self
.
assertEqual
(
request
.
chat_template_kwargs
,
{
"thinking"
:
True
})
def
test_chat_completion_json_format
(
self
):
def
test_chat_completion_json_format
(
self
):
"""Test chat completion json format"""
"""Test chat completion json format"""
transcript
=
"Good morning! It's 7:00 AM, and I'm just waking up. Today is going to be a busy day, "
transcript
=
"Good morning! It's 7:00 AM, and I'm just waking up. Today is going to be a busy day, "
...
...
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