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
f1f1d1d4
"torchvision/vscode:/vscode.git/clone" did not exist on "7de62659332effc3d1848d8b84dbeb6b8cb4ea21"
Unverified
Commit
f1f1d1d4
authored
Jul 15, 2025
by
jiawei
Committed by
GitHub
Jul 15, 2025
Browse files
Fix the input tools format and history tool_calls in OpenAI API (#6556)
parent
9120e83d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
2 deletions
+21
-2
python/sglang/srt/entrypoints/openai/serving_chat.py
python/sglang/srt/entrypoints/openai/serving_chat.py
+21
-2
No files found.
python/sglang/srt/entrypoints/openai/serving_chat.py
View file @
f1f1d1d4
...
@@ -113,12 +113,12 @@ class OpenAIServingChat(OpenAIServingBase):
...
@@ -113,12 +113,12 @@ class OpenAIServingChat(OpenAIServingBase):
request
.
skip_special_tokens
=
False
request
.
skip_special_tokens
=
False
if
not
isinstance
(
request
.
tool_choice
,
str
):
if
not
isinstance
(
request
.
tool_choice
,
str
):
tools
=
[
tools
=
[
item
.
function
.
model_dump
()
item
.
model_dump
()
for
item
in
request
.
tools
for
item
in
request
.
tools
if
item
.
function
.
name
==
request
.
tool_choice
.
function
.
name
if
item
.
function
.
name
==
request
.
tool_choice
.
function
.
name
]
]
else
:
else
:
tools
=
[
item
.
function
.
model_dump
()
for
item
in
request
.
tools
]
tools
=
[
item
.
model_dump
()
for
item
in
request
.
tools
]
tool_call_parser
=
self
.
tokenizer_manager
.
server_args
.
tool_call_parser
tool_call_parser
=
self
.
tokenizer_manager
.
server_args
.
tool_call_parser
parser
=
FunctionCallParser
(
request
.
tools
,
tool_call_parser
)
parser
=
FunctionCallParser
(
request
.
tools
,
tool_call_parser
)
...
@@ -164,6 +164,25 @@ class OpenAIServingChat(OpenAIServingBase):
...
@@ -164,6 +164,25 @@ class OpenAIServingChat(OpenAIServingBase):
audio_data
,
audio_data
,
modalities
,
modalities
,
)
)
if
"tool_calls"
in
processed_msg
and
isinstance
(
processed_msg
.
get
(
"tool_calls"
),
list
):
for
call
in
processed_msg
[
"tool_calls"
]:
try
:
if
"arguments"
in
call
[
"function"
]
and
isinstance
(
call
[
"function"
][
"arguments"
],
str
):
call
[
"function"
][
"arguments"
]
=
json
.
loads
(
call
[
"function"
][
"arguments"
]
)
except
json
.
JSONDecodeError
as
e
:
# Log a warning or error if JSON parsing fails for arguments
logger
.
warning
(
f
"Failed to parse tool call arguments as JSON:
{
e
}
"
)
# Decide whether to continue or raise the exception based on desired behavior
continue
# Or raise e if strict parsing is required
openai_compatible_messages
.
append
(
processed_msg
)
openai_compatible_messages
.
append
(
processed_msg
)
# Handle assistant prefix for continue_final_message
# Handle assistant prefix for continue_final_message
...
...
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