Skip to content

VideoInput

autogen.beta.events.input_events.VideoInput #

VideoInput(url: str) -> VideoUrlInput
VideoInput(*, file_id: str, filename: str | None = None) -> FileIdInput
VideoInput(*, data: bytes, media_type: VideoMediaType) -> BinaryInput
VideoInput(*, path: str | PathLike[str], media_type: VideoMediaType | None = None) -> BinaryInput
VideoInput(url=None, *, file_id=None, filename=None, data=None, media_type=None, path=None)

Factory for creating video input events.

Usage

VideoInput("https://example.com/video.mp4") # URL VideoInput(file_id="file-abc123") # pre-uploaded file VideoInput(data=raw_bytes, media_type="video/mp4") # raw binary VideoInput(path="clip.mp4") # local file

Source code in autogen/beta/events/input_events.py
def VideoInput(  # noqa: N802
    url: str | None = None,
    *,
    file_id: str | None = None,
    filename: str | None = None,
    data: bytes | None = None,
    media_type: VideoMediaType | None = None,
    path: str | PathLike[str] | None = None,
) -> VideoUrlInput | FileIdInput | BinaryInput:
    """Factory for creating video input events.

    Usage:
        VideoInput("https://example.com/video.mp4")            # URL
        VideoInput(file_id="file-abc123")                      # pre-uploaded file
        VideoInput(data=raw_bytes, media_type="video/mp4")     # raw binary
        VideoInput(path="clip.mp4")                            # local file
    """
    if url is not None:
        return VideoUrlInput(url)

    if file_id is not None:
        return FileIdInput(file_id, filename=filename)

    if path is not None:
        p = Path(path)
        suffix = p.suffix.lower()
        resolved_type = _VIDEO_EXTENSION_TO_MEDIA_TYPE.get(suffix)

        if resolved_type is None:
            if media_type is None:
                raise ValueError(
                    f"Cannot infer video media type from extension '{suffix}'. Provide 'media_type' explicitly."
                )

            resolved_type = media_type

        return BinaryInput(
            p.read_bytes(),
            media_type=resolved_type,
            vendor_metadata={"filename": p.name},
            kind=BinaryType.VIDEO,
        )

    if data is not None:
        if media_type is None:
            raise ValueError("'media_type' is required when using 'data'")
        return BinaryInput(
            data,
            media_type=media_type,
            kind=BinaryType.VIDEO,
        )

    raise ValueError("VideoInput() requires one of: 'url', 'file_id', 'data' + 'media_type', or 'path'")