fix: UnboundLocalError for role in streaming audio/image responses (#784)
Signed-off-by: Pierre Le Guen <26087574+PierreLeGuen@users.noreply.github.com>
This commit is contained in:
1 parent
790e34e375
commit
2c294a750b
1 file changed
+6
-6
@@ -667,17 +667,17 @@ class OmniOpenAIServingChat(OpenAIServingChat, AudioMixin):
|
||||
if res.encoder_prompt_token_ids is not None:
|
||||
num_prompt_tokens += len(res.encoder_prompt_token_ids)
|
||||
|
||||
# Initialize role before conditional blocks to avoid UnboundLocalError
|
||||
# when handling audio/image responses
|
||||
role = self.get_chat_request_role(request)
|
||||
|
||||
# We need to do it here, because if there are exceptions in
|
||||
# the result_generator, it needs to be sent as the FIRST
|
||||
# response (by the try...catch).
|
||||
if first_iteration_dict[final_output_type] and final_output_type == "text":
|
||||
num_cached_tokens = res.num_cached_tokens
|
||||
# Send first response for each request.n (index) with
|
||||
# the role
|
||||
role = self.get_chat_request_role(request)
|
||||
|
||||
# NOTE num_choices defaults to 1 so this usually executes
|
||||
# once per request
|
||||
# Send first response for each choice with role
|
||||
# NOTE: num_choices defaults to 1 so this usually executes once per request
|
||||
for i in range(num_choices):
|
||||
choice_data = ChatCompletionResponseStreamChoice(
|
||||
index=i,
|
||||
|
||||
Reference in new issue
Block a user