Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions src/interfaze/_inputs.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,14 +10,35 @@
BytesLike = Union[bytes, bytearray]

_EXT_MIME = {
"png": "image/png", "jpg": "image/jpeg", "jpeg": "image/jpeg", "webp": "image/webp",
"gif": "image/gif", "bmp": "image/bmp", "heic": "image/heic", "heif": "image/heif",
"pdf": "application/pdf", "csv": "text/csv", "tsv": "text/tab-separated-values",
"xml": "application/xml", "json": "application/json", "txt": "text/plain",
"md": "text/markdown", "markdown": "text/markdown", "yaml": "application/yaml", "yml": "application/yaml",
"wav": "audio/wav", "mp3": "audio/mpeg", "m4a": "audio/mp4", "ogg": "audio/ogg", "flac": "audio/flac",
"mp4": "video/mp4", "mov": "video/quicktime", "webm": "video/webm", "avi": "video/x-msvideo",
"mkv": "video/x-matroska", "3gp": "video/3gpp",
"png": "image/png",
"jpg": "image/jpeg",
"jpeg": "image/jpeg",
"webp": "image/webp",
"gif": "image/gif",
"bmp": "image/bmp",
"heic": "image/heic",
"heif": "image/heif",
"pdf": "application/pdf",
"csv": "text/csv",
"tsv": "text/tab-separated-values",
"xml": "application/xml",
"json": "application/json",
"txt": "text/plain",
"md": "text/markdown",
"markdown": "text/markdown",
"yaml": "application/yaml",
"yml": "application/yaml",
"wav": "audio/wav",
"mp3": "audio/mpeg",
"m4a": "audio/mp4",
"ogg": "audio/ogg",
"flac": "audio/flac",
"mp4": "video/mp4",
"mov": "video/quicktime",
"webm": "video/webm",
"avi": "video/x-msvideo",
"mkv": "video/x-matroska",
"3gp": "video/3gpp",
}


Expand DownExpand Up@@ -63,8 +84,8 @@ def file(src: str, *, filename: Optional[str] = None, format: Optional[str] = No
f: Dict[str, Any] = {"file_data": src}
if filename:
f["filename"] = filename
if format:
f["format"] = format
if mime:
f["format"] = mime
return {"type": "file", "file": f}


Expand Down
14 changes: 14 additions & 0 deletions tests/test_inputs_and_client.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,6 +22,19 @@ def test_file_part():
)


def test_file_forwards_computed_mime():
assert inputs.file("https://x.com/d.pdf")["file"]["format"] == "application/pdf"


def test_video_forwards_mp4_mime():
part = inputs.video("https://x.com/clip.mp4")
assert part["type"] == "file" and part["file"]["format"] == "video/mp4"


def test_file_unknown_ext_omits_format():
assert "format" not in inputs.file("https://x.com/page")["file"]


def test_audio_uses_input_audio():
part = inputs.audio("https://x.com/a.wav")
assert part["type"] == "input_audio" and part["input_audio"]["format"] == "wav"
Expand DownExpand Up@@ -51,6 +64,7 @@ def test_auto_part_routing():
assert inputs.auto_part("https://x.com/a.wav")["type"] == "input_audio"
assert inputs.auto_part("https://x.com/a.pdf")["type"] == "file"
assert inputs.auto_part("https://x.com/a.mp4")["type"] == "file"
assert inputs.auto_part("https://x.com/a.mp4")["file"]["format"] == "video/mp4"


# ---- client surface ----
Expand Down