From 2c493eb71ffbc11b49130098eb0b53f0c516ba8d Mon Sep 17 00:00:00 2001 From: "fern-api[bot]" <115122769+fern-api[bot]@users.noreply.github.com> Date: Thu, 4 Apr 2024 16:38:21 -0500 Subject: [PATCH] SDK regeneration (#460) Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com> --- poetry.lock | 2 +- pyproject.toml | 6 +- src/cohere/base_client.py | 144 +++++++------ src/cohere/connectors/client.py | 130 ++++++----- src/cohere/core/__init__.py | 2 + src/cohere/core/client_wrapper.py | 2 +- src/cohere/core/jsonable_encoder.py | 10 +- src/cohere/core/pydantic_utilities.py | 12 ++ src/cohere/datasets/client.py | 46 ++-- .../types/datasets_create_response.py | 12 +- .../datasets/types/datasets_get_response.py | 10 +- .../types/datasets_get_usage_response.py | 12 +- .../datasets/types/datasets_list_response.py | 10 +- src/cohere/embed_jobs/client.py | 74 +++---- src/cohere/finetuning/client.py | 202 +++++++++--------- .../finetuning/finetuning/types/base_model.py | 18 +- .../types/create_finetuned_model_response.py | 12 +- .../finetuning/finetuning/types/error.py | 12 +- .../finetuning/finetuning/types/event.py | 16 +- .../finetuning/types/finetuned_model.py | 30 ++- .../types/get_finetuned_model_response.py | 12 +- .../finetuning/types/hyperparameters.py | 20 +- .../finetuning/types/list_events_response.py | 16 +- .../types/list_finetuned_models_response.py | 16 +- .../list_training_step_metrics_response.py | 14 +- .../finetuning/finetuning/types/settings.py | 18 +- .../finetuning/types/training_step_metrics.py | 16 +- .../types/update_finetuned_model_response.py | 12 +- src/cohere/models/client.py | 30 ++- src/cohere/types/api_meta.py | 10 +- src/cohere/types/api_meta_api_version.py | 10 +- src/cohere/types/api_meta_billed_units.py | 18 +- src/cohere/types/chat_citation.py | 18 +- .../types/chat_citation_generation_event.py | 10 +- src/cohere/types/chat_connector.py | 18 +- src/cohere/types/chat_data_metrics.py | 16 +- src/cohere/types/chat_message.py | 14 +- .../chat_request_connectors_search_options.py | 12 +- .../types/chat_request_tool_results_item.py | 10 +- .../chat_search_queries_generation_event.py | 10 +- src/cohere/types/chat_search_query.py | 14 +- src/cohere/types/chat_search_result.py | 18 +- .../types/chat_search_result_connector.py | 12 +- src/cohere/types/chat_search_results_event.py | 12 +- src/cohere/types/chat_stream_end_event.py | 12 +- src/cohere/types/chat_stream_event.py | 10 +- ...tream_request_connectors_search_options.py | 12 +- .../chat_stream_request_tool_results_item.py | 10 +- src/cohere/types/chat_stream_start_event.py | 10 +- .../types/chat_text_generation_event.py | 10 +- .../types/chat_tool_calls_generation_event.py | 8 +- src/cohere/types/classify_data_metrics.py | 12 +- src/cohere/types/classify_example.py | 10 +- src/cohere/types/classify_response.py | 10 +- .../classify_response_classifications_item.py | 24 +-- ...ponse_classifications_item_labels_value.py | 10 +- src/cohere/types/connector.py | 36 ++-- src/cohere/types/connector_o_auth.py | 20 +- src/cohere/types/create_connector_o_auth.py | 20 +- src/cohere/types/create_connector_response.py | 10 +- .../types/create_connector_service_auth.py | 12 +- src/cohere/types/create_embed_job_response.py | 10 +- src/cohere/types/dataset.py | 26 +-- src/cohere/types/dataset_part.py | 24 +-- src/cohere/types/detokenize_response.py | 12 +- src/cohere/types/embed_by_type_response.py | 14 +- .../embed_by_type_response_embeddings.py | 20 +- src/cohere/types/embed_floats_response.py | 14 +- src/cohere/types/embed_job.py | 26 +-- src/cohere/types/embed_response.py | 4 +- src/cohere/types/finetune_dataset_metrics.py | 22 +- src/cohere/types/generate_stream_end.py | 8 +- .../types/generate_stream_end_response.py | 10 +- src/cohere/types/generate_stream_error.py | 12 +- src/cohere/types/generate_stream_event.py | 10 +- src/cohere/types/generate_stream_text.py | 12 +- .../types/generate_streamed_response.py | 6 +- src/cohere/types/generation.py | 14 +- src/cohere/types/get_connector_response.py | 10 +- src/cohere/types/get_model_response.py | 22 +- src/cohere/types/label_metric.py | 16 +- src/cohere/types/list_connectors_response.py | 12 +- src/cohere/types/list_embed_job_response.py | 10 +- src/cohere/types/list_models_response.py | 12 +- src/cohere/types/metrics.py | 10 +- .../types/non_streamed_chat_response.py | 26 +-- src/cohere/types/o_auth_authorize_response.py | 12 +- src/cohere/types/parse_info.py | 10 +- .../rerank_request_documents_item_text.py | 12 +- src/cohere/types/rerank_response.py | 12 +- .../types/rerank_response_results_item.py | 16 +- .../rerank_response_results_item_document.py | 12 +- src/cohere/types/reranker_data_metrics.py | 24 +-- src/cohere/types/single_generation.py | 16 +- .../types/single_generation_in_stream.py | 14 +- ...ingle_generation_token_likelihoods_item.py | 10 +- src/cohere/types/streamed_chat_response.py | 14 +- src/cohere/types/summarize_response.py | 14 +- src/cohere/types/tokenize_response.py | 12 +- src/cohere/types/tool.py | 16 +- src/cohere/types/tool_call.py | 14 +- .../types/tool_parameter_definitions_value.py | 16 +- src/cohere/types/update_connector_response.py | 10 +- 103 files changed, 799 insertions(+), 1151 deletions(-) create mode 100644 src/cohere/core/pydantic_utilities.py diff --git a/poetry.lock b/poetry.lock index d0893caa8..97f643052 100644 --- a/poetry.lock +++ b/poetry.lock @@ -934,4 +934,4 @@ zstd = ["zstandard (>=0.18.0)"] [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "aac1cd0da57fbafcdf93eba927cba28bb037d3df2b9f88973681d18fe65967f2" +content-hash = "84fe943faec6b1d96dbd10e09f5b25cd3f292c9ad386de452057644c3e5ea254" diff --git a/pyproject.toml b/pyproject.toml index c5f51f598..e903ed669 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cohere" -version = "5.2.1" +version = "5.2.2" description = "" readme = "README.md" authors = [] @@ -13,9 +13,9 @@ python = "^3.8" fastavro = "^1.9.4" httpx = ">=0.21.2" pydantic = ">= 1.9.2" -requests = "^2.31.0" +requests = "^2.0.0" tokenizers = "^0.15.2" -types-requests = "^2.31.0.20240311" +types-requests = "^2.0.0" typing_extensions = ">= 4.0.0" [tool.poetry.dev-dependencies] diff --git a/src/cohere/base_client.py b/src/cohere/base_client.py index fc681b931..3a18df675 100644 --- a/src/cohere/base_client.py +++ b/src/cohere/base_client.py @@ -12,6 +12,7 @@ from .core.api_error import ApiError from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from .core.jsonable_encoder import jsonable_encoder +from .core.pydantic_utilities import pydantic_v1 from .core.remove_none_from_dict import remove_none_from_dict from .core.request_options import RequestOptions from .datasets.client import AsyncDatasetsClient, DatasetsClient @@ -54,11 +55,6 @@ from .types.tokenize_response import TokenizeResponse from .types.tool import Tool -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - # this is used as the default value for optional parameters OMIT = typing.cast(typing.Any, ...) @@ -80,6 +76,8 @@ class BaseCohere: - timeout: typing.Optional[float]. The timeout to be used, in seconds, for requests by default the timeout is 60 seconds, unless a custom httpx client is used, in which case a default is not set. + - follow_redirects: typing.Optional[bool]. Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in. + - httpx_client: typing.Optional[httpx.Client]. The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration. --- from cohere.client import Client @@ -98,6 +96,7 @@ def __init__( client_name: typing.Optional[str] = None, token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = os.getenv("CO_API_KEY"), timeout: typing.Optional[float] = None, + follow_redirects: typing.Optional[bool] = None, httpx_client: typing.Optional[httpx.Client] = None, ): _defaulted_timeout = timeout if timeout is not None else 300 if httpx_client is None else None @@ -107,7 +106,11 @@ def __init__( base_url=_get_base_url(base_url=base_url, environment=environment), client_name=client_name, token=token, - httpx_client=httpx.Client(timeout=_defaulted_timeout) if httpx_client is None else httpx_client, + httpx_client=httpx_client + if httpx_client is not None + else httpx.Client(timeout=_defaulted_timeout, follow_redirects=follow_redirects) + if follow_redirects is not None + else httpx.Client(timeout=_defaulted_timeout), timeout=_defaulted_timeout, ) self.embed_jobs = EmbedJobsClient(client_wrapper=self._client_wrapper) @@ -402,11 +405,11 @@ def chat_stream( for _text in _response.iter_lines(): if len(_text) == 0: continue - yield pydantic.parse_obj_as(StreamedChatResponse, json.loads(_text)) # type: ignore + yield pydantic_v1.parse_obj_as(StreamedChatResponse, json.loads(_text)) # type: ignore return _response.read() if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -644,9 +647,9 @@ def chat( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(NonStreamedChatResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(NonStreamedChatResponse, _response.json()) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -823,15 +826,15 @@ def generate_stream( for _text in _response.iter_lines(): if len(_text) == 0: continue - yield pydantic.parse_obj_as(GenerateStreamedResponse, json.loads(_text)) # type: ignore + yield pydantic_v1.parse_obj_as(GenerateStreamedResponse, json.loads(_text)) # type: ignore return _response.read() if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -991,13 +994,13 @@ def generate( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(Generation, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(Generation, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -1104,13 +1107,13 @@ def embed( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(EmbedResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(EmbedResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -1203,9 +1206,9 @@ def rerank( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(RerankResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(RerankResponse, _response.json()) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -1329,13 +1332,13 @@ def classify( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(ClassifyResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(ClassifyResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -1428,9 +1431,9 @@ def summarize( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(SummarizeResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(SummarizeResponse, _response.json()) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -1488,13 +1491,13 @@ def tokenize( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(TokenizeResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(TokenizeResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -1552,9 +1555,9 @@ def detokenize( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(DetokenizeResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(DetokenizeResponse, _response.json()) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -1579,6 +1582,8 @@ class AsyncBaseCohere: - timeout: typing.Optional[float]. The timeout to be used, in seconds, for requests by default the timeout is 60 seconds, unless a custom httpx client is used, in which case a default is not set. + - follow_redirects: typing.Optional[bool]. Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in. + - httpx_client: typing.Optional[httpx.AsyncClient]. The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration. --- from cohere.client import AsyncClient @@ -1597,6 +1602,7 @@ def __init__( client_name: typing.Optional[str] = None, token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = os.getenv("CO_API_KEY"), timeout: typing.Optional[float] = None, + follow_redirects: typing.Optional[bool] = None, httpx_client: typing.Optional[httpx.AsyncClient] = None, ): _defaulted_timeout = timeout if timeout is not None else 300 if httpx_client is None else None @@ -1606,7 +1612,11 @@ def __init__( base_url=_get_base_url(base_url=base_url, environment=environment), client_name=client_name, token=token, - httpx_client=httpx.AsyncClient(timeout=_defaulted_timeout) if httpx_client is None else httpx_client, + httpx_client=httpx_client + if httpx_client is not None + else httpx.AsyncClient(timeout=_defaulted_timeout, follow_redirects=follow_redirects) + if follow_redirects is not None + else httpx.AsyncClient(timeout=_defaulted_timeout), timeout=_defaulted_timeout, ) self.embed_jobs = AsyncEmbedJobsClient(client_wrapper=self._client_wrapper) @@ -1901,11 +1911,11 @@ async def chat_stream( async for _text in _response.aiter_lines(): if len(_text) == 0: continue - yield pydantic.parse_obj_as(StreamedChatResponse, json.loads(_text)) # type: ignore + yield pydantic_v1.parse_obj_as(StreamedChatResponse, json.loads(_text)) # type: ignore return await _response.aread() if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -2143,9 +2153,9 @@ async def chat( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(NonStreamedChatResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(NonStreamedChatResponse, _response.json()) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -2322,15 +2332,15 @@ async def generate_stream( async for _text in _response.aiter_lines(): if len(_text) == 0: continue - yield pydantic.parse_obj_as(GenerateStreamedResponse, json.loads(_text)) # type: ignore + yield pydantic_v1.parse_obj_as(GenerateStreamedResponse, json.loads(_text)) # type: ignore return await _response.aread() if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -2490,13 +2500,13 @@ async def generate( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(Generation, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(Generation, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -2603,13 +2613,13 @@ async def embed( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(EmbedResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(EmbedResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -2702,9 +2712,9 @@ async def rerank( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(RerankResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(RerankResponse, _response.json()) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -2828,13 +2838,13 @@ async def classify( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(ClassifyResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(ClassifyResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -2927,9 +2937,9 @@ async def summarize( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(SummarizeResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(SummarizeResponse, _response.json()) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -2987,13 +2997,13 @@ async def tokenize( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(TokenizeResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(TokenizeResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -3051,9 +3061,9 @@ async def detokenize( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(DetokenizeResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(DetokenizeResponse, _response.json()) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: diff --git a/src/cohere/connectors/client.py b/src/cohere/connectors/client.py index 57b4bba61..4c896cd62 100644 --- a/src/cohere/connectors/client.py +++ b/src/cohere/connectors/client.py @@ -7,6 +7,7 @@ from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ..core.jsonable_encoder import jsonable_encoder +from ..core.pydantic_utilities import pydantic_v1 from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..errors.bad_request_error import BadRequestError @@ -23,11 +24,6 @@ from ..types.o_auth_authorize_response import OAuthAuthorizeResponse from ..types.update_connector_response import UpdateConnectorResponse -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - # this is used as the default value for optional parameters OMIT = typing.cast(typing.Any, ...) @@ -92,13 +88,13 @@ def list( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(ListConnectorsResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(ListConnectorsResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -191,15 +187,15 @@ def create( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(CreateConnectorResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(CreateConnectorResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 403: - raise ForbiddenError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise ForbiddenError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -246,15 +242,15 @@ def get(self, id: str, *, request_options: typing.Optional[RequestOptions] = Non max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(GetConnectorResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(GetConnectorResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -301,17 +297,17 @@ def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(DeleteConnectorResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(DeleteConnectorResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 403: - raise ForbiddenError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise ForbiddenError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -405,17 +401,17 @@ def update( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(UpdateConnectorResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(UpdateConnectorResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 403: - raise ForbiddenError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise ForbiddenError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -484,15 +480,15 @@ def o_auth_authorize( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(OAuthAuthorizeResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(OAuthAuthorizeResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -560,13 +556,13 @@ async def list( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(ListConnectorsResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(ListConnectorsResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -659,15 +655,15 @@ async def create( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(CreateConnectorResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(CreateConnectorResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 403: - raise ForbiddenError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise ForbiddenError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -714,15 +710,15 @@ async def get(self, id: str, *, request_options: typing.Optional[RequestOptions] max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(GetConnectorResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(GetConnectorResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -771,17 +767,17 @@ async def delete( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(DeleteConnectorResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(DeleteConnectorResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 403: - raise ForbiddenError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise ForbiddenError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -875,17 +871,17 @@ async def update( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(UpdateConnectorResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(UpdateConnectorResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 403: - raise ForbiddenError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise ForbiddenError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -954,15 +950,15 @@ async def o_auth_authorize( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(OAuthAuthorizeResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(OAuthAuthorizeResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: diff --git a/src/cohere/core/__init__.py b/src/cohere/core/__init__.py index b3e43c228..78a7f80fb 100644 --- a/src/cohere/core/__init__.py +++ b/src/cohere/core/__init__.py @@ -6,6 +6,7 @@ from .file import File, convert_file_dict_to_httpx_tuples from .http_client import AsyncHttpClient, HttpClient from .jsonable_encoder import jsonable_encoder +from .pydantic_utilities import pydantic_v1 from .remove_none_from_dict import remove_none_from_dict from .request_options import RequestOptions @@ -20,6 +21,7 @@ "SyncClientWrapper", "convert_file_dict_to_httpx_tuples", "jsonable_encoder", + "pydantic_v1", "remove_none_from_dict", "serialize_datetime", ] diff --git a/src/cohere/core/client_wrapper.py b/src/cohere/core/client_wrapper.py index f0acebbf8..5d0dd6958 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.2.1", + "X-Fern-SDK-Version": "5.2.2", } if self._client_name is not None: headers["X-Client-Name"] = self._client_name diff --git a/src/cohere/core/jsonable_encoder.py b/src/cohere/core/jsonable_encoder.py index 81fa99fbd..7f4827326 100644 --- a/src/cohere/core/jsonable_encoder.py +++ b/src/cohere/core/jsonable_encoder.py @@ -16,16 +16,8 @@ from types import GeneratorType from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union -import pydantic - from .datetime_utils import serialize_datetime - -IS_PYDANTIC_V2 = pydantic.VERSION.startswith("2.") - -if IS_PYDANTIC_V2: - import pydantic.v1 as pydantic_v1 # type: ignore -else: - import pydantic as pydantic_v1 # type: ignore +from .pydantic_utilities import pydantic_v1 SetIntStr = Set[Union[int, str]] DictIntStrAny = Dict[Union[int, str], Any] diff --git a/src/cohere/core/pydantic_utilities.py b/src/cohere/core/pydantic_utilities.py new file mode 100644 index 000000000..952b5f2a8 --- /dev/null +++ b/src/cohere/core/pydantic_utilities.py @@ -0,0 +1,12 @@ +# This file was auto-generated by Fern from our API Definition. + +import pydantic + +IS_PYDANTIC_V2 = pydantic.VERSION.startswith("2.") + +if IS_PYDANTIC_V2: + import pydantic.v1 as pydantic_v1 # type: ignore # nopycln: import +else: + import pydantic as pydantic_v1 # type: ignore # nopycln: import + +__all__ = ["pydantic_v1"] diff --git a/src/cohere/datasets/client.py b/src/cohere/datasets/client.py index 6fc9451ec..051141f66 100644 --- a/src/cohere/datasets/client.py +++ b/src/cohere/datasets/client.py @@ -10,6 +10,7 @@ from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ..core.datetime_utils import serialize_datetime from ..core.jsonable_encoder import jsonable_encoder +from ..core.pydantic_utilities import pydantic_v1 from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..errors.too_many_requests_error import TooManyRequestsError @@ -19,11 +20,6 @@ from .types.datasets_get_usage_response import DatasetsGetUsageResponse from .types.datasets_list_response import DatasetsListResponse -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - # this is used as the default value for optional parameters OMIT = typing.cast(typing.Any, ...) @@ -100,9 +96,9 @@ def list( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(DatasetsListResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(DatasetsListResponse, _response.json()) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -211,9 +207,9 @@ def create( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(DatasetsCreateResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(DatasetsCreateResponse, _response.json()) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -256,9 +252,9 @@ def get_usage(self, *, request_options: typing.Optional[RequestOptions] = None) max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(DatasetsGetUsageResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(DatasetsGetUsageResponse, _response.json()) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -305,9 +301,9 @@ def get(self, id: str, *, request_options: typing.Optional[RequestOptions] = Non max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(DatasetsGetResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(DatasetsGetResponse, _response.json()) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -356,9 +352,9 @@ def delete( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(typing.Dict[str, typing.Any], _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(typing.Dict[str, typing.Any], _response.json()) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -438,9 +434,9 @@ async def list( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(DatasetsListResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(DatasetsListResponse, _response.json()) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -549,9 +545,9 @@ async def create( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(DatasetsCreateResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(DatasetsCreateResponse, _response.json()) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -594,9 +590,9 @@ async def get_usage(self, *, request_options: typing.Optional[RequestOptions] = max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(DatasetsGetUsageResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(DatasetsGetUsageResponse, _response.json()) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -643,9 +639,9 @@ async def get(self, id: str, *, request_options: typing.Optional[RequestOptions] max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(DatasetsGetResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(DatasetsGetResponse, _response.json()) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -694,9 +690,9 @@ async def delete( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(typing.Dict[str, typing.Any], _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(typing.Dict[str, typing.Any], _response.json()) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: diff --git a/src/cohere/datasets/types/datasets_create_response.py b/src/cohere/datasets/types/datasets_create_response.py index 76dd46168..62a93a655 100644 --- a/src/cohere/datasets/types/datasets_create_response.py +++ b/src/cohere/datasets/types/datasets_create_response.py @@ -4,15 +4,11 @@ import typing from ...core.datetime_utils import serialize_datetime +from ...core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class DatasetsCreateResponse(pydantic.BaseModel): - id: typing.Optional[str] = pydantic.Field(default=None) +class DatasetsCreateResponse(pydantic_v1.BaseModel): + id: typing.Optional[str] = pydantic_v1.Field(default=None) """ The dataset ID """ @@ -28,5 +24,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/datasets/types/datasets_get_response.py b/src/cohere/datasets/types/datasets_get_response.py index 96e0637de..dc7d9e9ff 100644 --- a/src/cohere/datasets/types/datasets_get_response.py +++ b/src/cohere/datasets/types/datasets_get_response.py @@ -4,15 +4,11 @@ import typing from ...core.datetime_utils import serialize_datetime +from ...core.pydantic_utilities import pydantic_v1 from ...types.dataset import Dataset -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class DatasetsGetResponse(pydantic.BaseModel): +class DatasetsGetResponse(pydantic_v1.BaseModel): dataset: Dataset def json(self, **kwargs: typing.Any) -> str: @@ -26,5 +22,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/datasets/types/datasets_get_usage_response.py b/src/cohere/datasets/types/datasets_get_usage_response.py index bc0a6cf22..792968e92 100644 --- a/src/cohere/datasets/types/datasets_get_usage_response.py +++ b/src/cohere/datasets/types/datasets_get_usage_response.py @@ -4,15 +4,11 @@ import typing from ...core.datetime_utils import serialize_datetime +from ...core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class DatasetsGetUsageResponse(pydantic.BaseModel): - organization_usage: typing.Optional[str] = pydantic.Field(default=None) +class DatasetsGetUsageResponse(pydantic_v1.BaseModel): + organization_usage: typing.Optional[str] = pydantic_v1.Field(default=None) """ The total number of bytes used by the organization. """ @@ -28,5 +24,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/datasets/types/datasets_list_response.py b/src/cohere/datasets/types/datasets_list_response.py index 335d6f525..20039ee49 100644 --- a/src/cohere/datasets/types/datasets_list_response.py +++ b/src/cohere/datasets/types/datasets_list_response.py @@ -4,15 +4,11 @@ import typing from ...core.datetime_utils import serialize_datetime +from ...core.pydantic_utilities import pydantic_v1 from ...types.dataset import Dataset -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class DatasetsListResponse(pydantic.BaseModel): +class DatasetsListResponse(pydantic_v1.BaseModel): datasets: typing.Optional[typing.List[Dataset]] = None def json(self, **kwargs: typing.Any) -> str: @@ -26,5 +22,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/embed_jobs/client.py b/src/cohere/embed_jobs/client.py index 85946cb5c..112357880 100644 --- a/src/cohere/embed_jobs/client.py +++ b/src/cohere/embed_jobs/client.py @@ -7,6 +7,7 @@ from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ..core.jsonable_encoder import jsonable_encoder +from ..core.pydantic_utilities import pydantic_v1 from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..errors.bad_request_error import BadRequestError @@ -20,11 +21,6 @@ from ..types.list_embed_job_response import ListEmbedJobResponse from .types.create_embed_job_request_truncate import CreateEmbedJobRequestTruncate -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - # this is used as the default value for optional parameters OMIT = typing.cast(typing.Any, ...) @@ -69,13 +65,13 @@ def list(self, *, request_options: typing.Optional[RequestOptions] = None) -> Li max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(ListEmbedJobResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(ListEmbedJobResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -171,13 +167,13 @@ def create( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(CreateEmbedJobResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(CreateEmbedJobResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -224,15 +220,15 @@ def get(self, id: str, *, request_options: typing.Optional[RequestOptions] = Non max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(EmbedJob, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(EmbedJob, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -286,13 +282,13 @@ def cancel(self, id: str, *, request_options: typing.Optional[RequestOptions] = if 200 <= _response.status_code < 300: return if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -340,13 +336,13 @@ async def list(self, *, request_options: typing.Optional[RequestOptions] = None) max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(ListEmbedJobResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(ListEmbedJobResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -442,13 +438,13 @@ async def create( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(CreateEmbedJobResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(CreateEmbedJobResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -495,15 +491,15 @@ async def get(self, id: str, *, request_options: typing.Optional[RequestOptions] max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(EmbedJob, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(EmbedJob, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -557,13 +553,13 @@ async def cancel(self, id: str, *, request_options: typing.Optional[RequestOptio if 200 <= _response.status_code < 300: return if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: diff --git a/src/cohere/finetuning/client.py b/src/cohere/finetuning/client.py index 8b08024c7..036fe47c8 100644 --- a/src/cohere/finetuning/client.py +++ b/src/cohere/finetuning/client.py @@ -8,6 +8,7 @@ from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ..core.jsonable_encoder import jsonable_encoder +from ..core.pydantic_utilities import pydantic_v1 from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..errors.bad_request_error import BadRequestError @@ -28,11 +29,6 @@ from .finetuning.types.status import Status from .finetuning.types.update_finetuned_model_response import UpdateFinetunedModelResponse -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - # this is used as the default value for optional parameters OMIT = typing.cast(typing.Any, ...) @@ -104,19 +100,19 @@ def list_finetuned_models( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(ListFinetunedModelsResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(ListFinetunedModelsResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 401: - raise UnauthorizedError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise UnauthorizedError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore if _response.status_code == 403: - raise ForbiddenError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise ForbiddenError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 503: - raise ServiceUnavailableError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise ServiceUnavailableError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -178,19 +174,19 @@ def create_finetuned_model( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(CreateFinetunedModelResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(CreateFinetunedModelResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 401: - raise UnauthorizedError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise UnauthorizedError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore if _response.status_code == 403: - raise ForbiddenError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise ForbiddenError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 503: - raise ServiceUnavailableError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise ServiceUnavailableError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -239,19 +235,19 @@ def get_finetuned_model( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(GetFinetunedModelResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(GetFinetunedModelResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 401: - raise UnauthorizedError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise UnauthorizedError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore if _response.status_code == 403: - raise ForbiddenError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise ForbiddenError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 503: - raise ServiceUnavailableError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise ServiceUnavailableError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -300,19 +296,19 @@ def delete_finetuned_model( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(DeleteFinetunedModelResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(DeleteFinetunedModelResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 401: - raise UnauthorizedError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise UnauthorizedError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore if _response.status_code == 403: - raise ForbiddenError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise ForbiddenError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 503: - raise ServiceUnavailableError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise ServiceUnavailableError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -420,19 +416,19 @@ def update_finetuned_model( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(UpdateFinetunedModelResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(UpdateFinetunedModelResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 401: - raise UnauthorizedError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise UnauthorizedError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore if _response.status_code == 403: - raise ForbiddenError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise ForbiddenError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 503: - raise ServiceUnavailableError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise ServiceUnavailableError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -510,19 +506,19 @@ def list_events( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(ListEventsResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(ListEventsResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 401: - raise UnauthorizedError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise UnauthorizedError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore if _response.status_code == 403: - raise ForbiddenError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise ForbiddenError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 503: - raise ServiceUnavailableError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise ServiceUnavailableError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -591,19 +587,19 @@ def list_training_step_metrics( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(ListTrainingStepMetricsResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(ListTrainingStepMetricsResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 401: - raise UnauthorizedError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise UnauthorizedError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore if _response.status_code == 403: - raise ForbiddenError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise ForbiddenError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 503: - raise ServiceUnavailableError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise ServiceUnavailableError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -678,19 +674,19 @@ async def list_finetuned_models( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(ListFinetunedModelsResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(ListFinetunedModelsResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 401: - raise UnauthorizedError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise UnauthorizedError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore if _response.status_code == 403: - raise ForbiddenError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise ForbiddenError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 503: - raise ServiceUnavailableError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise ServiceUnavailableError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -752,19 +748,19 @@ async def create_finetuned_model( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(CreateFinetunedModelResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(CreateFinetunedModelResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 401: - raise UnauthorizedError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise UnauthorizedError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore if _response.status_code == 403: - raise ForbiddenError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise ForbiddenError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 503: - raise ServiceUnavailableError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise ServiceUnavailableError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -813,19 +809,19 @@ async def get_finetuned_model( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(GetFinetunedModelResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(GetFinetunedModelResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 401: - raise UnauthorizedError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise UnauthorizedError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore if _response.status_code == 403: - raise ForbiddenError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise ForbiddenError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 503: - raise ServiceUnavailableError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise ServiceUnavailableError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -874,19 +870,19 @@ async def delete_finetuned_model( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(DeleteFinetunedModelResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(DeleteFinetunedModelResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 401: - raise UnauthorizedError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise UnauthorizedError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore if _response.status_code == 403: - raise ForbiddenError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise ForbiddenError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 503: - raise ServiceUnavailableError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise ServiceUnavailableError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -994,19 +990,19 @@ async def update_finetuned_model( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(UpdateFinetunedModelResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(UpdateFinetunedModelResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 401: - raise UnauthorizedError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise UnauthorizedError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore if _response.status_code == 403: - raise ForbiddenError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise ForbiddenError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 503: - raise ServiceUnavailableError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise ServiceUnavailableError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -1084,19 +1080,19 @@ async def list_events( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(ListEventsResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(ListEventsResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 401: - raise UnauthorizedError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise UnauthorizedError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore if _response.status_code == 403: - raise ForbiddenError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise ForbiddenError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 503: - raise ServiceUnavailableError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise ServiceUnavailableError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -1165,19 +1161,19 @@ async def list_training_step_metrics( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(ListTrainingStepMetricsResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(ListTrainingStepMetricsResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 401: - raise UnauthorizedError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise UnauthorizedError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore if _response.status_code == 403: - raise ForbiddenError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise ForbiddenError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 404: - raise NotFoundError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise NotFoundError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 503: - raise ServiceUnavailableError(pydantic.parse_obj_as(Error, _response.json())) # type: ignore + raise ServiceUnavailableError(pydantic_v1.parse_obj_as(Error, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: diff --git a/src/cohere/finetuning/finetuning/types/base_model.py b/src/cohere/finetuning/finetuning/types/base_model.py index 2bafa60da..bdd499a17 100644 --- a/src/cohere/finetuning/finetuning/types/base_model.py +++ b/src/cohere/finetuning/finetuning/types/base_model.py @@ -4,36 +4,32 @@ import typing from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import pydantic_v1 from .base_type import BaseType from .strategy import Strategy -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class BaseModel(pydantic.BaseModel): +class BaseModel(pydantic_v1.BaseModel): """ The base model used for fine-tuning. """ - name: typing.Optional[str] = pydantic.Field(default=None) + name: typing.Optional[str] = pydantic_v1.Field(default=None) """ The name of the base model. """ - version: typing.Optional[str] = pydantic.Field(default=None) + version: typing.Optional[str] = pydantic_v1.Field(default=None) """ read-only. The version of the base model. """ - base_type: BaseType = pydantic.Field() + base_type: BaseType = pydantic_v1.Field() """ The type of the base model. """ - strategy: typing.Optional[Strategy] = pydantic.Field(default=None) + strategy: typing.Optional[Strategy] = pydantic_v1.Field(default=None) """ The fine-tuning strategy. """ @@ -49,5 +45,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/finetuning/finetuning/types/create_finetuned_model_response.py b/src/cohere/finetuning/finetuning/types/create_finetuned_model_response.py index db8de8b81..e285431f8 100644 --- a/src/cohere/finetuning/finetuning/types/create_finetuned_model_response.py +++ b/src/cohere/finetuning/finetuning/types/create_finetuned_model_response.py @@ -4,20 +4,16 @@ import typing from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import pydantic_v1 from .finetuned_model import FinetunedModel -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class CreateFinetunedModelResponse(pydantic.BaseModel): +class CreateFinetunedModelResponse(pydantic_v1.BaseModel): """ Response to request to create a fine-tuned model. """ - finetuned_model: typing.Optional[FinetunedModel] = pydantic.Field(default=None) + finetuned_model: typing.Optional[FinetunedModel] = pydantic_v1.Field(default=None) """ Information about the fine-tuned model. """ @@ -33,5 +29,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/finetuning/finetuning/types/error.py b/src/cohere/finetuning/finetuning/types/error.py index 5fa6c6b54..63a10cc0f 100644 --- a/src/cohere/finetuning/finetuning/types/error.py +++ b/src/cohere/finetuning/finetuning/types/error.py @@ -4,19 +4,15 @@ import typing from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class Error(pydantic.BaseModel): +class Error(pydantic_v1.BaseModel): """ Error is the response for any unsuccessful event. """ - message: typing.Optional[str] = pydantic.Field(default=None) + message: typing.Optional[str] = pydantic_v1.Field(default=None) """ A developer-facing error message. """ @@ -32,5 +28,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/finetuning/finetuning/types/event.py b/src/cohere/finetuning/finetuning/types/event.py index f3ad95ea2..f442c530b 100644 --- a/src/cohere/finetuning/finetuning/types/event.py +++ b/src/cohere/finetuning/finetuning/types/event.py @@ -4,30 +4,26 @@ import typing from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import pydantic_v1 from .status import Status -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class Event(pydantic.BaseModel): +class Event(pydantic_v1.BaseModel): """ A change in status of a fine-tuned model. """ - user_id: typing.Optional[str] = pydantic.Field(default=None) + user_id: typing.Optional[str] = pydantic_v1.Field(default=None) """ ID of the user who initiated the event. Empty if initiated by the system. """ - status: typing.Optional[Status] = pydantic.Field(default=None) + status: typing.Optional[Status] = pydantic_v1.Field(default=None) """ Status of the fine-tuned model. """ - created_at: typing.Optional[dt.datetime] = pydantic.Field(default=None) + created_at: typing.Optional[dt.datetime] = pydantic_v1.Field(default=None) """ Timestamp when the event happened. """ @@ -43,5 +39,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/finetuning/finetuning/types/finetuned_model.py b/src/cohere/finetuning/finetuning/types/finetuned_model.py index 82aa92846..3f57c6f85 100644 --- a/src/cohere/finetuning/finetuning/types/finetuned_model.py +++ b/src/cohere/finetuning/finetuning/types/finetuned_model.py @@ -4,66 +4,62 @@ import typing from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import pydantic_v1 from .settings import Settings from .status import Status -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class FinetunedModel(pydantic.BaseModel): +class FinetunedModel(pydantic_v1.BaseModel): """ This resource represents a fine-tuned model. """ - id: typing.Optional[str] = pydantic.Field(default=None) + id: typing.Optional[str] = pydantic_v1.Field(default=None) """ read-only. FinetunedModel ID. """ - name: str = pydantic.Field() + name: str = pydantic_v1.Field() """ FinetunedModel name (e.g. `foobar`). """ - creator_id: typing.Optional[str] = pydantic.Field(default=None) + creator_id: typing.Optional[str] = pydantic_v1.Field(default=None) """ read-only. User ID of the creator. """ - organization_id: typing.Optional[str] = pydantic.Field(default=None) + organization_id: typing.Optional[str] = pydantic_v1.Field(default=None) """ read-only. Organization ID. """ - settings: Settings = pydantic.Field() + settings: Settings = pydantic_v1.Field() """ FinetunedModel settings such as dataset, hyperparameters... """ - status: typing.Optional[Status] = pydantic.Field(default=None) + status: typing.Optional[Status] = pydantic_v1.Field(default=None) """ read-only. Current stage in the life-cycle of the fine-tuned model. """ - created_at: typing.Optional[dt.datetime] = pydantic.Field(default=None) + created_at: typing.Optional[dt.datetime] = pydantic_v1.Field(default=None) """ read-only. Creation timestamp. """ - updated_at: typing.Optional[dt.datetime] = pydantic.Field(default=None) + updated_at: typing.Optional[dt.datetime] = pydantic_v1.Field(default=None) """ read-only. Latest update timestamp. """ - completed_at: typing.Optional[dt.datetime] = pydantic.Field(default=None) + completed_at: typing.Optional[dt.datetime] = pydantic_v1.Field(default=None) """ read-only. Timestamp for the completed fine-tuning. """ - last_used: typing.Optional[dt.datetime] = pydantic.Field(default=None) + last_used: typing.Optional[dt.datetime] = pydantic_v1.Field(default=None) """ read-only. Timestamp for the latest request to this fine-tuned model. """ @@ -79,5 +75,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/finetuning/finetuning/types/get_finetuned_model_response.py b/src/cohere/finetuning/finetuning/types/get_finetuned_model_response.py index d39250c49..e820ca795 100644 --- a/src/cohere/finetuning/finetuning/types/get_finetuned_model_response.py +++ b/src/cohere/finetuning/finetuning/types/get_finetuned_model_response.py @@ -4,20 +4,16 @@ import typing from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import pydantic_v1 from .finetuned_model import FinetunedModel -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class GetFinetunedModelResponse(pydantic.BaseModel): +class GetFinetunedModelResponse(pydantic_v1.BaseModel): """ Response to a request to get a fine-tuned model. """ - finetuned_model: typing.Optional[FinetunedModel] = pydantic.Field(default=None) + finetuned_model: typing.Optional[FinetunedModel] = pydantic_v1.Field(default=None) """ Information about the fine-tuned model. """ @@ -33,5 +29,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/finetuning/finetuning/types/hyperparameters.py b/src/cohere/finetuning/finetuning/types/hyperparameters.py index 5aa941a08..f39f20101 100644 --- a/src/cohere/finetuning/finetuning/types/hyperparameters.py +++ b/src/cohere/finetuning/finetuning/types/hyperparameters.py @@ -4,41 +4,37 @@ import typing from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class Hyperparameters(pydantic.BaseModel): +class Hyperparameters(pydantic_v1.BaseModel): """ The fine-tuning hyperparameters. """ - early_stopping_patience: typing.Optional[int] = pydantic.Field(default=None) + early_stopping_patience: typing.Optional[int] = pydantic_v1.Field(default=None) """ Stops training if the loss metric does not improve beyond the value of `early_stopping_threshold` after this many times of evaluation. """ - early_stopping_threshold: typing.Optional[float] = pydantic.Field(default=None) + early_stopping_threshold: typing.Optional[float] = pydantic_v1.Field(default=None) """ How much the loss must improve to prevent early stopping. """ - train_batch_size: typing.Optional[int] = pydantic.Field(default=None) + train_batch_size: typing.Optional[int] = pydantic_v1.Field(default=None) """ The batch size is the number of training examples included in a single training pass. """ - train_epochs: typing.Optional[int] = pydantic.Field(default=None) + train_epochs: typing.Optional[int] = pydantic_v1.Field(default=None) """ The number of epochs to train for. """ - learning_rate: typing.Optional[float] = pydantic.Field(default=None) + learning_rate: typing.Optional[float] = pydantic_v1.Field(default=None) """ The learning rate to be used during training. """ @@ -54,5 +50,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/finetuning/finetuning/types/list_events_response.py b/src/cohere/finetuning/finetuning/types/list_events_response.py index cce797403..df5d30fc4 100644 --- a/src/cohere/finetuning/finetuning/types/list_events_response.py +++ b/src/cohere/finetuning/finetuning/types/list_events_response.py @@ -4,31 +4,27 @@ import typing from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import pydantic_v1 from .event import Event -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ListEventsResponse(pydantic.BaseModel): +class ListEventsResponse(pydantic_v1.BaseModel): """ Response to a request to list events of a fine-tuned model. """ - events: typing.Optional[typing.List[Event]] = pydantic.Field(default=None) + events: typing.Optional[typing.List[Event]] = pydantic_v1.Field(default=None) """ List of events for the fine-tuned model. """ - next_page_token: typing.Optional[str] = pydantic.Field(default=None) + next_page_token: typing.Optional[str] = pydantic_v1.Field(default=None) """ Pagination token to retrieve the next page of results. If the value is "", it means no further results for the request. """ - total_size: typing.Optional[int] = pydantic.Field(default=None) + total_size: typing.Optional[int] = pydantic_v1.Field(default=None) """ Total count of results. """ @@ -44,5 +40,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/finetuning/finetuning/types/list_finetuned_models_response.py b/src/cohere/finetuning/finetuning/types/list_finetuned_models_response.py index 3ba23475f..7a69524e2 100644 --- a/src/cohere/finetuning/finetuning/types/list_finetuned_models_response.py +++ b/src/cohere/finetuning/finetuning/types/list_finetuned_models_response.py @@ -4,31 +4,27 @@ import typing from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import pydantic_v1 from .finetuned_model import FinetunedModel -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ListFinetunedModelsResponse(pydantic.BaseModel): +class ListFinetunedModelsResponse(pydantic_v1.BaseModel): """ Response to a request to list fine-tuned models. """ - finetuned_models: typing.Optional[typing.List[FinetunedModel]] = pydantic.Field(default=None) + finetuned_models: typing.Optional[typing.List[FinetunedModel]] = pydantic_v1.Field(default=None) """ List of fine-tuned models matching the request. """ - next_page_token: typing.Optional[str] = pydantic.Field(default=None) + next_page_token: typing.Optional[str] = pydantic_v1.Field(default=None) """ Pagination token to retrieve the next page of results. If the value is "", it means no further results for the request. """ - total_size: typing.Optional[int] = pydantic.Field(default=None) + total_size: typing.Optional[int] = pydantic_v1.Field(default=None) """ Total count of results. """ @@ -44,5 +40,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/finetuning/finetuning/types/list_training_step_metrics_response.py b/src/cohere/finetuning/finetuning/types/list_training_step_metrics_response.py index 27218ed9c..485c2d3e7 100644 --- a/src/cohere/finetuning/finetuning/types/list_training_step_metrics_response.py +++ b/src/cohere/finetuning/finetuning/types/list_training_step_metrics_response.py @@ -4,25 +4,21 @@ import typing from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import pydantic_v1 from .training_step_metrics import TrainingStepMetrics -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ListTrainingStepMetricsResponse(pydantic.BaseModel): +class ListTrainingStepMetricsResponse(pydantic_v1.BaseModel): """ Response to a request to list training-step metrics of a fine-tuned model. """ - step_metrics: typing.Optional[typing.List[TrainingStepMetrics]] = pydantic.Field(default=None) + step_metrics: typing.Optional[typing.List[TrainingStepMetrics]] = pydantic_v1.Field(default=None) """ The metrics for each step the evaluation was run on. """ - next_page_token: typing.Optional[str] = pydantic.Field(default=None) + next_page_token: typing.Optional[str] = pydantic_v1.Field(default=None) """ Pagination token to retrieve the next page of results. If the value is "", it means no further results for the request. @@ -39,5 +35,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/finetuning/finetuning/types/settings.py b/src/cohere/finetuning/finetuning/types/settings.py index a7ed6e321..040ae09a2 100644 --- a/src/cohere/finetuning/finetuning/types/settings.py +++ b/src/cohere/finetuning/finetuning/types/settings.py @@ -4,36 +4,32 @@ import typing from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import pydantic_v1 from .base_model import BaseModel from .hyperparameters import Hyperparameters -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class Settings(pydantic.BaseModel): +class Settings(pydantic_v1.BaseModel): """ The configuration used for fine-tuning. """ - base_model: BaseModel = pydantic.Field() + base_model: BaseModel = pydantic_v1.Field() """ The base model to fine-tune. """ - dataset_id: str = pydantic.Field() + dataset_id: str = pydantic_v1.Field() """ The data used for training and evaluating the fine-tuned model. """ - hyperparameters: typing.Optional[Hyperparameters] = pydantic.Field(default=None) + hyperparameters: typing.Optional[Hyperparameters] = pydantic_v1.Field(default=None) """ Fine-tuning hyper-parameters. """ - multi_label: typing.Optional[bool] = pydantic.Field(default=None) + multi_label: typing.Optional[bool] = pydantic_v1.Field(default=None) """ read-only. Whether the model is single-label or multi-label (only for classification). """ @@ -49,5 +45,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/finetuning/finetuning/types/training_step_metrics.py b/src/cohere/finetuning/finetuning/types/training_step_metrics.py index 7bc7a63d6..8ac8f4364 100644 --- a/src/cohere/finetuning/finetuning/types/training_step_metrics.py +++ b/src/cohere/finetuning/finetuning/types/training_step_metrics.py @@ -4,29 +4,25 @@ import typing from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class TrainingStepMetrics(pydantic.BaseModel): +class TrainingStepMetrics(pydantic_v1.BaseModel): """ The evaluation metrics at a given step of the training of a fine-tuned model. """ - created_at: typing.Optional[dt.datetime] = pydantic.Field(default=None) + created_at: typing.Optional[dt.datetime] = pydantic_v1.Field(default=None) """ Creation timestamp. """ - step_number: typing.Optional[int] = pydantic.Field(default=None) + step_number: typing.Optional[int] = pydantic_v1.Field(default=None) """ Step number. """ - metrics: typing.Optional[typing.Dict[str, float]] = pydantic.Field(default=None) + metrics: typing.Optional[typing.Dict[str, float]] = pydantic_v1.Field(default=None) """ Map of names and values for each evaluation metrics. """ @@ -42,5 +38,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/finetuning/finetuning/types/update_finetuned_model_response.py b/src/cohere/finetuning/finetuning/types/update_finetuned_model_response.py index 2615ace14..b640403e6 100644 --- a/src/cohere/finetuning/finetuning/types/update_finetuned_model_response.py +++ b/src/cohere/finetuning/finetuning/types/update_finetuned_model_response.py @@ -4,20 +4,16 @@ import typing from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import pydantic_v1 from .finetuned_model import FinetunedModel -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class UpdateFinetunedModelResponse(pydantic.BaseModel): +class UpdateFinetunedModelResponse(pydantic_v1.BaseModel): """ Response to a request to update a fine-tuned model. """ - finetuned_model: typing.Optional[FinetunedModel] = pydantic.Field(default=None) + finetuned_model: typing.Optional[FinetunedModel] = pydantic_v1.Field(default=None) """ Information about the fine-tuned model. """ @@ -33,5 +29,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/models/client.py b/src/cohere/models/client.py index 0e944692b..72b4117ce 100644 --- a/src/cohere/models/client.py +++ b/src/cohere/models/client.py @@ -7,6 +7,7 @@ from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ..core.jsonable_encoder import jsonable_encoder +from ..core.pydantic_utilities import pydantic_v1 from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..errors.bad_request_error import BadRequestError @@ -16,11 +17,6 @@ from ..types.get_model_response import GetModelResponse from ..types.list_models_response import ListModelsResponse -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - class ModelsClient: def __init__(self, *, client_wrapper: SyncClientWrapper): @@ -66,13 +62,13 @@ def get(self, model: str, *, request_options: typing.Optional[RequestOptions] = max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(GetModelResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(GetModelResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -139,9 +135,9 @@ def list( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(ListModelsResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(ListModelsResponse, _response.json()) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -193,13 +189,13 @@ async def get(self, model: str, *, request_options: typing.Optional[RequestOptio max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(GetModelResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(GetModelResponse, _response.json()) # type: ignore if _response.status_code == 400: - raise BadRequestError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise BadRequestError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore if _response.status_code == 500: - raise InternalServerError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise InternalServerError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: @@ -266,9 +262,9 @@ async def list( max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore ) if 200 <= _response.status_code < 300: - return pydantic.parse_obj_as(ListModelsResponse, _response.json()) # type: ignore + return pydantic_v1.parse_obj_as(ListModelsResponse, _response.json()) # type: ignore if _response.status_code == 429: - raise TooManyRequestsError(pydantic.parse_obj_as(typing.Any, _response.json())) # type: ignore + raise TooManyRequestsError(pydantic_v1.parse_obj_as(typing.Any, _response.json())) # type: ignore try: _response_json = _response.json() except JSONDecodeError: diff --git a/src/cohere/types/api_meta.py b/src/cohere/types/api_meta.py index 5fac069a0..8cc07bcb1 100644 --- a/src/cohere/types/api_meta.py +++ b/src/cohere/types/api_meta.py @@ -4,16 +4,12 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .api_meta_api_version import ApiMetaApiVersion from .api_meta_billed_units import ApiMetaBilledUnits -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ApiMeta(pydantic.BaseModel): +class ApiMeta(pydantic_v1.BaseModel): api_version: typing.Optional[ApiMetaApiVersion] = None billed_units: typing.Optional[ApiMetaBilledUnits] = None warnings: typing.Optional[typing.List[str]] = None @@ -29,5 +25,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/api_meta_api_version.py b/src/cohere/types/api_meta_api_version.py index 826f5648f..0593c8552 100644 --- a/src/cohere/types/api_meta_api_version.py +++ b/src/cohere/types/api_meta_api_version.py @@ -4,14 +4,10 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ApiMetaApiVersion(pydantic.BaseModel): +class ApiMetaApiVersion(pydantic_v1.BaseModel): version: str is_deprecated: typing.Optional[bool] = None is_experimental: typing.Optional[bool] = None @@ -27,5 +23,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/api_meta_billed_units.py b/src/cohere/types/api_meta_billed_units.py index 06d49af64..cb5c17387 100644 --- a/src/cohere/types/api_meta_billed_units.py +++ b/src/cohere/types/api_meta_billed_units.py @@ -4,30 +4,26 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ApiMetaBilledUnits(pydantic.BaseModel): - input_tokens: typing.Optional[float] = pydantic.Field(default=None) +class ApiMetaBilledUnits(pydantic_v1.BaseModel): + input_tokens: typing.Optional[float] = pydantic_v1.Field(default=None) """ The number of billed input tokens. """ - output_tokens: typing.Optional[float] = pydantic.Field(default=None) + output_tokens: typing.Optional[float] = pydantic_v1.Field(default=None) """ The number of billed output tokens. """ - search_units: typing.Optional[float] = pydantic.Field(default=None) + search_units: typing.Optional[float] = pydantic_v1.Field(default=None) """ The number of billed search units. """ - classifications: typing.Optional[float] = pydantic.Field(default=None) + classifications: typing.Optional[float] = pydantic_v1.Field(default=None) """ The number of billed classifications units. """ @@ -43,5 +39,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/chat_citation.py b/src/cohere/types/chat_citation.py index bc479b8ab..bf444c36f 100644 --- a/src/cohere/types/chat_citation.py +++ b/src/cohere/types/chat_citation.py @@ -4,34 +4,30 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ChatCitation(pydantic.BaseModel): +class ChatCitation(pydantic_v1.BaseModel): """ A section of the generated reply which cites external knowledge. """ - start: int = pydantic.Field() + start: int = pydantic_v1.Field() """ The index of text that the citation starts at, counting from zero. For example, a generation of `Hello, world!` with a citation on `world` would have a start value of `7`. This is because the citation starts at `w`, which is the seventh character. """ - end: int = pydantic.Field() + end: int = pydantic_v1.Field() """ The index of text that the citation ends after, counting from zero. For example, a generation of `Hello, world!` with a citation on `world` would have an end value of `11`. This is because the citation ends after `d`, which is the eleventh character. """ - text: str = pydantic.Field() + text: str = pydantic_v1.Field() """ The text of the citation. For example, a generation of `Hello, world!` with a citation of `world` would have a text value of `world`. """ - document_ids: typing.List[str] = pydantic.Field() + document_ids: typing.List[str] = pydantic_v1.Field() """ Identifiers of documents cited by this section of the generated reply. """ @@ -47,5 +43,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/chat_citation_generation_event.py b/src/cohere/types/chat_citation_generation_event.py index 421709db8..6f837c7b6 100644 --- a/src/cohere/types/chat_citation_generation_event.py +++ b/src/cohere/types/chat_citation_generation_event.py @@ -4,17 +4,13 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .chat_citation import ChatCitation from .chat_stream_event import ChatStreamEvent -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - class ChatCitationGenerationEvent(ChatStreamEvent): - citations: typing.List[ChatCitation] = pydantic.Field() + citations: typing.List[ChatCitation] = pydantic_v1.Field() """ Citations for the generated reply. """ @@ -32,5 +28,5 @@ class Config: smart_union = True allow_population_by_field_name = True populate_by_name = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/chat_connector.py b/src/cohere/types/chat_connector.py index 13994e92d..8cc97cbdb 100644 --- a/src/cohere/types/chat_connector.py +++ b/src/cohere/types/chat_connector.py @@ -4,36 +4,32 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ChatConnector(pydantic.BaseModel): +class ChatConnector(pydantic_v1.BaseModel): """ The connector used for fetching documents. """ - id: str = pydantic.Field() + id: str = pydantic_v1.Field() """ The identifier of the connector. """ - user_access_token: typing.Optional[str] = pydantic.Field(default=None) + user_access_token: typing.Optional[str] = pydantic_v1.Field(default=None) """ When specified, this user access token will be passed to the connector in the Authorization header instead of the Cohere generated one. """ - continue_on_failure: typing.Optional[bool] = pydantic.Field(default=None) + continue_on_failure: typing.Optional[bool] = pydantic_v1.Field(default=None) """ Defaults to `false`. When `true`, the request will continue if this connector returned an error. """ - options: typing.Optional[typing.Dict[str, typing.Any]] = pydantic.Field(default=None) + options: typing.Optional[typing.Dict[str, typing.Any]] = pydantic_v1.Field(default=None) """ Provides the connector with different settings at request time. The key/value pairs of this object are specific to each connector. @@ -51,5 +47,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/chat_data_metrics.py b/src/cohere/types/chat_data_metrics.py index 2754a4280..184812d6a 100644 --- a/src/cohere/types/chat_data_metrics.py +++ b/src/cohere/types/chat_data_metrics.py @@ -4,25 +4,21 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ChatDataMetrics(pydantic.BaseModel): - num_train_turns: typing.Optional[str] = pydantic.Field(alias="numTrainTurns", default=None) +class ChatDataMetrics(pydantic_v1.BaseModel): + num_train_turns: typing.Optional[str] = pydantic_v1.Field(alias="numTrainTurns", default=None) """ The sum of all turns of valid train examples. """ - num_eval_turns: typing.Optional[str] = pydantic.Field(alias="numEvalTurns", default=None) + num_eval_turns: typing.Optional[str] = pydantic_v1.Field(alias="numEvalTurns", default=None) """ The sum of all turns of valid eval examples. """ - preamble: typing.Optional[str] = pydantic.Field(default=None) + preamble: typing.Optional[str] = pydantic_v1.Field(default=None) """ The preamble of this dataset. """ @@ -40,5 +36,5 @@ class Config: smart_union = True allow_population_by_field_name = True populate_by_name = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/chat_message.py b/src/cohere/types/chat_message.py index 63bc0b54f..b96c58d0a 100644 --- a/src/cohere/types/chat_message.py +++ b/src/cohere/types/chat_message.py @@ -4,27 +4,23 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .chat_message_role import ChatMessageRole -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ChatMessage(pydantic.BaseModel): +class ChatMessage(pydantic_v1.BaseModel): """ Represents a single message in the chat history, excluding the current user turn. It has two properties: `role` and `message`. The `role` identifies the sender (`CHATBOT`, `SYSTEM`, or `USER`), while the `message` contains the text content. The chat_history parameter should not be used for `SYSTEM` messages in most cases. Instead, to add a `SYSTEM` role message at the beginning of a conversation, the `preamble` parameter should be used. """ - role: ChatMessageRole = pydantic.Field() + role: ChatMessageRole = pydantic_v1.Field() """ One of `CHATBOT`, `SYSTEM`, or `USER` to identify who the message is coming from. """ - message: str = pydantic.Field() + message: str = pydantic_v1.Field() """ Contents of the chat message. """ @@ -40,5 +36,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/chat_request_connectors_search_options.py b/src/cohere/types/chat_request_connectors_search_options.py index b946500ff..dba7976f4 100644 --- a/src/cohere/types/chat_request_connectors_search_options.py +++ b/src/cohere/types/chat_request_connectors_search_options.py @@ -4,14 +4,10 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ChatRequestConnectorsSearchOptions(pydantic.BaseModel): +class ChatRequestConnectorsSearchOptions(pydantic_v1.BaseModel): """ (internal) Sets inference and model options for RAG search query and tool use generations. Defaults are used when options are not specified here, meaning that other parameters outside of connectors_search_options are ignored (such as model= or temperature=). """ @@ -20,7 +16,7 @@ class ChatRequestConnectorsSearchOptions(pydantic.BaseModel): temperature: typing.Optional[typing.Any] = None max_tokens: typing.Optional[typing.Any] = None preamble: typing.Optional[typing.Any] = None - seed: typing.Optional[float] = pydantic.Field(default=None) + seed: typing.Optional[float] = pydantic_v1.Field(default=None) """ If specified, the backend will make a best effort to sample tokens deterministically, such that repeated requests with the same seed and parameters should return the same result. However, determinsim cannot be totally guaranteed. """ @@ -36,5 +32,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/chat_request_tool_results_item.py b/src/cohere/types/chat_request_tool_results_item.py index f728592de..5d9d3f372 100644 --- a/src/cohere/types/chat_request_tool_results_item.py +++ b/src/cohere/types/chat_request_tool_results_item.py @@ -4,15 +4,11 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .tool_call import ToolCall -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ChatRequestToolResultsItem(pydantic.BaseModel): +class ChatRequestToolResultsItem(pydantic_v1.BaseModel): call: ToolCall outputs: typing.List[typing.Dict[str, typing.Any]] @@ -27,5 +23,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/chat_search_queries_generation_event.py b/src/cohere/types/chat_search_queries_generation_event.py index 2728f76c9..78639d1b1 100644 --- a/src/cohere/types/chat_search_queries_generation_event.py +++ b/src/cohere/types/chat_search_queries_generation_event.py @@ -4,17 +4,13 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .chat_search_query import ChatSearchQuery from .chat_stream_event import ChatStreamEvent -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - class ChatSearchQueriesGenerationEvent(ChatStreamEvent): - search_queries: typing.List[ChatSearchQuery] = pydantic.Field() + search_queries: typing.List[ChatSearchQuery] = pydantic_v1.Field() """ Generated search queries, meant to be used as part of the RAG flow. """ @@ -32,5 +28,5 @@ class Config: smart_union = True allow_population_by_field_name = True populate_by_name = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/chat_search_query.py b/src/cohere/types/chat_search_query.py index 3d4238f0c..b904ef0a0 100644 --- a/src/cohere/types/chat_search_query.py +++ b/src/cohere/types/chat_search_query.py @@ -4,24 +4,20 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ChatSearchQuery(pydantic.BaseModel): +class ChatSearchQuery(pydantic_v1.BaseModel): """ The generated search query. Contains the text of the query and a unique identifier for the query. """ - text: str = pydantic.Field() + text: str = pydantic_v1.Field() """ The text of the search query. """ - generation_id: str = pydantic.Field() + generation_id: str = pydantic_v1.Field() """ Unique identifier for the generated search query. Useful for submitting feedback. """ @@ -37,5 +33,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/chat_search_result.py b/src/cohere/types/chat_search_result.py index a7f624009..f06a5b7fd 100644 --- a/src/cohere/types/chat_search_result.py +++ b/src/cohere/types/chat_search_result.py @@ -4,33 +4,29 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .chat_search_query import ChatSearchQuery from .chat_search_result_connector import ChatSearchResultConnector -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ChatSearchResult(pydantic.BaseModel): +class ChatSearchResult(pydantic_v1.BaseModel): search_query: typing.Optional[ChatSearchQuery] = None - connector: ChatSearchResultConnector = pydantic.Field() + connector: ChatSearchResultConnector = pydantic_v1.Field() """ The connector from which this result comes from. """ - document_ids: typing.List[str] = pydantic.Field() + document_ids: typing.List[str] = pydantic_v1.Field() """ Identifiers of documents found by this search query. """ - error_message: typing.Optional[str] = pydantic.Field(default=None) + error_message: typing.Optional[str] = pydantic_v1.Field(default=None) """ An error message if the search failed. """ - continue_on_failure: typing.Optional[bool] = pydantic.Field(default=None) + continue_on_failure: typing.Optional[bool] = pydantic_v1.Field(default=None) """ Whether a chat request should continue or not if the request to this connector fails. """ @@ -46,5 +42,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/chat_search_result_connector.py b/src/cohere/types/chat_search_result_connector.py index 24d993885..82b81fcea 100644 --- a/src/cohere/types/chat_search_result_connector.py +++ b/src/cohere/types/chat_search_result_connector.py @@ -4,19 +4,15 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ChatSearchResultConnector(pydantic.BaseModel): +class ChatSearchResultConnector(pydantic_v1.BaseModel): """ The connector used for fetching documents. """ - id: str = pydantic.Field() + id: str = pydantic_v1.Field() """ The identifier of the connector. """ @@ -32,5 +28,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/chat_search_results_event.py b/src/cohere/types/chat_search_results_event.py index 44b90d21c..28cb5163a 100644 --- a/src/cohere/types/chat_search_results_event.py +++ b/src/cohere/types/chat_search_results_event.py @@ -4,23 +4,19 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .chat_document import ChatDocument from .chat_search_result import ChatSearchResult from .chat_stream_event import ChatStreamEvent -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - class ChatSearchResultsEvent(ChatStreamEvent): - search_results: typing.Optional[typing.List[ChatSearchResult]] = pydantic.Field(default=None) + search_results: typing.Optional[typing.List[ChatSearchResult]] = pydantic_v1.Field(default=None) """ Conducted searches and the ids of documents retrieved from each of them. """ - documents: typing.Optional[typing.List[ChatDocument]] = pydantic.Field(default=None) + documents: typing.Optional[typing.List[ChatDocument]] = pydantic_v1.Field(default=None) """ Documents fetched from searches or provided by the user. """ @@ -38,5 +34,5 @@ class Config: smart_union = True allow_population_by_field_name = True populate_by_name = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/chat_stream_end_event.py b/src/cohere/types/chat_stream_end_event.py index 24bd66134..2b7dfd027 100644 --- a/src/cohere/types/chat_stream_end_event.py +++ b/src/cohere/types/chat_stream_end_event.py @@ -4,18 +4,14 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .chat_stream_end_event_finish_reason import ChatStreamEndEventFinishReason from .chat_stream_event import ChatStreamEvent from .non_streamed_chat_response import NonStreamedChatResponse -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - class ChatStreamEndEvent(ChatStreamEvent): - finish_reason: ChatStreamEndEventFinishReason = pydantic.Field() + finish_reason: ChatStreamEndEventFinishReason = pydantic_v1.Field() """ - `COMPLETE` - the model sent back a finished reply - `ERROR_LIMIT` - the reply was cut off because the model reached the maximum number of tokens for its context length @@ -24,7 +20,7 @@ class ChatStreamEndEvent(ChatStreamEvent): - `ERROR_TOXIC` - the model generated a reply that was deemed toxic """ - response: NonStreamedChatResponse = pydantic.Field() + response: NonStreamedChatResponse = pydantic_v1.Field() """ The consolidated response from the model. Contains the generated reply and all the other information streamed back in the previous events. """ @@ -42,5 +38,5 @@ class Config: smart_union = True allow_population_by_field_name = True populate_by_name = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/chat_stream_event.py b/src/cohere/types/chat_stream_event.py index f61c170ef..5d918bf0c 100644 --- a/src/cohere/types/chat_stream_event.py +++ b/src/cohere/types/chat_stream_event.py @@ -4,14 +4,10 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ChatStreamEvent(pydantic.BaseModel): +class ChatStreamEvent(pydantic_v1.BaseModel): def json(self, **kwargs: typing.Any) -> str: kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} return super().json(**kwargs_with_defaults) @@ -23,5 +19,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/chat_stream_request_connectors_search_options.py b/src/cohere/types/chat_stream_request_connectors_search_options.py index cb879814f..02372e58b 100644 --- a/src/cohere/types/chat_stream_request_connectors_search_options.py +++ b/src/cohere/types/chat_stream_request_connectors_search_options.py @@ -4,14 +4,10 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ChatStreamRequestConnectorsSearchOptions(pydantic.BaseModel): +class ChatStreamRequestConnectorsSearchOptions(pydantic_v1.BaseModel): """ (internal) Sets inference and model options for RAG search query and tool use generations. Defaults are used when options are not specified here, meaning that other parameters outside of connectors_search_options are ignored (such as model= or temperature=). """ @@ -20,7 +16,7 @@ class ChatStreamRequestConnectorsSearchOptions(pydantic.BaseModel): temperature: typing.Optional[typing.Any] = None max_tokens: typing.Optional[typing.Any] = None preamble: typing.Optional[typing.Any] = None - seed: typing.Optional[float] = pydantic.Field(default=None) + seed: typing.Optional[float] = pydantic_v1.Field(default=None) """ If specified, the backend will make a best effort to sample tokens deterministically, such that repeated requests with the same seed and parameters should return the same result. However, determinsim cannot be totally guaranteed. """ @@ -36,5 +32,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/chat_stream_request_tool_results_item.py b/src/cohere/types/chat_stream_request_tool_results_item.py index 4bb893f6b..6ccbe2bfc 100644 --- a/src/cohere/types/chat_stream_request_tool_results_item.py +++ b/src/cohere/types/chat_stream_request_tool_results_item.py @@ -4,15 +4,11 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .tool_call import ToolCall -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ChatStreamRequestToolResultsItem(pydantic.BaseModel): +class ChatStreamRequestToolResultsItem(pydantic_v1.BaseModel): call: ToolCall outputs: typing.List[typing.Dict[str, typing.Any]] @@ -27,5 +23,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/chat_stream_start_event.py b/src/cohere/types/chat_stream_start_event.py index 38e3d495a..84a0c3972 100644 --- a/src/cohere/types/chat_stream_start_event.py +++ b/src/cohere/types/chat_stream_start_event.py @@ -4,16 +4,12 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .chat_stream_event import ChatStreamEvent -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - class ChatStreamStartEvent(ChatStreamEvent): - generation_id: str = pydantic.Field() + generation_id: str = pydantic_v1.Field() """ Unique identifier for the generated reply. Useful for submitting feedback. """ @@ -31,5 +27,5 @@ class Config: smart_union = True allow_population_by_field_name = True populate_by_name = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/chat_text_generation_event.py b/src/cohere/types/chat_text_generation_event.py index d3b29b53c..d29ba5cdf 100644 --- a/src/cohere/types/chat_text_generation_event.py +++ b/src/cohere/types/chat_text_generation_event.py @@ -4,16 +4,12 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .chat_stream_event import ChatStreamEvent -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - class ChatTextGenerationEvent(ChatStreamEvent): - text: str = pydantic.Field() + text: str = pydantic_v1.Field() """ The next batch of text generated by the model. """ @@ -31,5 +27,5 @@ class Config: smart_union = True allow_population_by_field_name = True populate_by_name = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/chat_tool_calls_generation_event.py b/src/cohere/types/chat_tool_calls_generation_event.py index b726cd09a..33b148713 100644 --- a/src/cohere/types/chat_tool_calls_generation_event.py +++ b/src/cohere/types/chat_tool_calls_generation_event.py @@ -4,14 +4,10 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .chat_stream_event import ChatStreamEvent from .tool_call import ToolCall -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - class ChatToolCallsGenerationEvent(ChatStreamEvent): tool_calls: typing.List[ToolCall] @@ -29,5 +25,5 @@ class Config: smart_union = True allow_population_by_field_name = True populate_by_name = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/classify_data_metrics.py b/src/cohere/types/classify_data_metrics.py index a9fdfb9cc..69adabf78 100644 --- a/src/cohere/types/classify_data_metrics.py +++ b/src/cohere/types/classify_data_metrics.py @@ -4,16 +4,12 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .label_metric import LabelMetric -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ClassifyDataMetrics(pydantic.BaseModel): - label_metrics: typing.Optional[typing.List[LabelMetric]] = pydantic.Field(alias="labelMetrics", default=None) +class ClassifyDataMetrics(pydantic_v1.BaseModel): + label_metrics: typing.Optional[typing.List[LabelMetric]] = pydantic_v1.Field(alias="labelMetrics", default=None) def json(self, **kwargs: typing.Any) -> str: kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} @@ -28,5 +24,5 @@ class Config: smart_union = True allow_population_by_field_name = True populate_by_name = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/classify_example.py b/src/cohere/types/classify_example.py index 735251ca7..dfb58f4f3 100644 --- a/src/cohere/types/classify_example.py +++ b/src/cohere/types/classify_example.py @@ -4,14 +4,10 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ClassifyExample(pydantic.BaseModel): +class ClassifyExample(pydantic_v1.BaseModel): text: typing.Optional[str] = None label: typing.Optional[str] = None @@ -26,5 +22,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/classify_response.py b/src/cohere/types/classify_response.py index 863f9cca5..e68cf3520 100644 --- a/src/cohere/types/classify_response.py +++ b/src/cohere/types/classify_response.py @@ -4,16 +4,12 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .api_meta import ApiMeta from .classify_response_classifications_item import ClassifyResponseClassificationsItem -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ClassifyResponse(pydantic.BaseModel): +class ClassifyResponse(pydantic_v1.BaseModel): id: str classifications: typing.List[ClassifyResponseClassificationsItem] meta: typing.Optional[ApiMeta] = None @@ -29,5 +25,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/classify_response_classifications_item.py b/src/cohere/types/classify_response_classifications_item.py index 95825dbc4..a7db56cfa 100644 --- a/src/cohere/types/classify_response_classifications_item.py +++ b/src/cohere/types/classify_response_classifications_item.py @@ -4,50 +4,46 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .classify_response_classifications_item_classification_type import ( ClassifyResponseClassificationsItemClassificationType, ) from .classify_response_classifications_item_labels_value import ClassifyResponseClassificationsItemLabelsValue -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ClassifyResponseClassificationsItem(pydantic.BaseModel): +class ClassifyResponseClassificationsItem(pydantic_v1.BaseModel): id: str - input: typing.Optional[str] = pydantic.Field(default=None) + input: typing.Optional[str] = pydantic_v1.Field(default=None) """ The input text that was classified """ - prediction: typing.Optional[str] = pydantic.Field(default=None) + prediction: typing.Optional[str] = pydantic_v1.Field(default=None) """ The predicted label for the associated query (only filled for single-label models) """ - predictions: typing.List[str] = pydantic.Field() + predictions: typing.List[str] = pydantic_v1.Field() """ An array containing the predicted labels for the associated query (only filled for single-label classification) """ - confidence: typing.Optional[float] = pydantic.Field(default=None) + confidence: typing.Optional[float] = pydantic_v1.Field(default=None) """ The confidence score for the top predicted class (only filled for single-label classification) """ - confidences: typing.List[float] = pydantic.Field() + confidences: typing.List[float] = pydantic_v1.Field() """ An array containing the confidence scores of all the predictions in the same order """ - labels: typing.Dict[str, ClassifyResponseClassificationsItemLabelsValue] = pydantic.Field() + labels: typing.Dict[str, ClassifyResponseClassificationsItemLabelsValue] = pydantic_v1.Field() """ A map containing each label and its confidence score according to the classifier. All the confidence scores add up to 1 for single-label classification. For multi-label classification the label confidences are independent of each other, so they don't have to sum up to 1. """ - classification_type: ClassifyResponseClassificationsItemClassificationType = pydantic.Field() + classification_type: ClassifyResponseClassificationsItemClassificationType = pydantic_v1.Field() """ The type of classification performed """ @@ -63,5 +59,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/classify_response_classifications_item_labels_value.py b/src/cohere/types/classify_response_classifications_item_labels_value.py index fdf22639d..48fe6c734 100644 --- a/src/cohere/types/classify_response_classifications_item_labels_value.py +++ b/src/cohere/types/classify_response_classifications_item_labels_value.py @@ -4,14 +4,10 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ClassifyResponseClassificationsItemLabelsValue(pydantic.BaseModel): +class ClassifyResponseClassificationsItemLabelsValue(pydantic_v1.BaseModel): confidence: typing.Optional[float] = None def json(self, **kwargs: typing.Any) -> str: @@ -25,5 +21,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/connector.py b/src/cohere/types/connector.py index e51ea2e65..1360fc8ce 100644 --- a/src/cohere/types/connector.py +++ b/src/cohere/types/connector.py @@ -4,84 +4,80 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .connector_auth_status import ConnectorAuthStatus from .connector_o_auth import ConnectorOAuth -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class Connector(pydantic.BaseModel): +class Connector(pydantic_v1.BaseModel): """ A connector allows you to integrate data sources with the '/chat' endpoint to create grounded generations with citations to the data source. documents to help answer users. """ - id: str = pydantic.Field() + id: str = pydantic_v1.Field() """ The unique identifier of the connector (used in both `/connectors` & `/chat` endpoints). This is automatically created from the name of the connector upon registration. """ - organization_id: typing.Optional[str] = pydantic.Field(default=None) + organization_id: typing.Optional[str] = pydantic_v1.Field(default=None) """ The organization to which this connector belongs. This is automatically set to the organization of the user who created the connector. """ - name: str = pydantic.Field() + name: str = pydantic_v1.Field() """ A human-readable name for the connector. """ - description: typing.Optional[str] = pydantic.Field(default=None) + description: typing.Optional[str] = pydantic_v1.Field(default=None) """ A description of the connector. """ - url: typing.Optional[str] = pydantic.Field(default=None) + url: typing.Optional[str] = pydantic_v1.Field(default=None) """ The URL of the connector that will be used to search for documents. """ - created_at: dt.datetime = pydantic.Field() + created_at: dt.datetime = pydantic_v1.Field() """ The UTC time at which the connector was created. """ - updated_at: dt.datetime = pydantic.Field() + updated_at: dt.datetime = pydantic_v1.Field() """ The UTC time at which the connector was last updated. """ - excludes: typing.Optional[typing.List[str]] = pydantic.Field(default=None) + excludes: typing.Optional[typing.List[str]] = pydantic_v1.Field(default=None) """ A list of fields to exclude from the prompt (fields remain in the document). """ - auth_type: typing.Optional[str] = pydantic.Field(default=None) + auth_type: typing.Optional[str] = pydantic_v1.Field(default=None) """ The type of authentication/authorization used by the connector. Possible values: [oauth, service_auth] """ - oauth: typing.Optional[ConnectorOAuth] = pydantic.Field(default=None) + oauth: typing.Optional[ConnectorOAuth] = pydantic_v1.Field(default=None) """ The OAuth 2.0 configuration for the connector. """ - auth_status: typing.Optional[ConnectorAuthStatus] = pydantic.Field(default=None) + auth_status: typing.Optional[ConnectorAuthStatus] = pydantic_v1.Field(default=None) """ The OAuth status for the user making the request. One of ["valid", "expired", ""]. Empty string (field is omitted) means the user has not authorized the connector yet. """ - active: typing.Optional[bool] = pydantic.Field(default=None) + active: typing.Optional[bool] = pydantic_v1.Field(default=None) """ Whether the connector is active or not. """ - continue_on_failure: typing.Optional[bool] = pydantic.Field(default=None) + continue_on_failure: typing.Optional[bool] = pydantic_v1.Field(default=None) """ Whether a chat request should continue or not if the request to this connector fails. """ @@ -97,5 +93,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/connector_o_auth.py b/src/cohere/types/connector_o_auth.py index 54ef489df..b19c52ccb 100644 --- a/src/cohere/types/connector_o_auth.py +++ b/src/cohere/types/connector_o_auth.py @@ -4,35 +4,31 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ConnectorOAuth(pydantic.BaseModel): - client_id: typing.Optional[str] = pydantic.Field(default=None) +class ConnectorOAuth(pydantic_v1.BaseModel): + client_id: typing.Optional[str] = pydantic_v1.Field(default=None) """ The OAuth 2.0 client ID. This field is encrypted at rest. """ - client_secret: typing.Optional[str] = pydantic.Field(default=None) + client_secret: typing.Optional[str] = pydantic_v1.Field(default=None) """ The OAuth 2.0 client Secret. This field is encrypted at rest and never returned in a response. """ - authorize_url: str = pydantic.Field() + authorize_url: str = pydantic_v1.Field() """ The OAuth 2.0 /authorize endpoint to use when users authorize the connector. """ - token_url: str = pydantic.Field() + token_url: str = pydantic_v1.Field() """ The OAuth 2.0 /token endpoint to use when users authorize the connector. """ - scope: typing.Optional[str] = pydantic.Field(default=None) + scope: typing.Optional[str] = pydantic_v1.Field(default=None) """ The OAuth scopes to request when users authorize the connector. """ @@ -48,5 +44,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/create_connector_o_auth.py b/src/cohere/types/create_connector_o_auth.py index d39c063ea..b2ca09244 100644 --- a/src/cohere/types/create_connector_o_auth.py +++ b/src/cohere/types/create_connector_o_auth.py @@ -4,35 +4,31 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class CreateConnectorOAuth(pydantic.BaseModel): - client_id: typing.Optional[str] = pydantic.Field(default=None) +class CreateConnectorOAuth(pydantic_v1.BaseModel): + client_id: typing.Optional[str] = pydantic_v1.Field(default=None) """ The OAuth 2.0 client ID. This fields is encrypted at rest. """ - client_secret: typing.Optional[str] = pydantic.Field(default=None) + client_secret: typing.Optional[str] = pydantic_v1.Field(default=None) """ The OAuth 2.0 client Secret. This field is encrypted at rest and never returned in a response. """ - authorize_url: typing.Optional[str] = pydantic.Field(default=None) + authorize_url: typing.Optional[str] = pydantic_v1.Field(default=None) """ The OAuth 2.0 /authorize endpoint to use when users authorize the connector. """ - token_url: typing.Optional[str] = pydantic.Field(default=None) + token_url: typing.Optional[str] = pydantic_v1.Field(default=None) """ The OAuth 2.0 /token endpoint to use when users authorize the connector. """ - scope: typing.Optional[str] = pydantic.Field(default=None) + scope: typing.Optional[str] = pydantic_v1.Field(default=None) """ The OAuth scopes to request when users authorize the connector. """ @@ -48,5 +44,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/create_connector_response.py b/src/cohere/types/create_connector_response.py index a3b7bcd01..16dfa53d0 100644 --- a/src/cohere/types/create_connector_response.py +++ b/src/cohere/types/create_connector_response.py @@ -4,15 +4,11 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .connector import Connector -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class CreateConnectorResponse(pydantic.BaseModel): +class CreateConnectorResponse(pydantic_v1.BaseModel): connector: Connector def json(self, **kwargs: typing.Any) -> str: @@ -26,5 +22,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/create_connector_service_auth.py b/src/cohere/types/create_connector_service_auth.py index 988a3f197..a1d93f4ff 100644 --- a/src/cohere/types/create_connector_service_auth.py +++ b/src/cohere/types/create_connector_service_auth.py @@ -4,17 +4,13 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .auth_token_type import AuthTokenType -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class CreateConnectorServiceAuth(pydantic.BaseModel): +class CreateConnectorServiceAuth(pydantic_v1.BaseModel): type: AuthTokenType - token: str = pydantic.Field() + token: str = pydantic_v1.Field() """ The token that will be used in the HTTP Authorization header when making requests to the connector. This field is encrypted at rest and never returned in a response. """ @@ -30,5 +26,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/create_embed_job_response.py b/src/cohere/types/create_embed_job_response.py index 7a852946d..2b2fe8b3e 100644 --- a/src/cohere/types/create_embed_job_response.py +++ b/src/cohere/types/create_embed_job_response.py @@ -4,15 +4,11 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .api_meta import ApiMeta -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class CreateEmbedJobResponse(pydantic.BaseModel): +class CreateEmbedJobResponse(pydantic_v1.BaseModel): """ Response from creating an embed job. """ @@ -31,5 +27,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/dataset.py b/src/cohere/types/dataset.py index b54f6a898..1fd664da3 100644 --- a/src/cohere/types/dataset.py +++ b/src/cohere/types/dataset.py @@ -4,57 +4,53 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .dataset_part import DatasetPart from .dataset_type import DatasetType from .dataset_validation_status import DatasetValidationStatus -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class Dataset(pydantic.BaseModel): - id: str = pydantic.Field() +class Dataset(pydantic_v1.BaseModel): + id: str = pydantic_v1.Field() """ The dataset ID """ - name: str = pydantic.Field() + name: str = pydantic_v1.Field() """ The name of the dataset """ - created_at: dt.datetime = pydantic.Field() + created_at: dt.datetime = pydantic_v1.Field() """ The creation date """ - updated_at: dt.datetime = pydantic.Field() + updated_at: dt.datetime = pydantic_v1.Field() """ The last update date """ dataset_type: DatasetType validation_status: DatasetValidationStatus - validation_error: typing.Optional[str] = pydantic.Field(default=None) + validation_error: typing.Optional[str] = pydantic_v1.Field(default=None) """ Errors found during validation """ - schema_: typing.Optional[str] = pydantic.Field(alias="schema", default=None) + schema_: typing.Optional[str] = pydantic_v1.Field(alias="schema", default=None) """ the avro schema of the dataset """ required_fields: typing.Optional[typing.List[str]] = None preserve_fields: typing.Optional[typing.List[str]] = None - dataset_parts: typing.Optional[typing.List[DatasetPart]] = pydantic.Field(default=None) + dataset_parts: typing.Optional[typing.List[DatasetPart]] = pydantic_v1.Field(default=None) """ the underlying files that make up the dataset """ - validation_warnings: typing.Optional[typing.List[str]] = pydantic.Field(default=None) + validation_warnings: typing.Optional[typing.List[str]] = pydantic_v1.Field(default=None) """ warnings found during validation """ @@ -72,5 +68,5 @@ class Config: smart_union = True allow_population_by_field_name = True populate_by_name = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/dataset_part.py b/src/cohere/types/dataset_part.py index d3645cb16..d3e95f002 100644 --- a/src/cohere/types/dataset_part.py +++ b/src/cohere/types/dataset_part.py @@ -4,45 +4,41 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class DatasetPart(pydantic.BaseModel): - id: str = pydantic.Field() +class DatasetPart(pydantic_v1.BaseModel): + id: str = pydantic_v1.Field() """ The dataset part ID """ - name: str = pydantic.Field() + name: str = pydantic_v1.Field() """ The name of the dataset part """ - url: typing.Optional[str] = pydantic.Field(default=None) + url: typing.Optional[str] = pydantic_v1.Field(default=None) """ The download url of the file """ - index: typing.Optional[int] = pydantic.Field(default=None) + index: typing.Optional[int] = pydantic_v1.Field(default=None) """ The index of the file """ - size_bytes: typing.Optional[int] = pydantic.Field(default=None) + size_bytes: typing.Optional[int] = pydantic_v1.Field(default=None) """ The size of the file in bytes """ - num_rows: typing.Optional[int] = pydantic.Field(default=None) + num_rows: typing.Optional[int] = pydantic_v1.Field(default=None) """ The number of rows in the file """ - original_url: typing.Optional[str] = pydantic.Field(default=None) + original_url: typing.Optional[str] = pydantic_v1.Field(default=None) """ The download url of the original file """ @@ -58,5 +54,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/detokenize_response.py b/src/cohere/types/detokenize_response.py index 5b05d8569..3c63bf7fe 100644 --- a/src/cohere/types/detokenize_response.py +++ b/src/cohere/types/detokenize_response.py @@ -4,16 +4,12 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .api_meta import ApiMeta -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class DetokenizeResponse(pydantic.BaseModel): - text: str = pydantic.Field() +class DetokenizeResponse(pydantic_v1.BaseModel): + text: str = pydantic_v1.Field() """ A string representing the list of tokens. """ @@ -31,5 +27,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/embed_by_type_response.py b/src/cohere/types/embed_by_type_response.py index 9ae0edbf2..74afb9a03 100644 --- a/src/cohere/types/embed_by_type_response.py +++ b/src/cohere/types/embed_by_type_response.py @@ -4,23 +4,19 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .api_meta import ApiMeta from .embed_by_type_response_embeddings import EmbedByTypeResponseEmbeddings -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class EmbedByTypeResponse(pydantic.BaseModel): +class EmbedByTypeResponse(pydantic_v1.BaseModel): id: str - embeddings: EmbedByTypeResponseEmbeddings = pydantic.Field() + embeddings: EmbedByTypeResponseEmbeddings = pydantic_v1.Field() """ An object with different embedding types. The length of each embedding type array will be the same as the length of the original `texts` array. """ - texts: typing.List[str] = pydantic.Field() + texts: typing.List[str] = pydantic_v1.Field() """ The text entries for which embeddings were returned. """ @@ -38,5 +34,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/embed_by_type_response_embeddings.py b/src/cohere/types/embed_by_type_response_embeddings.py index cd544f12f..81b8b2107 100644 --- a/src/cohere/types/embed_by_type_response_embeddings.py +++ b/src/cohere/types/embed_by_type_response_embeddings.py @@ -4,39 +4,35 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class EmbedByTypeResponseEmbeddings(pydantic.BaseModel): +class EmbedByTypeResponseEmbeddings(pydantic_v1.BaseModel): """ An object with different embedding types. The length of each embedding type array will be the same as the length of the original `texts` array. """ - float_: typing.Optional[typing.List[typing.List[float]]] = pydantic.Field(alias="float", default=None) + float_: typing.Optional[typing.List[typing.List[float]]] = pydantic_v1.Field(alias="float", default=None) """ An array of float embeddings. """ - int8: typing.Optional[typing.List[typing.List[float]]] = pydantic.Field(default=None) + int8: typing.Optional[typing.List[typing.List[float]]] = pydantic_v1.Field(default=None) """ An array of signed int8 embeddings. Each value is between -128 and 127. """ - uint8: typing.Optional[typing.List[typing.List[float]]] = pydantic.Field(default=None) + uint8: typing.Optional[typing.List[typing.List[float]]] = pydantic_v1.Field(default=None) """ An array of unsigned int8 embeddings. Each value is between 0 and 255. """ - binary: typing.Optional[typing.List[typing.List[float]]] = pydantic.Field(default=None) + binary: typing.Optional[typing.List[typing.List[float]]] = pydantic_v1.Field(default=None) """ An array of packed signed binary embeddings. The length of each binary embedding is 1/8 the length of the float embeddings of the provided model. Each value is between -128 and 127. """ - ubinary: typing.Optional[typing.List[typing.List[float]]] = pydantic.Field(default=None) + ubinary: typing.Optional[typing.List[typing.List[float]]] = pydantic_v1.Field(default=None) """ An array of packed unsigned binary embeddings. The length of each binary embedding is 1/8 the length of the float embeddings of the provided model. Each value is between 0 and 255. """ @@ -54,5 +50,5 @@ class Config: smart_union = True allow_population_by_field_name = True populate_by_name = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/embed_floats_response.py b/src/cohere/types/embed_floats_response.py index 80666e1a0..743671d55 100644 --- a/src/cohere/types/embed_floats_response.py +++ b/src/cohere/types/embed_floats_response.py @@ -4,22 +4,18 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .api_meta import ApiMeta -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class EmbedFloatsResponse(pydantic.BaseModel): +class EmbedFloatsResponse(pydantic_v1.BaseModel): id: str - embeddings: typing.List[typing.List[float]] = pydantic.Field() + embeddings: typing.List[typing.List[float]] = pydantic_v1.Field() """ An array of embeddings, where each embedding is an array of floats. The length of the `embeddings` array will be the same as the length of the original `texts` array. """ - texts: typing.List[str] = pydantic.Field() + texts: typing.List[str] = pydantic_v1.Field() """ The text entries for which embeddings were returned. """ @@ -37,5 +33,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/embed_job.py b/src/cohere/types/embed_job.py index e741adee2..e20981903 100644 --- a/src/cohere/types/embed_job.py +++ b/src/cohere/types/embed_job.py @@ -4,53 +4,49 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .api_meta import ApiMeta from .embed_job_status import EmbedJobStatus from .embed_job_truncate import EmbedJobTruncate -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class EmbedJob(pydantic.BaseModel): - job_id: str = pydantic.Field() +class EmbedJob(pydantic_v1.BaseModel): + job_id: str = pydantic_v1.Field() """ ID of the embed job """ - name: typing.Optional[str] = pydantic.Field(default=None) + name: typing.Optional[str] = pydantic_v1.Field(default=None) """ The name of the embed job """ - status: EmbedJobStatus = pydantic.Field() + status: EmbedJobStatus = pydantic_v1.Field() """ The status of the embed job """ - created_at: dt.datetime = pydantic.Field() + created_at: dt.datetime = pydantic_v1.Field() """ The creation date of the embed job """ - input_dataset_id: str = pydantic.Field() + input_dataset_id: str = pydantic_v1.Field() """ ID of the input dataset """ - output_dataset_id: typing.Optional[str] = pydantic.Field(default=None) + output_dataset_id: typing.Optional[str] = pydantic_v1.Field(default=None) """ ID of the resulting output dataset """ - model: str = pydantic.Field() + model: str = pydantic_v1.Field() """ ID of the model used to embed """ - truncate: EmbedJobTruncate = pydantic.Field() + truncate: EmbedJobTruncate = pydantic_v1.Field() """ The truncation option used """ @@ -68,5 +64,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/embed_response.py b/src/cohere/types/embed_response.py index ea82e2460..48e0b2122 100644 --- a/src/cohere/types/embed_response.py +++ b/src/cohere/types/embed_response.py @@ -9,7 +9,7 @@ class EmbedResponse_EmbeddingsFloats(EmbedFloatsResponse): - response_type: typing.Literal["embeddings_floats"] + response_type: typing.Literal["embeddings_floats"] = "embeddings_floats" class Config: frozen = True @@ -19,7 +19,7 @@ class Config: class EmbedResponse_EmbeddingsByType(EmbedByTypeResponse): - response_type: typing.Literal["embeddings_by_type"] + response_type: typing.Literal["embeddings_by_type"] = "embeddings_by_type" class Config: frozen = True diff --git a/src/cohere/types/finetune_dataset_metrics.py b/src/cohere/types/finetune_dataset_metrics.py index 05c7391e2..64c41d5a2 100644 --- a/src/cohere/types/finetune_dataset_metrics.py +++ b/src/cohere/types/finetune_dataset_metrics.py @@ -4,40 +4,36 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class FinetuneDatasetMetrics(pydantic.BaseModel): - trainable_token_count: typing.Optional[str] = pydantic.Field(alias="trainableTokenCount", default=None) +class FinetuneDatasetMetrics(pydantic_v1.BaseModel): + trainable_token_count: typing.Optional[str] = pydantic_v1.Field(alias="trainableTokenCount", default=None) """ The number of tokens of valid examples that can be used for training. """ - total_examples: typing.Optional[str] = pydantic.Field(alias="totalExamples", default=None) + total_examples: typing.Optional[str] = pydantic_v1.Field(alias="totalExamples", default=None) """ The overall number of examples. """ - train_examples: typing.Optional[str] = pydantic.Field(alias="trainExamples", default=None) + train_examples: typing.Optional[str] = pydantic_v1.Field(alias="trainExamples", default=None) """ The number of training examples. """ - train_size_bytes: typing.Optional[str] = pydantic.Field(alias="trainSizeBytes", default=None) + train_size_bytes: typing.Optional[str] = pydantic_v1.Field(alias="trainSizeBytes", default=None) """ The size in bytes of all training examples. """ - eval_examples: typing.Optional[str] = pydantic.Field(alias="evalExamples", default=None) + eval_examples: typing.Optional[str] = pydantic_v1.Field(alias="evalExamples", default=None) """ Number of evaluation examples. """ - eval_size_bytes: typing.Optional[str] = pydantic.Field(alias="evalSizeBytes", default=None) + eval_size_bytes: typing.Optional[str] = pydantic_v1.Field(alias="evalSizeBytes", default=None) """ The size in bytes of all eval examples. """ @@ -55,5 +51,5 @@ class Config: smart_union = True allow_population_by_field_name = True populate_by_name = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/generate_stream_end.py b/src/cohere/types/generate_stream_end.py index b014ef360..8436c8628 100644 --- a/src/cohere/types/generate_stream_end.py +++ b/src/cohere/types/generate_stream_end.py @@ -4,15 +4,11 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .finish_reason import FinishReason from .generate_stream_end_response import GenerateStreamEndResponse from .generate_stream_event import GenerateStreamEvent -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - class GenerateStreamEnd(GenerateStreamEvent): is_finished: bool @@ -32,5 +28,5 @@ class Config: smart_union = True allow_population_by_field_name = True populate_by_name = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/generate_stream_end_response.py b/src/cohere/types/generate_stream_end_response.py index d135ecfb8..5153c0b78 100644 --- a/src/cohere/types/generate_stream_end_response.py +++ b/src/cohere/types/generate_stream_end_response.py @@ -4,15 +4,11 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .single_generation_in_stream import SingleGenerationInStream -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class GenerateStreamEndResponse(pydantic.BaseModel): +class GenerateStreamEndResponse(pydantic_v1.BaseModel): id: str prompt: typing.Optional[str] = None generations: typing.Optional[typing.List[SingleGenerationInStream]] = None @@ -28,5 +24,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/generate_stream_error.py b/src/cohere/types/generate_stream_error.py index 45ab2db44..6264cc940 100644 --- a/src/cohere/types/generate_stream_error.py +++ b/src/cohere/types/generate_stream_error.py @@ -4,24 +4,20 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .finish_reason import FinishReason from .generate_stream_event import GenerateStreamEvent -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - class GenerateStreamError(GenerateStreamEvent): - index: typing.Optional[int] = pydantic.Field(default=None) + index: typing.Optional[int] = pydantic_v1.Field(default=None) """ Refers to the nth generation. Only present when `num_generations` is greater than zero. """ is_finished: bool finish_reason: FinishReason - err: str = pydantic.Field() + err: str = pydantic_v1.Field() """ Error message """ @@ -39,5 +35,5 @@ class Config: smart_union = True allow_population_by_field_name = True populate_by_name = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/generate_stream_event.py b/src/cohere/types/generate_stream_event.py index 73abcdef5..fdbba80a9 100644 --- a/src/cohere/types/generate_stream_event.py +++ b/src/cohere/types/generate_stream_event.py @@ -4,14 +4,10 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class GenerateStreamEvent(pydantic.BaseModel): +class GenerateStreamEvent(pydantic_v1.BaseModel): def json(self, **kwargs: typing.Any) -> str: kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} return super().json(**kwargs_with_defaults) @@ -23,5 +19,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/generate_stream_text.py b/src/cohere/types/generate_stream_text.py index 0907cdc8d..f7426d0dc 100644 --- a/src/cohere/types/generate_stream_text.py +++ b/src/cohere/types/generate_stream_text.py @@ -4,21 +4,17 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .generate_stream_event import GenerateStreamEvent -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - class GenerateStreamText(GenerateStreamEvent): - text: str = pydantic.Field() + text: str = pydantic_v1.Field() """ A segment of text of the generation. """ - index: typing.Optional[int] = pydantic.Field(default=None) + index: typing.Optional[int] = pydantic_v1.Field(default=None) """ Refers to the nth generation. Only present when `num_generations` is greater than zero, and only when text responses are being streamed. """ @@ -38,5 +34,5 @@ class Config: smart_union = True allow_population_by_field_name = True populate_by_name = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/generate_streamed_response.py b/src/cohere/types/generate_streamed_response.py index 6c20aa8fe..f3f57c1b7 100644 --- a/src/cohere/types/generate_streamed_response.py +++ b/src/cohere/types/generate_streamed_response.py @@ -10,7 +10,7 @@ class GenerateStreamedResponse_TextGeneration(GenerateStreamText): - event_type: typing.Literal["text-generation"] + event_type: typing.Literal["text-generation"] = "text-generation" class Config: frozen = True @@ -20,7 +20,7 @@ class Config: class GenerateStreamedResponse_StreamEnd(GenerateStreamEnd): - event_type: typing.Literal["stream-end"] + event_type: typing.Literal["stream-end"] = "stream-end" class Config: frozen = True @@ -30,7 +30,7 @@ class Config: class GenerateStreamedResponse_StreamError(GenerateStreamError): - event_type: typing.Literal["stream-error"] + event_type: typing.Literal["stream-error"] = "stream-error" class Config: frozen = True diff --git a/src/cohere/types/generation.py b/src/cohere/types/generation.py index 6000dd328..db5a2bfa7 100644 --- a/src/cohere/types/generation.py +++ b/src/cohere/types/generation.py @@ -4,23 +4,19 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .api_meta import ApiMeta from .single_generation import SingleGeneration -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class Generation(pydantic.BaseModel): +class Generation(pydantic_v1.BaseModel): id: str - prompt: typing.Optional[str] = pydantic.Field(default=None) + prompt: typing.Optional[str] = pydantic_v1.Field(default=None) """ Prompt used for generations. """ - generations: typing.List[SingleGeneration] = pydantic.Field() + generations: typing.List[SingleGeneration] = pydantic_v1.Field() """ List of generated results """ @@ -38,5 +34,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/get_connector_response.py b/src/cohere/types/get_connector_response.py index 4451024e9..97ef93d73 100644 --- a/src/cohere/types/get_connector_response.py +++ b/src/cohere/types/get_connector_response.py @@ -4,15 +4,11 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .connector import Connector -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class GetConnectorResponse(pydantic.BaseModel): +class GetConnectorResponse(pydantic_v1.BaseModel): connector: Connector def json(self, **kwargs: typing.Any) -> str: @@ -26,5 +22,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/get_model_response.py b/src/cohere/types/get_model_response.py index 910aa045b..28378d370 100644 --- a/src/cohere/types/get_model_response.py +++ b/src/cohere/types/get_model_response.py @@ -4,45 +4,41 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .compatible_endpoint import CompatibleEndpoint -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class GetModelResponse(pydantic.BaseModel): +class GetModelResponse(pydantic_v1.BaseModel): """ Contains information about the model and which API endpoints it can be used with. """ - name: typing.Optional[str] = pydantic.Field(default=None) + name: typing.Optional[str] = pydantic_v1.Field(default=None) """ Specify this name in the `model` parameter of API requests to use your chosen model. """ - endpoints: typing.Optional[typing.List[CompatibleEndpoint]] = pydantic.Field(default=None) + endpoints: typing.Optional[typing.List[CompatibleEndpoint]] = pydantic_v1.Field(default=None) """ The API endpoints that the model is compatible with. """ - finetuned: typing.Optional[bool] = pydantic.Field(default=None) + finetuned: typing.Optional[bool] = pydantic_v1.Field(default=None) """ Whether the model has been fine-tuned or not. """ - context_length: typing.Optional[float] = pydantic.Field(default=None) + context_length: typing.Optional[float] = pydantic_v1.Field(default=None) """ The maximum number of tokens that the model can process in a single request. Note that not all of these tokens are always available due to special tokens and preambles that Cohere has added by default. """ - tokenizer: typing.Optional[str] = pydantic.Field(default=None) + tokenizer: typing.Optional[str] = pydantic_v1.Field(default=None) """ The name of the tokenizer used for the model. """ - tokenizer_url: typing.Optional[str] = pydantic.Field(default=None) + tokenizer_url: typing.Optional[str] = pydantic_v1.Field(default=None) """ Public URL to the tokenizer's configuration file. """ @@ -58,5 +54,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/label_metric.py b/src/cohere/types/label_metric.py index f9edc886a..43122c516 100644 --- a/src/cohere/types/label_metric.py +++ b/src/cohere/types/label_metric.py @@ -4,25 +4,21 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class LabelMetric(pydantic.BaseModel): - total_examples: typing.Optional[str] = pydantic.Field(alias="totalExamples", default=None) +class LabelMetric(pydantic_v1.BaseModel): + total_examples: typing.Optional[str] = pydantic_v1.Field(alias="totalExamples", default=None) """ Total number of examples for this label """ - label: typing.Optional[str] = pydantic.Field(default=None) + label: typing.Optional[str] = pydantic_v1.Field(default=None) """ value of the label """ - samples: typing.Optional[typing.List[str]] = pydantic.Field(default=None) + samples: typing.Optional[typing.List[str]] = pydantic_v1.Field(default=None) """ samples for this label """ @@ -40,5 +36,5 @@ class Config: smart_union = True allow_population_by_field_name = True populate_by_name = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/list_connectors_response.py b/src/cohere/types/list_connectors_response.py index 0adc1fb9b..ca1a598fa 100644 --- a/src/cohere/types/list_connectors_response.py +++ b/src/cohere/types/list_connectors_response.py @@ -4,17 +4,13 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .connector import Connector -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ListConnectorsResponse(pydantic.BaseModel): +class ListConnectorsResponse(pydantic_v1.BaseModel): connectors: typing.List[Connector] - total_count: typing.Optional[float] = pydantic.Field(default=None) + total_count: typing.Optional[float] = pydantic_v1.Field(default=None) """ Total number of connectors. """ @@ -30,5 +26,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/list_embed_job_response.py b/src/cohere/types/list_embed_job_response.py index 6b520333f..73a19aff9 100644 --- a/src/cohere/types/list_embed_job_response.py +++ b/src/cohere/types/list_embed_job_response.py @@ -4,15 +4,11 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .embed_job import EmbedJob -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ListEmbedJobResponse(pydantic.BaseModel): +class ListEmbedJobResponse(pydantic_v1.BaseModel): embed_jobs: typing.Optional[typing.List[EmbedJob]] = None def json(self, **kwargs: typing.Any) -> str: @@ -26,5 +22,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/list_models_response.py b/src/cohere/types/list_models_response.py index 93e1394ce..054cb4f5a 100644 --- a/src/cohere/types/list_models_response.py +++ b/src/cohere/types/list_models_response.py @@ -4,17 +4,13 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .get_model_response import GetModelResponse -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ListModelsResponse(pydantic.BaseModel): +class ListModelsResponse(pydantic_v1.BaseModel): models: typing.List[GetModelResponse] - next_page_token: typing.Optional[str] = pydantic.Field(default=None) + next_page_token: typing.Optional[str] = pydantic_v1.Field(default=None) """ A token to retrieve the next page of results. Provide in the page_token parameter of the next request. """ @@ -30,5 +26,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/metrics.py b/src/cohere/types/metrics.py index f4d8dafcc..9802cd2ae 100644 --- a/src/cohere/types/metrics.py +++ b/src/cohere/types/metrics.py @@ -4,15 +4,11 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .finetune_dataset_metrics import FinetuneDatasetMetrics -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class Metrics(pydantic.BaseModel): +class Metrics(pydantic_v1.BaseModel): finetune_dataset_metrics: typing.Optional[FinetuneDatasetMetrics] = None def json(self, **kwargs: typing.Any) -> str: @@ -26,5 +22,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/non_streamed_chat_response.py b/src/cohere/types/non_streamed_chat_response.py index 8bae6c0da..043412524 100644 --- a/src/cohere/types/non_streamed_chat_response.py +++ b/src/cohere/types/non_streamed_chat_response.py @@ -4,6 +4,7 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .chat_citation import ChatCitation from .chat_document import ChatDocument from .chat_message import ChatMessage @@ -12,51 +13,46 @@ from .finish_reason import FinishReason from .tool_call import ToolCall -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class NonStreamedChatResponse(pydantic.BaseModel): - text: str = pydantic.Field() +class NonStreamedChatResponse(pydantic_v1.BaseModel): + text: str = pydantic_v1.Field() """ Contents of the reply generated by the model. """ - generation_id: typing.Optional[str] = pydantic.Field(default=None) + generation_id: typing.Optional[str] = pydantic_v1.Field(default=None) """ Unique identifier for the generated reply. Useful for submitting feedback. """ - citations: typing.Optional[typing.List[ChatCitation]] = pydantic.Field(default=None) + citations: typing.Optional[typing.List[ChatCitation]] = pydantic_v1.Field(default=None) """ Inline citations for the generated reply. """ - documents: typing.Optional[typing.List[ChatDocument]] = pydantic.Field(default=None) + documents: typing.Optional[typing.List[ChatDocument]] = pydantic_v1.Field(default=None) """ Documents seen by the model when generating the reply. """ - is_search_required: typing.Optional[bool] = pydantic.Field(default=None) + is_search_required: typing.Optional[bool] = pydantic_v1.Field(default=None) """ Denotes that a search for documents is required during the RAG flow. """ - search_queries: typing.Optional[typing.List[ChatSearchQuery]] = pydantic.Field(default=None) + search_queries: typing.Optional[typing.List[ChatSearchQuery]] = pydantic_v1.Field(default=None) """ Generated search queries, meant to be used as part of the RAG flow. """ - search_results: typing.Optional[typing.List[ChatSearchResult]] = pydantic.Field(default=None) + search_results: typing.Optional[typing.List[ChatSearchResult]] = pydantic_v1.Field(default=None) """ Documents retrieved from each of the conducted searches. """ finish_reason: typing.Optional[FinishReason] = None tool_calls: typing.Optional[typing.List[ToolCall]] = None - chat_history: typing.Optional[typing.List[ChatMessage]] = pydantic.Field(default=None) + chat_history: typing.Optional[typing.List[ChatMessage]] = pydantic_v1.Field(default=None) """ A list of previous messages between the user and the model, meant to give the model conversational context for responding to the user's `message`. """ @@ -72,5 +68,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/o_auth_authorize_response.py b/src/cohere/types/o_auth_authorize_response.py index 690f6758c..a7046f717 100644 --- a/src/cohere/types/o_auth_authorize_response.py +++ b/src/cohere/types/o_auth_authorize_response.py @@ -4,15 +4,11 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class OAuthAuthorizeResponse(pydantic.BaseModel): - redirect_url: typing.Optional[str] = pydantic.Field(default=None) +class OAuthAuthorizeResponse(pydantic_v1.BaseModel): + redirect_url: typing.Optional[str] = pydantic_v1.Field(default=None) """ The OAuth 2.0 redirect url. Redirect the user to this url to authorize the connector. """ @@ -28,5 +24,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/parse_info.py b/src/cohere/types/parse_info.py index 280f1b154..7b3c5a75b 100644 --- a/src/cohere/types/parse_info.py +++ b/src/cohere/types/parse_info.py @@ -4,14 +4,10 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ParseInfo(pydantic.BaseModel): +class ParseInfo(pydantic_v1.BaseModel): separator: typing.Optional[str] = None delimiter: typing.Optional[str] = None @@ -26,5 +22,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/rerank_request_documents_item_text.py b/src/cohere/types/rerank_request_documents_item_text.py index 89f0fcb7a..f1c2a1761 100644 --- a/src/cohere/types/rerank_request_documents_item_text.py +++ b/src/cohere/types/rerank_request_documents_item_text.py @@ -4,15 +4,11 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class RerankRequestDocumentsItemText(pydantic.BaseModel): - text: str = pydantic.Field() +class RerankRequestDocumentsItemText(pydantic_v1.BaseModel): + text: str = pydantic_v1.Field() """ The text of the document to rerank. """ @@ -28,5 +24,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/rerank_response.py b/src/cohere/types/rerank_response.py index f04f3582c..931cfa97a 100644 --- a/src/cohere/types/rerank_response.py +++ b/src/cohere/types/rerank_response.py @@ -4,18 +4,14 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .api_meta import ApiMeta from .rerank_response_results_item import RerankResponseResultsItem -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class RerankResponse(pydantic.BaseModel): +class RerankResponse(pydantic_v1.BaseModel): id: typing.Optional[str] = None - results: typing.List[RerankResponseResultsItem] = pydantic.Field() + results: typing.List[RerankResponseResultsItem] = pydantic_v1.Field() """ An ordered list of ranked documents """ @@ -33,5 +29,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/rerank_response_results_item.py b/src/cohere/types/rerank_response_results_item.py index 48d32d276..605b7be96 100644 --- a/src/cohere/types/rerank_response_results_item.py +++ b/src/cohere/types/rerank_response_results_item.py @@ -4,26 +4,22 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .rerank_response_results_item_document import RerankResponseResultsItemDocument -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class RerankResponseResultsItem(pydantic.BaseModel): - document: typing.Optional[RerankResponseResultsItemDocument] = pydantic.Field(default=None) +class RerankResponseResultsItem(pydantic_v1.BaseModel): + document: typing.Optional[RerankResponseResultsItemDocument] = pydantic_v1.Field(default=None) """ The doc object which was ranked """ - index: int = pydantic.Field() + index: int = pydantic_v1.Field() """ The index of the input document """ - relevance_score: float = pydantic.Field() + relevance_score: float = pydantic_v1.Field() """ A relevance score assigned to the ranking """ @@ -39,5 +35,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/rerank_response_results_item_document.py b/src/cohere/types/rerank_response_results_item_document.py index 5e3925885..28ca7b902 100644 --- a/src/cohere/types/rerank_response_results_item_document.py +++ b/src/cohere/types/rerank_response_results_item_document.py @@ -4,19 +4,15 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class RerankResponseResultsItemDocument(pydantic.BaseModel): +class RerankResponseResultsItemDocument(pydantic_v1.BaseModel): """ The doc object which was ranked """ - text: str = pydantic.Field() + text: str = pydantic_v1.Field() """ The text of the document to rerank """ @@ -32,5 +28,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/reranker_data_metrics.py b/src/cohere/types/reranker_data_metrics.py index a0ab206f6..1ecfe53e7 100644 --- a/src/cohere/types/reranker_data_metrics.py +++ b/src/cohere/types/reranker_data_metrics.py @@ -4,40 +4,38 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class RerankerDataMetrics(pydantic.BaseModel): - num_train_queries: typing.Optional[str] = pydantic.Field(alias="numTrainQueries", default=None) +class RerankerDataMetrics(pydantic_v1.BaseModel): + num_train_queries: typing.Optional[str] = pydantic_v1.Field(alias="numTrainQueries", default=None) """ The number of training queries. """ - num_train_relevant_passages: typing.Optional[str] = pydantic.Field(alias="numTrainRelevantPassages", default=None) + num_train_relevant_passages: typing.Optional[str] = pydantic_v1.Field( + alias="numTrainRelevantPassages", default=None + ) """ The sum of all relevant passages of valid training examples. """ - num_train_hard_negatives: typing.Optional[str] = pydantic.Field(alias="numTrainHardNegatives", default=None) + num_train_hard_negatives: typing.Optional[str] = pydantic_v1.Field(alias="numTrainHardNegatives", default=None) """ The sum of all hard negatives of valid training examples. """ - num_eval_queries: typing.Optional[str] = pydantic.Field(alias="numEvalQueries", default=None) + num_eval_queries: typing.Optional[str] = pydantic_v1.Field(alias="numEvalQueries", default=None) """ The number of evaluation queries. """ - num_eval_relevant_passages: typing.Optional[str] = pydantic.Field(alias="numEvalRelevantPassages", default=None) + num_eval_relevant_passages: typing.Optional[str] = pydantic_v1.Field(alias="numEvalRelevantPassages", default=None) """ The sum of all relevant passages of valid eval examples. """ - num_eval_hard_negatives: typing.Optional[str] = pydantic.Field(alias="numEvalHardNegatives", default=None) + num_eval_hard_negatives: typing.Optional[str] = pydantic_v1.Field(alias="numEvalHardNegatives", default=None) """ The sum of all hard negatives of valid eval examples. """ @@ -55,5 +53,5 @@ class Config: smart_union = True allow_population_by_field_name = True populate_by_name = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/single_generation.py b/src/cohere/types/single_generation.py index 03fe8c538..93a803c45 100644 --- a/src/cohere/types/single_generation.py +++ b/src/cohere/types/single_generation.py @@ -4,24 +4,22 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .single_generation_token_likelihoods_item import SingleGenerationTokenLikelihoodsItem -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class SingleGeneration(pydantic.BaseModel): +class SingleGeneration(pydantic_v1.BaseModel): id: str text: str - index: typing.Optional[int] = pydantic.Field(default=None) + index: typing.Optional[int] = pydantic_v1.Field(default=None) """ Refers to the nth generation. Only present when `num_generations` is greater than zero. """ likelihood: typing.Optional[float] = None - token_likelihoods: typing.Optional[typing.List[SingleGenerationTokenLikelihoodsItem]] = pydantic.Field(default=None) + token_likelihoods: typing.Optional[typing.List[SingleGenerationTokenLikelihoodsItem]] = pydantic_v1.Field( + default=None + ) """ Only returned if `return_likelihoods` is set to `GENERATION` or `ALL`. The likelihood refers to the average log-likelihood of the entire specified string, which is useful for [evaluating the performance of your model](likelihood-eval), especially if you've created a [custom model](/docs/training-custom-models). Individual token likelihoods provide the log-likelihood of each token. The first token will not have a likelihood. """ @@ -37,5 +35,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/single_generation_in_stream.py b/src/cohere/types/single_generation_in_stream.py index 34a81ed04..949da6574 100644 --- a/src/cohere/types/single_generation_in_stream.py +++ b/src/cohere/types/single_generation_in_stream.py @@ -4,22 +4,18 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .finish_reason import FinishReason -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class SingleGenerationInStream(pydantic.BaseModel): +class SingleGenerationInStream(pydantic_v1.BaseModel): id: str - text: str = pydantic.Field() + text: str = pydantic_v1.Field() """ Full text of the generation. """ - index: typing.Optional[int] = pydantic.Field(default=None) + index: typing.Optional[int] = pydantic_v1.Field(default=None) """ Refers to the nth generation. Only present when `num_generations` is greater than zero. """ @@ -37,5 +33,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/single_generation_token_likelihoods_item.py b/src/cohere/types/single_generation_token_likelihoods_item.py index f78510ada..4916f2dda 100644 --- a/src/cohere/types/single_generation_token_likelihoods_item.py +++ b/src/cohere/types/single_generation_token_likelihoods_item.py @@ -4,14 +4,10 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class SingleGenerationTokenLikelihoodsItem(pydantic.BaseModel): +class SingleGenerationTokenLikelihoodsItem(pydantic_v1.BaseModel): token: str likelihood: float @@ -26,5 +22,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/streamed_chat_response.py b/src/cohere/types/streamed_chat_response.py index e99b351a7..a3c9db19a 100644 --- a/src/cohere/types/streamed_chat_response.py +++ b/src/cohere/types/streamed_chat_response.py @@ -14,7 +14,7 @@ class StreamedChatResponse_StreamStart(ChatStreamStartEvent): - event_type: typing.Literal["stream-start"] + event_type: typing.Literal["stream-start"] = "stream-start" class Config: frozen = True @@ -24,7 +24,7 @@ class Config: class StreamedChatResponse_SearchQueriesGeneration(ChatSearchQueriesGenerationEvent): - event_type: typing.Literal["search-queries-generation"] + event_type: typing.Literal["search-queries-generation"] = "search-queries-generation" class Config: frozen = True @@ -34,7 +34,7 @@ class Config: class StreamedChatResponse_SearchResults(ChatSearchResultsEvent): - event_type: typing.Literal["search-results"] + event_type: typing.Literal["search-results"] = "search-results" class Config: frozen = True @@ -44,7 +44,7 @@ class Config: class StreamedChatResponse_TextGeneration(ChatTextGenerationEvent): - event_type: typing.Literal["text-generation"] + event_type: typing.Literal["text-generation"] = "text-generation" class Config: frozen = True @@ -54,7 +54,7 @@ class Config: class StreamedChatResponse_CitationGeneration(ChatCitationGenerationEvent): - event_type: typing.Literal["citation-generation"] + event_type: typing.Literal["citation-generation"] = "citation-generation" class Config: frozen = True @@ -64,7 +64,7 @@ class Config: class StreamedChatResponse_ToolCallsGeneration(ChatToolCallsGenerationEvent): - event_type: typing.Literal["tool-calls-generation"] + event_type: typing.Literal["tool-calls-generation"] = "tool-calls-generation" class Config: frozen = True @@ -74,7 +74,7 @@ class Config: class StreamedChatResponse_StreamEnd(ChatStreamEndEvent): - event_type: typing.Literal["stream-end"] + event_type: typing.Literal["stream-end"] = "stream-end" class Config: frozen = True diff --git a/src/cohere/types/summarize_response.py b/src/cohere/types/summarize_response.py index ad62c38f0..7e7dde5e1 100644 --- a/src/cohere/types/summarize_response.py +++ b/src/cohere/types/summarize_response.py @@ -4,21 +4,17 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .api_meta import ApiMeta -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class SummarizeResponse(pydantic.BaseModel): - id: typing.Optional[str] = pydantic.Field(default=None) +class SummarizeResponse(pydantic_v1.BaseModel): + id: typing.Optional[str] = pydantic_v1.Field(default=None) """ Generated ID for the summary """ - summary: typing.Optional[str] = pydantic.Field(default=None) + summary: typing.Optional[str] = pydantic_v1.Field(default=None) """ Generated summary for the text """ @@ -36,5 +32,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/tokenize_response.py b/src/cohere/types/tokenize_response.py index 4f24fdb92..661d6f7b7 100644 --- a/src/cohere/types/tokenize_response.py +++ b/src/cohere/types/tokenize_response.py @@ -4,16 +4,12 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .api_meta import ApiMeta -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class TokenizeResponse(pydantic.BaseModel): - tokens: typing.List[int] = pydantic.Field() +class TokenizeResponse(pydantic_v1.BaseModel): + tokens: typing.List[int] = pydantic_v1.Field() """ An array of tokens, where each token is an integer. """ @@ -32,5 +28,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/tool.py b/src/cohere/types/tool.py index f62b08a32..a083411c2 100644 --- a/src/cohere/types/tool.py +++ b/src/cohere/types/tool.py @@ -4,26 +4,22 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .tool_parameter_definitions_value import ToolParameterDefinitionsValue -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class Tool(pydantic.BaseModel): - name: str = pydantic.Field() +class Tool(pydantic_v1.BaseModel): + name: str = pydantic_v1.Field() """ The name of the tool to be called. Valid names contain only the characters `a-z`, `A-Z`, `0-9`, `_` and must not begin with a digit. """ - description: str = pydantic.Field() + description: str = pydantic_v1.Field() """ The description of what the tool does, the model uses the description to choose when and how to call the function. """ - parameter_definitions: typing.Optional[typing.Dict[str, ToolParameterDefinitionsValue]] = pydantic.Field( + parameter_definitions: typing.Optional[typing.Dict[str, ToolParameterDefinitionsValue]] = pydantic_v1.Field( default=None ) """ @@ -51,5 +47,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/tool_call.py b/src/cohere/types/tool_call.py index f98b6398c..3ef653fe1 100644 --- a/src/cohere/types/tool_call.py +++ b/src/cohere/types/tool_call.py @@ -4,24 +4,20 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ToolCall(pydantic.BaseModel): +class ToolCall(pydantic_v1.BaseModel): """ Contains the tool calls generated by the model. Use it to invoke your tools. """ - name: str = pydantic.Field() + name: str = pydantic_v1.Field() """ Name of the tool to call. """ - parameters: typing.Dict[str, typing.Any] = pydantic.Field() + parameters: typing.Dict[str, typing.Any] = pydantic_v1.Field() """ The name and value of the parameters to use when invoking a tool. """ @@ -37,5 +33,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/tool_parameter_definitions_value.py b/src/cohere/types/tool_parameter_definitions_value.py index 4556d4905..0c52e7ba7 100644 --- a/src/cohere/types/tool_parameter_definitions_value.py +++ b/src/cohere/types/tool_parameter_definitions_value.py @@ -4,25 +4,21 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class ToolParameterDefinitionsValue(pydantic.BaseModel): - description: typing.Optional[str] = pydantic.Field(default=None) +class ToolParameterDefinitionsValue(pydantic_v1.BaseModel): + description: typing.Optional[str] = pydantic_v1.Field(default=None) """ The description of the parameter. """ - type: str = pydantic.Field() + type: str = pydantic_v1.Field() """ The type of the parameter. Must be a valid Python type. """ - required: typing.Optional[bool] = pydantic.Field(default=None) + required: typing.Optional[bool] = pydantic_v1.Field(default=None) """ Denotes whether the parameter is always present (required) or not. Defaults to not required. """ @@ -38,5 +34,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/update_connector_response.py b/src/cohere/types/update_connector_response.py index 54a68f09f..2d6d768ac 100644 --- a/src/cohere/types/update_connector_response.py +++ b/src/cohere/types/update_connector_response.py @@ -4,15 +4,11 @@ import typing from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import pydantic_v1 from .connector import Connector -try: - import pydantic.v1 as pydantic # type: ignore -except ImportError: - import pydantic # type: ignore - -class UpdateConnectorResponse(pydantic.BaseModel): +class UpdateConnectorResponse(pydantic_v1.BaseModel): connector: Connector def json(self, **kwargs: typing.Any) -> str: @@ -26,5 +22,5 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: class Config: frozen = True smart_union = True - extra = pydantic.Extra.allow + extra = pydantic_v1.Extra.allow json_encoders = {dt.datetime: serialize_datetime}