diff --git a/poetry.lock b/poetry.lock index 8b3115ffa..c6cf6e8f0 100644 --- a/poetry.lock +++ b/poetry.lock @@ -38,17 +38,17 @@ trio = ["trio (>=0.23)"] [[package]] name = "boto3" -version = "1.34.110" +version = "1.34.111" description = "The AWS SDK for Python" optional = false python-versions = ">=3.8" files = [ - {file = "boto3-1.34.110-py3-none-any.whl", hash = "sha256:2fc871b4a5090716c7a71af52c462e539529227f4d4888fd04896d5028f9cedc"}, - {file = "boto3-1.34.110.tar.gz", hash = "sha256:83ffe2273da7bdfdb480d85b0705f04e95bd110e9741f23328b7c76c03e6d53c"}, + {file = "boto3-1.34.111-py3-none-any.whl", hash = "sha256:d6a8e77db316c6e1d9a25f77c795ed1e0a8bc621f863ce26d04b2225d30f2dce"}, + {file = "boto3-1.34.111.tar.gz", hash = "sha256:8f18d212b9199dbbd9d596dd5929685b583ac938c60cceeac2e045c0c5d10323"}, ] [package.dependencies] -botocore = ">=1.34.110,<1.35.0" +botocore = ">=1.34.111,<1.35.0" jmespath = ">=0.7.1,<2.0.0" s3transfer = ">=0.10.0,<0.11.0" @@ -57,13 +57,13 @@ crt = ["botocore[crt] (>=1.21.0,<2.0a0)"] [[package]] name = "botocore" -version = "1.34.110" +version = "1.34.111" description = "Low-level, data-driven core of boto 3." optional = false python-versions = ">=3.8" files = [ - {file = "botocore-1.34.110-py3-none-any.whl", hash = "sha256:1edf3a825ec0a5edf238b2d42ad23305de11d5a71bb27d6f9a58b7e8862df1b6"}, - {file = "botocore-1.34.110.tar.gz", hash = "sha256:b2c98c40ecf0b1facb9e61ceb7dfa28e61ae2456490554a16c8dbf99f20d6a18"}, + {file = "botocore-1.34.111-py3-none-any.whl", hash = "sha256:e10affb7f372d50da957260adf2753a3f153bf90abe6910e11f09d1e443b5515"}, + {file = "botocore-1.34.111.tar.gz", hash = "sha256:0e0fb9b605c46393d5c7c69bd516b36058334bdc8f389e680c6efcf0727f25db"}, ] [package.dependencies] @@ -978,13 +978,13 @@ types-urllib3 = "*" [[package]] name = "types-requests" -version = "2.32.0.20240521" +version = "2.32.0.20240523" description = "Typing stubs for requests" optional = false python-versions = ">=3.8" files = [ - {file = "types-requests-2.32.0.20240521.tar.gz", hash = "sha256:c5c4a0ae95aad51f1bf6dae9eed04a78f7f2575d4b171da37b622e08b93eb5d3"}, - {file = "types_requests-2.32.0.20240521-py3-none-any.whl", hash = "sha256:ab728ba43ffb073db31f21202ecb97db8753ded4a9dc49cb480d8a5350c5c421"}, + {file = "types-requests-2.32.0.20240523.tar.gz", hash = "sha256:26b8a6de32d9f561192b9942b41c0ab2d8010df5677ca8aa146289d11d505f57"}, + {file = "types_requests-2.32.0.20240523-py3-none-any.whl", hash = "sha256:f19ed0e2daa74302069bbbbf9e82902854ffa780bc790742a810a9aaa52f65ec"}, ] [package.dependencies] diff --git a/pyproject.toml b/pyproject.toml index aec2a8be9..9af742aa1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cohere" -version = "5.5.2" +version = "5.5.3" description = "" readme = "README.md" authors = [] diff --git a/src/cohere/base_client.py b/src/cohere/base_client.py index 5191aa06a..3e7b1b1a6 100644 --- a/src/cohere/base_client.py +++ b/src/cohere/base_client.py @@ -65,7 +65,7 @@ class BaseCohere: """ - Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propogate to these functions. + Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions. Parameters ---------- @@ -164,7 +164,7 @@ def chat_stream( ) -> typing.Iterator[StreamedChatResponse]: """ Generates a text response to a user message. - To learn how to use Chat with Streaming and RAG follow [this guide](https://docs.cohere.com/docs/cochat-beta#various-ways-of-using-the-chat-endpoint). + To learn how to use the Chat API with Streaming and RAG follow our [Text Generation guides](https://docs.cohere.com/docs/chat-api). Parameters ---------- @@ -460,7 +460,7 @@ def chat_stream( for chunk in response: yield chunk """ - _request: typing.Dict[str, typing.Any] = {"message": message} + _request: typing.Dict[str, typing.Any] = {"message": message, "stream": True} if model is not OMIT: _request["model"] = model if preamble is not OMIT: @@ -583,7 +583,7 @@ def chat( ) -> NonStreamedChatResponse: """ Generates a text response to a user message. - To learn how to use Chat with Streaming and RAG follow [this guide](https://docs.cohere.com/docs/cochat-beta#various-ways-of-using-the-chat-endpoint). + To learn how to use the Chat API with Streaming and RAG follow our [Text Generation guides](https://docs.cohere.com/docs/chat-api). Parameters ---------- @@ -803,7 +803,7 @@ def chat( temperature=0.3, ) """ - _request: typing.Dict[str, typing.Any] = {"message": message} + _request: typing.Dict[str, typing.Any] = {"message": message, "stream": False} if model is not OMIT: _request["model"] = model if preamble is not OMIT: @@ -1038,7 +1038,7 @@ def generate_stream( for chunk in response: yield chunk """ - _request: typing.Dict[str, typing.Any] = {"prompt": prompt} + _request: typing.Dict[str, typing.Any] = {"prompt": prompt, "stream": True} if model is not OMIT: _request["model"] = model if num_generations is not OMIT: @@ -1253,7 +1253,7 @@ def generate( prompt="Please explain to me how LLMs work", ) """ - _request: typing.Dict[str, typing.Any] = {"prompt": prompt} + _request: typing.Dict[str, typing.Any] = {"prompt": prompt, "stream": False} if model is not OMIT: _request["model"] = model if num_generations is not OMIT: @@ -2084,7 +2084,7 @@ def check_api_key(self, *, request_options: typing.Optional[RequestOptions] = No class AsyncBaseCohere: """ - Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propogate to these functions. + Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions. Parameters ---------- @@ -2183,7 +2183,7 @@ async def chat_stream( ) -> typing.AsyncIterator[StreamedChatResponse]: """ Generates a text response to a user message. - To learn how to use Chat with Streaming and RAG follow [this guide](https://docs.cohere.com/docs/cochat-beta#various-ways-of-using-the-chat-endpoint). + To learn how to use the Chat API with Streaming and RAG follow our [Text Generation guides](https://docs.cohere.com/docs/chat-api). Parameters ---------- @@ -2479,7 +2479,7 @@ async def chat_stream( async for chunk in response: yield chunk """ - _request: typing.Dict[str, typing.Any] = {"message": message} + _request: typing.Dict[str, typing.Any] = {"message": message, "stream": True} if model is not OMIT: _request["model"] = model if preamble is not OMIT: @@ -2602,7 +2602,7 @@ async def chat( ) -> NonStreamedChatResponse: """ Generates a text response to a user message. - To learn how to use Chat with Streaming and RAG follow [this guide](https://docs.cohere.com/docs/cochat-beta#various-ways-of-using-the-chat-endpoint). + To learn how to use the Chat API with Streaming and RAG follow our [Text Generation guides](https://docs.cohere.com/docs/chat-api). Parameters ---------- @@ -2822,7 +2822,7 @@ async def chat( temperature=0.3, ) """ - _request: typing.Dict[str, typing.Any] = {"message": message} + _request: typing.Dict[str, typing.Any] = {"message": message, "stream": False} if model is not OMIT: _request["model"] = model if preamble is not OMIT: @@ -3057,7 +3057,7 @@ async def generate_stream( async for chunk in response: yield chunk """ - _request: typing.Dict[str, typing.Any] = {"prompt": prompt} + _request: typing.Dict[str, typing.Any] = {"prompt": prompt, "stream": True} if model is not OMIT: _request["model"] = model if num_generations is not OMIT: @@ -3272,7 +3272,7 @@ async def generate( prompt="Please explain to me how LLMs work", ) """ - _request: typing.Dict[str, typing.Any] = {"prompt": prompt} + _request: typing.Dict[str, typing.Any] = {"prompt": prompt, "stream": False} if model is not OMIT: _request["model"] = model if num_generations is not OMIT: diff --git a/src/cohere/connectors/client.py b/src/cohere/connectors/client.py index fade0fc58..645c5431f 100644 --- a/src/cohere/connectors/client.py +++ b/src/cohere/connectors/client.py @@ -362,6 +362,9 @@ def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = request_options.get("additional_query_parameters") if request_options is not None else None ) ), + json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) + if request_options is not None + else None, headers=jsonable_encoder( remove_none_from_dict( { @@ -968,6 +971,9 @@ async def delete( request_options.get("additional_query_parameters") if request_options is not None else None ) ), + json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) + if request_options is not None + else None, headers=jsonable_encoder( remove_none_from_dict( { diff --git a/src/cohere/core/client_wrapper.py b/src/cohere/core/client_wrapper.py index bd61ac44e..cdd79ad33 100644 --- a/src/cohere/core/client_wrapper.py +++ b/src/cohere/core/client_wrapper.py @@ -25,7 +25,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.5.2", + "X-Fern-SDK-Version": "5.5.3", } if self._client_name is not None: headers["X-Client-Name"] = self._client_name diff --git a/src/cohere/core/unchecked_base_model.py b/src/cohere/core/unchecked_base_model.py index 5c56f25ae..425320df3 100644 --- a/src/cohere/core/unchecked_base_model.py +++ b/src/cohere/core/unchecked_base_model.py @@ -8,7 +8,7 @@ import typing_extensions from .datetime_utils import serialize_datetime -from .pydantic_utilities import pydantic_v1 +from .pydantic_utilities import IS_PYDANTIC_V2, pydantic_v1 class UnionMetadata: @@ -60,6 +60,7 @@ def construct( else: type_ = typing.cast(typing.Type, field.outer_type_) # type: ignore fields_values[name] = construct_type(object_=values[key], type_=type_) + _fields_set.add(name) elif not field.required: default = field.get_default() fields_values[name] = default @@ -71,10 +72,19 @@ def construct( _fields_set.add(key) # Add extras back in + _extra = {} for key, value in values.items(): - if key not in cls.__fields__: - _fields_set.add(key) - fields_values[key] = value + if key not in _fields_set: + _extra[key] = value + # In v2 we'll need to exclude extra fields from fields_values + if not IS_PYDANTIC_V2: + _fields_set.add(key) + fields_values[key] = value + + if IS_PYDANTIC_V2: + object.__setattr__(m, "__pydantic_private__", None) + object.__setattr__(m, "__pydantic_extra__", _extra) + object.__setattr__(m, "__pydantic_fields_set__", _fields_set) object.__setattr__(m, "__dict__", fields_values) object.__setattr__(m, "__fields_set__", _fields_set) @@ -144,8 +154,12 @@ def construct_type(*, type_: typing.Type[typing.Any], object_: typing.Any) -> ty if not isinstance(object_, typing.Mapping): return object_ - _, items_type = pydantic_v1.typing.get_args(type_) - return {key: construct_type(object_=item, type_=items_type) for key, item in object_.items()} + key_type, items_type = pydantic_v1.typing.get_args(type_) + d = { + construct_type(object_=key, type_=key_type): construct_type(object_=item, type_=items_type) + for key, item in object_.items() + } + return d if base_type == list: if not isinstance(object_, list): @@ -190,4 +204,20 @@ def construct_type(*, type_: typing.Type[typing.Any], object_: typing.Any) -> ty except Exception: return object_ + if base_type == int: + try: + return int(object_) + except Exception: + return object_ + + if base_type == bool: + try: + if isinstance(object_, str): + stringified_object = object_.lower() + return stringified_object == "true" or stringified_object == "1" + + return bool(object_) + except Exception: + return object_ + return object_ diff --git a/src/cohere/datasets/client.py b/src/cohere/datasets/client.py index 34b959533..e20b8d0e1 100644 --- a/src/cohere/datasets/client.py +++ b/src/cohere/datasets/client.py @@ -422,6 +422,9 @@ def delete( request_options.get("additional_query_parameters") if request_options is not None else None ) ), + json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) + if request_options is not None + else None, headers=jsonable_encoder( remove_none_from_dict( { @@ -844,6 +847,9 @@ async def delete( request_options.get("additional_query_parameters") if request_options is not None else None ) ), + json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) + if request_options is not None + else None, headers=jsonable_encoder( remove_none_from_dict( { diff --git a/src/cohere/finetuning/client.py b/src/cohere/finetuning/client.py index 04681bd46..8afb2de13 100644 --- a/src/cohere/finetuning/client.py +++ b/src/cohere/finetuning/client.py @@ -368,6 +368,9 @@ def delete_finetuned_model( request_options.get("additional_query_parameters") if request_options is not None else None ) ), + json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) + if request_options is not None + else None, headers=jsonable_encoder( remove_none_from_dict( { @@ -1127,6 +1130,9 @@ async def delete_finetuned_model( request_options.get("additional_query_parameters") if request_options is not None else None ) ), + json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) + if request_options is not None + else None, headers=jsonable_encoder( remove_none_from_dict( {