Skip to content

release: 1.7.1 #1061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 10, 2024
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
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "1.7.0"
".": "1.7.1"
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 1.7.1 (2024-01-10)

Full Changelog: [v1.7.0...v1.7.1](https://github.com/openai/openai-python/compare/v1.7.0...v1.7.1)

### Chores

* **client:** improve debug logging for failed requests ([#1060](https://github.com/openai/openai-python/issues/1060)) ([cf9a651](https://github.com/openai/openai-python/commit/cf9a6517b4aa0f24bcbe143c54ea908d43dfda92))

## 1.7.0 (2024-01-08)

Full Changelog: [v1.6.1...v1.7.0](https://github.com/openai/openai-python/compare/v1.6.1...v1.7.0)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "openai"
version = "1.7.0"
version = "1.7.1"
description = "The official Python library for the openai API"
readme = "README.md"
license = "Apache-2.0"
Expand Down
35 changes: 35 additions & 0 deletions src/openai/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,26 +646,33 @@ def _should_retry(self, response: httpx.Response) -> bool:

# If the server explicitly says whether or not to retry, obey.
if should_retry_header == "true":
log.debug("Retrying as header `x-should-retry` is set to `true`")
return True
if should_retry_header == "false":
log.debug("Not retrying as header `x-should-retry` is set to `false`")
return False

# Retry on request timeouts.
if response.status_code == 408:
log.debug("Retrying due to status code %i", response.status_code)
return True

# Retry on lock timeouts.
if response.status_code == 409:
log.debug("Retrying due to status code %i", response.status_code)
return True

# Retry on rate limits.
if response.status_code == 429:
log.debug("Retrying due to status code %i", response.status_code)
return True

# Retry internal errors.
if response.status_code >= 500:
log.debug("Retrying due to status code %i", response.status_code)
return True

log.debug("Not retrying")
return False

def _idempotency_key(self) -> str:
Expand Down Expand Up @@ -883,6 +890,8 @@ def _request(
**kwargs,
)
except httpx.TimeoutException as err:
log.debug("Encountered httpx.TimeoutException", exc_info=True)

if retries > 0:
return self._retry_request(
options,
Expand All @@ -893,8 +902,11 @@ def _request(
response_headers=None,
)

log.debug("Raising timeout error")
raise APITimeoutError(request=request) from err
except Exception as err:
log.debug("Encountered Exception", exc_info=True)

if retries > 0:
return self._retry_request(
options,
Expand All @@ -905,6 +917,7 @@ def _request(
response_headers=None,
)

log.debug("Raising connection error")
raise APIConnectionError(request=request) from err

log.debug(
Expand All @@ -914,6 +927,8 @@ def _request(
try:
response.raise_for_status()
except httpx.HTTPStatusError as err: # thrown on 4xx and 5xx status code
log.debug("Encountered httpx.HTTPStatusError", exc_info=True)

if retries > 0 and self._should_retry(err.response):
err.response.close()
return self._retry_request(
Expand All @@ -930,6 +945,7 @@ def _request(
if not err.response.is_closed:
err.response.read()

log.debug("Re-raising status error")
raise self._make_status_error_from_response(err.response) from None

return self._process_response(
Expand All @@ -951,6 +967,11 @@ def _retry_request(
stream_cls: type[_StreamT] | None,
) -> ResponseT | _StreamT:
remaining = remaining_retries - 1
if remaining == 1:
log.debug("1 retry left")
else:
log.debug("%i retries left", remaining)

timeout = self._calculate_retry_timeout(remaining, options, response_headers)
log.info("Retrying request to %s in %f seconds", options.url, timeout)

Expand Down Expand Up @@ -1349,6 +1370,8 @@ async def _request(
**kwargs,
)
except httpx.TimeoutException as err:
log.debug("Encountered httpx.TimeoutException", exc_info=True)

if retries > 0:
return await self._retry_request(
options,
Expand All @@ -1359,8 +1382,11 @@ async def _request(
response_headers=None,
)

log.debug("Raising timeout error")
raise APITimeoutError(request=request) from err
except Exception as err:
log.debug("Encountered Exception", exc_info=True)

if retries > 0:
return await self._retry_request(
options,
Expand All @@ -1371,6 +1397,7 @@ async def _request(
response_headers=None,
)

log.debug("Raising connection error")
raise APIConnectionError(request=request) from err

log.debug(
Expand All @@ -1380,6 +1407,8 @@ async def _request(
try:
response.raise_for_status()
except httpx.HTTPStatusError as err: # thrown on 4xx and 5xx status code
log.debug("Encountered httpx.HTTPStatusError", exc_info=True)

if retries > 0 and self._should_retry(err.response):
await err.response.aclose()
return await self._retry_request(
Expand All @@ -1396,6 +1425,7 @@ async def _request(
if not err.response.is_closed:
await err.response.aread()

log.debug("Re-raising status error")
raise self._make_status_error_from_response(err.response) from None

return self._process_response(
Expand All @@ -1417,6 +1447,11 @@ async def _retry_request(
stream_cls: type[_AsyncStreamT] | None,
) -> ResponseT | _AsyncStreamT:
remaining = remaining_retries - 1
if remaining == 1:
log.debug("1 retry left")
else:
log.debug("%i retries left", remaining)

timeout = self._calculate_retry_timeout(remaining, options, response_headers)
log.info("Retrying request to %s in %f seconds", options.url, timeout)

Expand Down
2 changes: 1 addition & 1 deletion src/openai/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless.

__title__ = "openai"
__version__ = "1.7.0" # x-release-please-version
__version__ = "1.7.1" # x-release-please-version