Skip to content

Commit 5efca07

Browse files
committed
refactor: optimize comments in streaming chat handler
Improve code comments based on PR feedback: - Clarify role initialization purpose to prevent UnboundLocalError - Consolidate split comment into single line for better readability Signed-off-by: Pierre Le Guen <26087574+PierreLeGuen@users.noreply.github.com>
1 parent e5c8de3 commit 5efca07

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

vllm_omni/entrypoints/openai/serving_chat.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,9 @@ async def chat_completion_stream_generator(
551551
created_time = int(time.time())
552552
chunk_object_type: Final = "chat.completion.chunk"
553553
first_iteration_dict = {}
554-
assert hasattr(request, "modalities") and request.modalities is not None, (
555-
"Streaming request must specify output modalities"
556-
)
554+
assert (
555+
hasattr(request, "modalities") and request.modalities is not None
556+
), "Streaming request must specify output modalities"
557557
for modality in request.modalities:
558558
first_iteration_dict[modality] = True
559559

@@ -638,19 +638,17 @@ async def chat_completion_stream_generator(
638638
if res.encoder_prompt_token_ids is not None:
639639
num_prompt_tokens += len(res.encoder_prompt_token_ids)
640640

641-
# Get role for all modalities (text, audio, image)
641+
# Initialize role before conditional blocks to avoid UnboundLocalError
642+
# when handling audio/image responses
642643
role = self.get_chat_request_role(request)
643644

644645
# We need to do it here, because if there are exceptions in
645646
# the result_generator, it needs to be sent as the FIRST
646647
# response (by the try...catch).
647648
if first_iteration_dict[final_output_type] and final_output_type == "text":
648649
num_cached_tokens = res.num_cached_tokens
649-
# Send first response for each request.n (index) with
650-
# the role
651-
652-
# NOTE num_choices defaults to 1 so this usually executes
653-
# once per request
650+
# Send first response for each choice with role
651+
# NOTE: num_choices defaults to 1 so this usually executes once per request
654652
for i in range(num_choices):
655653
choice_data = ChatCompletionResponseStreamChoice(
656654
index=i,

0 commit comments

Comments
 (0)