From 586688c4a023535e613bbb4ef5f00fdd5edcc1c5 Mon Sep 17 00:00:00 2001 From: Sander Land Date: Fri, 15 Sep 2023 10:00:25 +0200 Subject: [PATCH 1/2] fix attribute error in cohereapierror --- cohere/client_async.py | 8 +++++--- cohere/error.py | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cohere/client_async.py b/cohere/client_async.py index f95e944a7..56e9f2b43 100644 --- a/cohere/client_async.py +++ b/cohere/client_async.py @@ -113,11 +113,13 @@ async def _request( try: json_response = await response.json() - # `CohereAPIError.from_response()` will capture the http status code + # `CohereAPIError.from_aio_response()` will capture the http status code except jsonlib.decoder.JSONDecodeError: - raise CohereAPIError.from_response(response, message=f"Failed to decode json body: {await response.text()}") + raise CohereAPIError.from_aio_response( + response, message=f"Failed to decode json body: {await response.text()}" + ) except aiohttp.ClientPayloadError as e: - raise CohereAPIError.from_response( + raise CohereAPIError.from_aio_response( response, message=f"An unexpected error occurred while receiving the response: {e}" ) diff --git a/cohere/error.py b/cohere/error.py index 3681bd35d..18c1afe1a 100644 --- a/cohere/error.py +++ b/cohere/error.py @@ -29,6 +29,10 @@ def __init__(self, message: str = None, http_status: int = None, headers: Dict = def from_response(cls, response, message=None): return cls(message=message or response.text, http_status=response.status_code, headers=response.headers) + @classmethod + def from_aio_response(cls, response, message): + return cls(message=message, http_status=response.status, headers=response.headers) + def __repr__(self) -> str: return f"{self.__class__.__name__}(message={str(self)}, http_status={self.http_status})" From 5603f8183cdcdb61687712898ecc2522ea689cf5 Mon Sep 17 00:00:00 2001 From: Sander Land Date: Fri, 15 Sep 2023 10:02:19 +0200 Subject: [PATCH 2/2] bump --- CHANGELOG.md | 5 +++++ pyproject.toml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f88fb240f..cea2eaa9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 4.26.1 + +- [#306] (https://github.com/cohere-ai/cohere-python/pull/306) + - AsyncClient: Fix correctly raising error on connection issues. + ## 4.26 - [#296] (https://github.com/cohere-ai/cohere-python/pull/301) diff --git a/pyproject.toml b/pyproject.toml index 8b1695d12..cf3f915a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cohere" -version = "4.26" +version = "4.26.1" description = "" authors = ["Cohere"] readme = "README.md"