Skip to content

Commit 55872c2

Browse files
fix(client): correctly parse binary response | stream
1 parent 6c8b5ad commit 55872c2

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/writerai/_base_client.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,14 @@ def _process_response(
10741074
) -> ResponseT:
10751075
origin = get_origin(cast_to) or cast_to
10761076

1077-
if inspect.isclass(origin) and issubclass(origin, BaseAPIResponse):
1077+
if (
1078+
inspect.isclass(origin)
1079+
and issubclass(origin, BaseAPIResponse)
1080+
# we only want to actually return the custom BaseAPIResponse class if we're
1081+
# returning the raw response, or if we're not streaming SSE, as if we're streaming
1082+
# SSE then `cast_to` doesn't actively reflect the type we need to parse into
1083+
and (not stream or bool(response.request.headers.get(RAW_RESPONSE_HEADER)))
1084+
):
10781085
if not issubclass(origin, APIResponse):
10791086
raise TypeError(f"API Response types must subclass {APIResponse}; Received {origin}")
10801087

@@ -1586,7 +1593,14 @@ async def _process_response(
15861593
) -> ResponseT:
15871594
origin = get_origin(cast_to) or cast_to
15881595

1589-
if inspect.isclass(origin) and issubclass(origin, BaseAPIResponse):
1596+
if (
1597+
inspect.isclass(origin)
1598+
and issubclass(origin, BaseAPIResponse)
1599+
# we only want to actually return the custom BaseAPIResponse class if we're
1600+
# returning the raw response, or if we're not streaming SSE, as if we're streaming
1601+
# SSE then `cast_to` doesn't actively reflect the type we need to parse into
1602+
and (not stream or bool(response.request.headers.get(RAW_RESPONSE_HEADER)))
1603+
):
15901604
if not issubclass(origin, AsyncAPIResponse):
15911605
raise TypeError(f"API Response types must subclass {AsyncAPIResponse}; Received {origin}")
15921606

0 commit comments

Comments
 (0)