Skip to content

Commit cc13590

Browse files
committed
[Frontend] Adjust try/except blocks in API impl
These were changed to separate blocks in vllm-project#9759 but I feel it's cleaner/clearer as a single block. It actually doesn't matter which parts of the block raise the specific exceptions in the except clauses, we still want to handle them in the same way. Signed-off-by: Nick Hill <nhill@redhat.com>
1 parent 235366f commit cc13590

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

vllm/entrypoints/openai/serving_completion.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,7 @@ async def create_completion(
189189
try:
190190
async for i, res in result_generator:
191191
final_res_batch[i] = res
192-
except asyncio.CancelledError:
193-
return self.create_error_response("Client disconnected")
194-
except ValueError as e:
195-
# TODO: Use a vllm-specific Validation Error
196-
return self.create_error_response(str(e))
197192

198-
try:
199193
for i, final_res in enumerate(final_res_batch):
200194
assert final_res is not None
201195

@@ -217,6 +211,8 @@ async def create_completion(
217211
tokenizer,
218212
request_metadata,
219213
)
214+
except asyncio.CancelledError:
215+
return self.create_error_response("Client disconnected")
220216
except ValueError as e:
221217
# TODO: Use a vllm-specific Validation Error
222218
return self.create_error_response(str(e))

vllm/entrypoints/openai/serving_embedding.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,19 +205,17 @@ async def create_embedding(
205205
try:
206206
async for i, res in result_generator:
207207
final_res_batch[i] = res
208-
except asyncio.CancelledError:
209-
return self.create_error_response("Client disconnected")
210208

211-
try:
212-
for final_res in final_res_batch:
213-
assert final_res is not None
209+
assert all(final_res is not None for final_res in final_res_batch)
214210

215211
final_res_batch_checked = cast(List[EmbeddingRequestOutput],
216212
final_res_batch)
217213

218214
response = request_output_to_embedding_response(
219215
final_res_batch_checked, request_id, created_time, model_name,
220216
encoding_format)
217+
except asyncio.CancelledError:
218+
return self.create_error_response("Client disconnected")
221219
except ValueError as e:
222220
# TODO: Use a vllm-specific Validation Error
223221
return self.create_error_response(str(e))

0 commit comments

Comments
 (0)