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
8 changes: 8 additions & 0 deletions src/openai/_legacy_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class MyModel(BaseModel):
- `list`
- `Union`
- `str`
- `int`
- `float`
- `httpx.Response`
"""
cache_key = to if to is not None else self._cast_to
Expand Down Expand Up @@ -220,6 +222,12 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T:
if cast_to == str:
return cast(R, response.text)

if cast_to == int:
return cast(R, int(response.text))

if cast_to == float:
return cast(R, float(response.text))

origin = get_origin(cast_to) or cast_to

if inspect.isclass(origin) and issubclass(origin, HttpxBinaryResponseContent):
Expand Down
8 changes: 8 additions & 0 deletions src/openai/_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T:
if cast_to == bytes:
return cast(R, response.content)

if cast_to == int:
return cast(R, int(response.text))

if cast_to == float:
return cast(R, float(response.text))

origin = get_origin(cast_to) or cast_to

# handle the legacy binary response case
Expand Down Expand Up @@ -277,6 +283,8 @@ class MyModel(BaseModel):
- `list`
- `Union`
- `str`
- `int`
- `float`
- `httpx.Response`
"""
cache_key = to if to is not None else self._cast_to
Expand Down