Skip to content

Commit 260c761

Browse files
fix(client): correctly parse binary response | stream
1 parent 25017c4 commit 260c761

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/finch/_base_client.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,14 @@ def _process_response(
10861086

10871087
origin = get_origin(cast_to) or cast_to
10881088

1089-
if inspect.isclass(origin) and issubclass(origin, BaseAPIResponse):
1089+
if (
1090+
inspect.isclass(origin)
1091+
and issubclass(origin, BaseAPIResponse)
1092+
# we only want to actually return the custom BaseAPIResponse class if we're
1093+
# returning the raw response, or if we're not streaming SSE, as if we're streaming
1094+
# SSE then `cast_to` doesn't actively reflect the type we need to parse into
1095+
and (not stream or bool(response.request.headers.get(RAW_RESPONSE_HEADER)))
1096+
):
10901097
if not issubclass(origin, APIResponse):
10911098
raise TypeError(f"API Response types must subclass {APIResponse}; Received {origin}")
10921099

@@ -1603,7 +1610,14 @@ async def _process_response(
16031610

16041611
origin = get_origin(cast_to) or cast_to
16051612

1606-
if inspect.isclass(origin) and issubclass(origin, BaseAPIResponse):
1613+
if (
1614+
inspect.isclass(origin)
1615+
and issubclass(origin, BaseAPIResponse)
1616+
# we only want to actually return the custom BaseAPIResponse class if we're
1617+
# returning the raw response, or if we're not streaming SSE, as if we're streaming
1618+
# SSE then `cast_to` doesn't actively reflect the type we need to parse into
1619+
and (not stream or bool(response.request.headers.get(RAW_RESPONSE_HEADER)))
1620+
):
16071621
if not issubclass(origin, AsyncAPIResponse):
16081622
raise TypeError(f"API Response types must subclass {AsyncAPIResponse}; Received {origin}")
16091623

0 commit comments

Comments
 (0)