File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed
python/sglang/srt/entrypoints/openai
test/srt/openai_server/function_call Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -484,15 +484,21 @@ async def _generate_chat_stream(
484
484
485
485
# Handle tool calls
486
486
if request .tool_choice != "none" and request .tools :
487
- async for chunk in self ._process_tool_call_stream (
487
+ async for (
488
+ chunk ,
489
+ tool_call_finish_reason_type ,
490
+ ) in self ._process_tool_call_stream (
488
491
index ,
489
492
delta ,
490
493
parser_dict ,
491
494
content ,
492
495
request ,
493
496
finish_reason_type ,
494
497
):
495
- yield chunk
498
+ if chunk :
499
+ yield chunk
500
+ finish_reason_type = tool_call_finish_reason_type
501
+
496
502
else :
497
503
# Regular content
498
504
if delta or not (
@@ -865,7 +871,7 @@ async def _process_tool_call_stream(
865
871
choices = [choice_data ],
866
872
model = request .model ,
867
873
)
868
- yield f"data: { chunk .model_dump_json ()} \n \n "
874
+ yield f"data: { chunk .model_dump_json ()} \n \n " , finish_reason_type
869
875
870
876
# Yield tool calls
871
877
for call_item in calls :
@@ -920,4 +926,7 @@ async def _process_tool_call_stream(
920
926
choices = [choice_data ],
921
927
model = request .model ,
922
928
)
923
- yield f"data: { chunk .model_dump_json ()} \n \n "
929
+ yield f"data: { chunk .model_dump_json ()} \n \n " , finish_reason_type
930
+
931
+ if finish_reason_type == "stop" :
932
+ yield None , "tool_calls"
Original file line number Diff line number Diff line change @@ -159,6 +159,13 @@ def test_function_calling_streaming_simple(self):
159
159
"Target function name 'get_current_weather' was not found in the streaming chunks" ,
160
160
)
161
161
162
+ finish_reason = chunks [- 1 ].choices [0 ].finish_reason
163
+ self .assertEqual (
164
+ finish_reason ,
165
+ "tool_calls" ,
166
+ "Final response of function calling should have finish_reason 'tool_calls'" ,
167
+ )
168
+
162
169
def test_function_calling_streaming_args_parsing (self ):
163
170
"""
164
171
Test: Whether the function call arguments returned in streaming mode can be correctly concatenated into valid JSON.
You can’t perform that action at this time.
0 commit comments