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
a0e4d4eb
Unverified
Commit
a0e4d4eb
authored
Jun 11, 2025
by
Xu Wenqing
Committed by
GitHub
Jun 10, 2025
Browse files
Fix missing tool call id if tool call index >0 in streaming tool call output. (#7049)
Signed-off-by:
许文卿
<
xwq391974@alibaba-inc.com
>
parent
2f584455
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
3 deletions
+4
-3
python/sglang/srt/openai_api/adapter.py
python/sglang/srt/openai_api/adapter.py
+4
-3
No files found.
python/sglang/srt/openai_api/adapter.py
View file @
a0e4d4eb
...
@@ -1479,7 +1479,7 @@ async def v1_chat_completions(
...
@@ -1479,7 +1479,7 @@ async def v1_chat_completions(
reasoning_parser_dict
=
{}
reasoning_parser_dict
=
{}
async
def
generate_stream_resp
():
async
def
generate_stream_resp
():
tool_
call_first
=
True
tool_
index_previous
=
-
1
is_firsts
=
{}
is_firsts
=
{}
stream_buffers
=
{}
stream_buffers
=
{}
n_prev_tokens
=
{}
n_prev_tokens
=
{}
...
@@ -1645,6 +1645,7 @@ async def v1_chat_completions(
...
@@ -1645,6 +1645,7 @@ async def v1_chat_completions(
# 2) if we found calls, we output them as separate chunk(s)
# 2) if we found calls, we output them as separate chunk(s)
for
call_item
in
calls
:
for
call_item
in
calls
:
tool_index_current
=
call_item
.
tool_index
# transform call_item -> FunctionResponse + ToolCall
# transform call_item -> FunctionResponse + ToolCall
if
finish_reason_type
==
"stop"
:
if
finish_reason_type
==
"stop"
:
latest_delta_len
=
0
latest_delta_len
=
0
...
@@ -1671,7 +1672,7 @@ async def v1_chat_completions(
...
@@ -1671,7 +1672,7 @@ async def v1_chat_completions(
tool_call
=
ToolCall
(
tool_call
=
ToolCall
(
id
=
(
id
=
(
f
"call_
{
base64
.
urlsafe_b64encode
(
uuid
.
uuid4
().
bytes
).
rstrip
(
b
'='
).
decode
()
}
"
f
"call_
{
base64
.
urlsafe_b64encode
(
uuid
.
uuid4
().
bytes
).
rstrip
(
b
'='
).
decode
()
}
"
if
tool_
call_firs
t
if
tool_
index_previous
!=
tool_index_curren
t
else
None
else
None
),
),
index
=
call_item
.
tool_index
,
index
=
call_item
.
tool_index
,
...
@@ -1680,7 +1681,7 @@ async def v1_chat_completions(
...
@@ -1680,7 +1681,7 @@ async def v1_chat_completions(
arguments
=
call_item
.
parameters
,
arguments
=
call_item
.
parameters
,
),
),
)
)
tool_
call_first
=
False
tool_
index_previous
=
tool_index_current
choice_data
=
ChatCompletionResponseStreamChoice
(
choice_data
=
ChatCompletionResponseStreamChoice
(
index
=
index
,
index
=
index
,
delta
=
DeltaMessage
(
tool_calls
=
[
tool_call
]),
delta
=
DeltaMessage
(
tool_calls
=
[
tool_call
]),
...
...
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