diff --git a/pyproject.toml b/pyproject.toml index 8d0b8072b..f2b80c00e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cohere" -version = "5.13.1" +version = "5.13.2" description = "" readme = "README.md" authors = [] diff --git a/src/cohere/aws_client.py b/src/cohere/aws_client.py index 26ce11514..8aea9d15c 100644 --- a/src/cohere/aws_client.py +++ b/src/cohere/aws_client.py @@ -196,6 +196,13 @@ def _hook( return _hook +def get_boto3_session( + **kwargs: typing.Any, +): + non_none_args = {k: v for k, v in kwargs.items() if v is not None} + return lazy_boto3().Session(**non_none_args) + + def map_request_to_bedrock( service: str, @@ -204,14 +211,15 @@ def map_request_to_bedrock( aws_session_token: typing.Optional[str] = None, aws_region: typing.Optional[str] = None, ) -> EventHook: - session = lazy_boto3().Session( + session = get_boto3_session( region_name=aws_region, aws_access_key_id=aws_access_key, aws_secret_access_key=aws_secret_key, aws_session_token=aws_session_token, ) + aws_region = session.region_name credentials = session.get_credentials() - signer = lazy_botocore().auth.SigV4Auth(credentials, service, session.region_name) + signer = lazy_botocore().auth.SigV4Auth(credentials, service, aws_region) def _event_hook(request: httpx.Request) -> None: headers = request.headers.copy() diff --git a/src/cohere/core/client_wrapper.py b/src/cohere/core/client_wrapper.py index fcc6933d6..9fb4430e7 100644 --- a/src/cohere/core/client_wrapper.py +++ b/src/cohere/core/client_wrapper.py @@ -24,7 +24,7 @@ def get_headers(self) -> typing.Dict[str, str]: headers: typing.Dict[str, str] = { "X-Fern-Language": "Python", "X-Fern-SDK-Name": "cohere", - "X-Fern-SDK-Version": "5.13.1", + "X-Fern-SDK-Version": "5.13.2", } if self._client_name is not None: headers["X-Client-Name"] = self._client_name diff --git a/src/cohere/sagemaker_client.py b/src/cohere/sagemaker_client.py index 84d20a2ac..77f9f9115 100644 --- a/src/cohere/sagemaker_client.py +++ b/src/cohere/sagemaker_client.py @@ -26,7 +26,10 @@ def __init__( aws_region=aws_region, timeout=timeout, ) - self.sagemaker_finetuning = Client(aws_region=aws_region) + try: + self.sagemaker_finetuning = Client(aws_region=aws_region) + except Exception: + pass class SagemakerClientV2(AwsClientV2): @@ -50,4 +53,7 @@ def __init__( aws_region=aws_region, timeout=timeout, ) - self.sagemaker_finetuning = Client(aws_region=aws_region) \ No newline at end of file + try: + self.sagemaker_finetuning = Client(aws_region=aws_region) + except Exception: + pass \ No newline at end of file diff --git a/tests/test_client_init.py b/tests/test_client_init.py new file mode 100644 index 000000000..9783b2540 --- /dev/null +++ b/tests/test_client_init.py @@ -0,0 +1,16 @@ +import os +import typing +import unittest + +import cohere +from cohere import ToolMessage, UserMessage, AssistantMessage + +class TestClientInit(unittest.TestCase): + def test_inits(self) -> None: + cohere.BedrockClient() + cohere.BedrockClientV2() + cohere.SagemakerClient() + cohere.SagemakerClientV2() + cohere.Client(api_key="n/a") + cohere.ClientV2(api_key="n/a") +