Skip to content

Commit bbfb55c

Browse files
[Misc] Allow fetch_* utils to access local files by default (vllm-project#29932)
Signed-off-by: DarkLight1337 <[email protected]>
1 parent 0bec63f commit bbfb55c

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

vllm/multimodal/utils.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ def __init__(
6767
to set num_frames for video, set
6868
`--media-io-kwargs '{"video":{"num_frames":40}}'`
6969
connection: HTTP connection client to download media contents.
70-
allowed_local_media_path: A local directory to load media files
71-
from.
70+
allowed_local_media_path: A local directory to load media files from.
71+
allowed_media_domains: If set, only media URLs that belong to this
72+
domain can be used for multi-modal inputs.
7273
"""
7374
super().__init__()
7475

@@ -123,16 +124,16 @@ def _load_file_url(
123124
"Cannot load local files without `--allowed-local-media-path`."
124125
)
125126

126-
filepath = Path(url2pathname(url_spec.path))
127+
filepath = Path(url2pathname(url_spec.netloc + url_spec.path))
127128
if allowed_local_media_path not in filepath.resolve().parents:
128129
raise ValueError(
129130
f"The file path {filepath} must be a subpath "
130-
f"of `--allowed-local-media-path` {allowed_local_media_path}."
131+
f"of `--allowed-local-media-path {allowed_local_media_path}`."
131132
)
132133

133134
return media_io.load_file(filepath)
134135

135-
def _assert_url_in_allowed_media_domains(self, url_spec) -> None:
136+
def _assert_url_in_allowed_media_domains(self, url_spec: ParseResult) -> None:
136137
if (
137138
self.allowed_media_domains
138139
and url_spec.hostname not in self.allowed_media_domains
@@ -489,9 +490,16 @@ def fetch_audio(
489490
Args:
490491
audio_url: URL of the audio file to fetch.
491492
audio_io_kwargs: Additional kwargs passed to handle audio IO.
493+
494+
Warning:
495+
This method has direct access to local files and is only intended
496+
to be called by user code. Never call this from the online server!
492497
"""
493498
media_io_kwargs = None if not audio_io_kwargs else {"audio": audio_io_kwargs}
494-
media_connector = MediaConnector(media_io_kwargs=media_io_kwargs)
499+
media_connector = MediaConnector(
500+
media_io_kwargs=media_io_kwargs,
501+
allowed_local_media_path="/",
502+
)
495503
return media_connector.fetch_audio(audio_url)
496504

497505

@@ -503,9 +511,16 @@ def fetch_image(
503511
Args:
504512
image_url: URL of the image file to fetch.
505513
image_io_kwargs: Additional kwargs passed to handle image IO.
514+
515+
Warning:
516+
This method has direct access to local files and is only intended
517+
to be called by user code. Never call this from the online server!
506518
"""
507519
media_io_kwargs = None if not image_io_kwargs else {"image": image_io_kwargs}
508-
media_connector = MediaConnector(media_io_kwargs=media_io_kwargs)
520+
media_connector = MediaConnector(
521+
media_io_kwargs=media_io_kwargs,
522+
allowed_local_media_path="/",
523+
)
509524
return media_connector.fetch_image(image_url)
510525

511526

@@ -517,7 +532,14 @@ def fetch_video(
517532
Args:
518533
video_url: URL of the video file to fetch.
519534
video_io_kwargs: Additional kwargs passed to handle video IO.
535+
536+
Warning:
537+
This method has direct access to local files and is only intended
538+
to be called by user code. Never call this from the online server!
520539
"""
521540
media_io_kwargs = None if not video_io_kwargs else {"video": video_io_kwargs}
522-
media_connector = MediaConnector(media_io_kwargs=media_io_kwargs)
541+
media_connector = MediaConnector(
542+
media_io_kwargs=media_io_kwargs,
543+
allowed_local_media_path="/",
544+
)
523545
return media_connector.fetch_video(video_url)

vllm/multimodal/video.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def load_bytes(
267267
return frames, metadata
268268

269269

270-
class VideoMediaIO(MediaIO[npt.NDArray]):
270+
class VideoMediaIO(MediaIO[tuple[npt.NDArray, dict[str, Any]]]):
271271
def __init__(
272272
self,
273273
image_io: ImageMediaIO,

0 commit comments

Comments
 (0)