Skip to content

Commit 411bf89

Browse files
fix: multipart-form request for image translation.
1 parent 4146c25 commit 411bf89

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

jigsawstack/translate.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ def image(
9595
blob: Union[TranslateImageParams, bytes],
9696
options: TranslateImageParams = None,
9797
) -> Union[TranslateImageResponse, bytes]:
98+
path = "/ai/translate/image"
99+
options = options or {}
98100
if isinstance(
99101
blob, dict
100102
): # If params is provided as a dict, we assume it's the first argument
@@ -106,17 +108,14 @@ def image(
106108
).perform_with_content()
107109
return resp
108110

109-
options = options or {}
110-
path = build_path(base_path="/ai/translate/image", params=options)
111-
content_type = options.get("content_type", "application/octet-stream")
112-
headers = {"Content-Type": content_type}
113-
111+
112+
files = {"file": blob}
114113
resp = Request(
115114
config=self.config,
116115
path=path,
117116
params=options,
118117
data=blob,
119-
headers=headers,
118+
files=files,
120119
verb="post",
121120
).perform_with_content()
122121
return resp
@@ -159,6 +158,8 @@ async def image(
159158
blob: Union[TranslateImageParams, bytes],
160159
options: TranslateImageParams = None,
161160
) -> Union[TranslateImageResponse, bytes]:
161+
path = "/ai/translate/image"
162+
options = options or {}
162163
if isinstance(blob, dict):
163164
resp = await AsyncRequest(
164165
config=self.config,
@@ -168,17 +169,13 @@ async def image(
168169
).perform_with_content()
169170
return resp
170171

171-
options = options or {}
172-
path = build_path(base_path="/ai/translate/image", params=options)
173-
content_type = options.get("content_type", "application/octet-stream")
174-
headers = {"Content-Type": content_type}
175-
172+
files = {"file": blob}
176173
resp = await AsyncRequest(
177174
config=self.config,
178175
path=path,
179176
params=options,
180177
data=blob,
181-
headers=headers,
178+
files=files,
182179
verb="post",
183180
).perform_with_content()
184181
return resp

0 commit comments

Comments
 (0)