Skip to content

Commit c2d46b7

Browse files
hmellormawong-amd
authored andcommitted
Handle error when str passed to /v1/audio/transcriptions (vllm-project#17909)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
1 parent 57651c7 commit c2d46b7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

vllm/entrypoints/openai/protocol.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
import json
66
import re
77
import time
8+
from http import HTTPStatus
89
from typing import Annotated, Any, ClassVar, Literal, Optional, Union
910

1011
import torch
11-
from fastapi import UploadFile
12+
from fastapi import HTTPException, UploadFile
1213
from pydantic import (BaseModel, ConfigDict, Field, TypeAdapter,
1314
ValidationInfo, field_validator, model_validator)
1415
from typing_extensions import TypeAlias
@@ -1727,7 +1728,13 @@ def to_sampling_params(
17271728

17281729
@model_validator(mode="before")
17291730
@classmethod
1730-
def validate_stream_options(cls, data):
1731+
def validate_transcription_request(cls, data):
1732+
if isinstance(data.get("file"), str):
1733+
raise HTTPException(
1734+
status_code=HTTPStatus.UNPROCESSABLE_ENTITY,
1735+
detail="Expected 'file' to be a file-like object, not 'str'.",
1736+
)
1737+
17311738
stream_opts = ["stream_include_usage", "stream_continuous_usage_stats"]
17321739
stream = data.get("stream", False)
17331740
if any(bool(data.get(so, False)) for so in stream_opts) and not stream:

0 commit comments

Comments
 (0)