Commit ff8154f8
Changed files (2)
src
src/openai/_legacy_response.py
@@ -107,6 +107,8 @@ class LegacyAPIResponse(Generic[R]):
- `list`
- `Union`
- `str`
+ - `int`
+ - `float`
- `httpx.Response`
"""
cache_key = to if to is not None else self._cast_to
@@ -220,6 +222,12 @@ class LegacyAPIResponse(Generic[R]):
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):
src/openai/_response.py
@@ -172,6 +172,12 @@ class BaseAPIResponse(Generic[R]):
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
@@ -277,6 +283,8 @@ class APIResponse(BaseAPIResponse[R]):
- `list`
- `Union`
- `str`
+ - `int`
+ - `float`
- `httpx.Response`
"""
cache_key = to if to is not None else self._cast_to