Skip to content

Commit aa0d06d

Browse files
feat(client): support file upload requests
1 parent 1c5e20c commit aa0d06d

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/writerai/_base_client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,10 @@ def _build_request(
534534
is_body_allowed = options.method.lower() != "get"
535535

536536
if is_body_allowed:
537-
kwargs["json"] = json_data if is_given(json_data) else None
537+
if isinstance(json_data, bytes):
538+
kwargs["content"] = json_data
539+
else:
540+
kwargs["json"] = json_data if is_given(json_data) else None
538541
kwargs["files"] = files
539542
else:
540543
headers.pop("Content-Type", None)

src/writerai/_files.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ def _transform_file(file: FileTypes) -> HttpxFileTypes:
6969
return file
7070

7171
if is_tuple_t(file):
72-
return (file[0], _read_file_content(file[1]), *file[2:])
72+
return (file[0], read_file_content(file[1]), *file[2:])
7373

7474
raise TypeError(f"Expected file types input to be a FileContent type or to be a tuple")
7575

7676

77-
def _read_file_content(file: FileContent) -> HttpxFileContent:
77+
def read_file_content(file: FileContent) -> HttpxFileContent:
7878
if isinstance(file, os.PathLike):
7979
return pathlib.Path(file).read_bytes()
8080
return file
@@ -118,12 +118,12 @@ async def _async_transform_file(file: FileTypes) -> HttpxFileTypes:
118118
return file
119119

120120
if is_tuple_t(file):
121-
return (file[0], await _async_read_file_content(file[1]), *file[2:])
121+
return (file[0], await async_read_file_content(file[1]), *file[2:])
122122

123123
raise TypeError(f"Expected file types input to be a FileContent type or to be a tuple")
124124

125125

126-
async def _async_read_file_content(file: FileContent) -> HttpxFileContent:
126+
async def async_read_file_content(file: FileContent) -> HttpxFileContent:
127127
if isinstance(file, os.PathLike):
128128
return await anyio.Path(file).read_bytes()
129129

0 commit comments

Comments
 (0)