Skip to content

Commit

Permalink
[Frontend] Adjust try/except blocks in API impl
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
njhill committed Nov 5, 2024
1 parent 235366f commit 67bbfdc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
8 changes: 2 additions & 6 deletions vllm/entrypoints/openai/serving_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,7 @@ async def create_completion(
try:
async for i, res in result_generator:
final_res_batch[i] = res
except asyncio.CancelledError:
return self.create_error_response("Client disconnected")
except ValueError as e:
# TODO: Use a vllm-specific Validation Error
return self.create_error_response(str(e))

try:
for i, final_res in enumerate(final_res_batch):
assert final_res is not None

Expand All @@ -217,6 +211,8 @@ async def create_completion(
tokenizer,
request_metadata,
)
except asyncio.CancelledError:
return self.create_error_response("Client disconnected")
except ValueError as e:
# TODO: Use a vllm-specific Validation Error
return self.create_error_response(str(e))
Expand Down
8 changes: 3 additions & 5 deletions vllm/entrypoints/openai/serving_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,17 @@ async def create_embedding(
try:
async for i, res in result_generator:
final_res_batch[i] = res
except asyncio.CancelledError:
return self.create_error_response("Client disconnected")

try:
for final_res in final_res_batch:
assert final_res is not None
assert all(final_res is not None for final_res in final_res_batch)

final_res_batch_checked = cast(List[EmbeddingRequestOutput],
final_res_batch)

response = request_output_to_embedding_response(
final_res_batch_checked, request_id, created_time, model_name,
encoding_format)
except asyncio.CancelledError:
return self.create_error_response("Client disconnected")
except ValueError as e:
# TODO: Use a vllm-specific Validation Error
return self.create_error_response(str(e))
Expand Down

0 comments on commit 67bbfdc

Please sign in to comment.