diff --git a/poetry.lock b/poetry.lock index b928f8407..b70edfcbe 100644 --- a/poetry.lock +++ b/poetry.lock @@ -38,17 +38,17 @@ trio = ["trio (>=0.23)"] [[package]] name = "boto3" -version = "1.34.146" +version = "1.34.145" description = "The AWS SDK for Python" optional = false python-versions = ">=3.8" files = [ - {file = "boto3-1.34.146-py3-none-any.whl", hash = "sha256:7ec568fb19bce82a70be51f08fddac1ef927ca3fb0896cbb34303a012ba228d8"}, - {file = "boto3-1.34.146.tar.gz", hash = "sha256:5686fe2a6d1aa1de8a88e9589cdcc33361640d3d7a13da718a30717248886124"}, + {file = "boto3-1.34.145-py3-none-any.whl", hash = "sha256:69d5afb7a017d07dd6bdfb680d2912d5d369b3fafa0a45161207d9f393b14d7e"}, + {file = "boto3-1.34.145.tar.gz", hash = "sha256:ac770fb53dde1743aec56bd8e56b7ee2e2f5ad42a37825968ec4ff8428822640"}, ] [package.dependencies] -botocore = ">=1.34.146,<1.35.0" +botocore = ">=1.34.145,<1.35.0" jmespath = ">=0.7.1,<2.0.0" s3transfer = ">=0.10.0,<0.11.0" @@ -57,13 +57,13 @@ crt = ["botocore[crt] (>=1.21.0,<2.0a0)"] [[package]] name = "botocore" -version = "1.34.146" +version = "1.34.145" description = "Low-level, data-driven core of boto 3." optional = false python-versions = ">=3.8" files = [ - {file = "botocore-1.34.146-py3-none-any.whl", hash = "sha256:3fd4782362bd29c192704ebf859c5c8c5189ad05719e391eefe23088434427ae"}, - {file = "botocore-1.34.146.tar.gz", hash = "sha256:849cb8e54e042443aeabcd7822b5f2b76cb5cfe33fe3a71f91c7c069748a869c"}, + {file = "botocore-1.34.145-py3-none-any.whl", hash = "sha256:2e72e262de02adcb0264ac2bac159a28f55dbba8d9e52aa0308773a42950dff5"}, + {file = "botocore-1.34.145.tar.gz", hash = "sha256:edf0fb4c02186ae29b76263ac5fda18b0a085d334a310551c9984407cf1079e6"}, ] [package.dependencies] @@ -382,13 +382,13 @@ files = [ [[package]] name = "huggingface-hub" -version = "0.24.1" +version = "0.24.0" description = "Client library to download and publish models, datasets and other repos on the huggingface.co hub" optional = false python-versions = ">=3.8.0" files = [ - {file = "huggingface_hub-0.24.1-py3-none-any.whl", hash = "sha256:d3a623d0f2cbb9399299aefc85e3423fa2689f18ab9b6e1aa0f95d1793889f30"}, - {file = "huggingface_hub-0.24.1.tar.gz", hash = "sha256:6915e34c7b1282b0f7c2387c12db21003b79889f1dad57da0434ecd10f3293a8"}, + {file = "huggingface_hub-0.24.0-py3-none-any.whl", hash = "sha256:7ad92edefb93d8145c061f6df8d99df2ff85f8379ba5fac8a95aca0642afa5d7"}, + {file = "huggingface_hub-0.24.0.tar.gz", hash = "sha256:6c7092736b577d89d57b3cdfea026f1b0dc2234ae783fa0d59caf1bf7d52dfa7"}, ] [package.dependencies] @@ -1086,4 +1086,4 @@ zstd = ["zstandard (>=0.18.0)"] [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "318623e66274694b6aa5af32280d5f81b82e6df59bd4cebeb8a8c840ad235b4d" +content-hash = "9b7a0f3e6027d6e2d5e1ec9c45a405f776b03c9c7935cb30b7fe8aec23683ce2" diff --git a/pyproject.toml b/pyproject.toml index 68ec1e806..3f03a05e2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cohere" -version = "5.7.0" +version = "5.6.2" description = "" readme = "README.md" authors = [] @@ -38,7 +38,6 @@ httpx = ">=0.21.2" httpx-sse = "^0.4.0" parameterized = "^0.9.0" pydantic = ">= 1.9.2" -pydantic-core = "^2.18.2" requests = "^2.0.0" tokenizers = ">=0.15,<1" types-requests = "^2.0.0" diff --git a/reference.md b/reference.md deleted file mode 100644 index 327943257..000000000 --- a/reference.md +++ /dev/null @@ -1,4338 +0,0 @@ -# Reference -
client.chat_stream(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -Generates a text response to a user message. -To learn how to use the Chat API with Streaming and RAG follow our [Text Generation guides](https://docs.cohere.com/docs/chat-api). -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere import ( - ChatConnector, - ChatStreamRequestConnectorsSearchOptions, - Message_Chatbot, - ResponseFormat_Text, - Tool, - ToolCall, - ToolParameterDefinitionsValue, - ToolResult, -) -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -response = client.chat_stream( - message="string", - model="string", - preamble="string", - chat_history=[ - Message_Chatbot( - message="string", - tool_calls=[ - ToolCall( - name="string", - parameters={"string": {"key": "value"}}, - ) - ], - ) - ], - conversation_id="string", - prompt_truncation="OFF", - connectors=[ - ChatConnector( - id="string", - user_access_token="string", - continue_on_failure=True, - options={"string": {"key": "value"}}, - ) - ], - search_queries_only=True, - documents=[{"string": {"key": "value"}}], - citation_quality="fast", - temperature=1.1, - max_tokens=1, - max_input_tokens=1, - k=1, - p=1.1, - seed=1, - stop_sequences=["string"], - connectors_search_options=ChatStreamRequestConnectorsSearchOptions( - seed=1, - ), - frequency_penalty=1.1, - presence_penalty=1.1, - raw_prompting=True, - return_prompt=True, - tools=[ - Tool( - name="string", - description="string", - parameter_definitions={ - "string": ToolParameterDefinitionsValue( - description="string", - type="string", - required=True, - ) - }, - ) - ], - tool_results=[ - ToolResult( - call=ToolCall( - name="string", - parameters={"string": {"key": "value"}}, - ), - outputs=[{"string": {"key": "value"}}], - ) - ], - force_single_step=True, - response_format=ResponseFormat_Text(), -) -for chunk in response: - yield chunk - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**message:** `str` - -Text input for the model to respond to. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**model:** `typing.Optional[str]` - -Defaults to `command-r-plus`. - -The name of a compatible [Cohere model](https://docs.cohere.com/docs/models) or the ID of a [fine-tuned](https://docs.cohere.com/docs/chat-fine-tuning) model. -Compatible Deployments: Cohere Platform, Private Deployments - - -
-
- -
-
- -**preamble:** `typing.Optional[str]` - -When specified, the default Cohere preamble will be replaced with the provided one. Preambles are a part of the prompt used to adjust the model's overall behavior and conversation style, and use the `SYSTEM` role. - -The `SYSTEM` role is also used for the contents of the optional `chat_history=` parameter. When used with the `chat_history=` parameter it adds content throughout a conversation. Conversely, when used with the `preamble=` parameter it adds content at the start of the conversation only. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**chat_history:** `typing.Optional[typing.Sequence[Message]]` - -A list of previous messages between the user and the model, giving the model conversational context for responding to the user's `message`. - -Each item 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. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**conversation_id:** `typing.Optional[str]` - -An alternative to `chat_history`. - -Providing a `conversation_id` creates or resumes a persisted conversation with the specified ID. The ID can be any non empty string. -Compatible Deployments: Cohere Platform - - -
-
- -
-
- -**prompt_truncation:** `typing.Optional[ChatStreamRequestPromptTruncation]` - -Defaults to `AUTO` when `connectors` are specified and `OFF` in all other cases. - -Dictates how the prompt will be constructed. - -With `prompt_truncation` set to "AUTO", some elements from `chat_history` and `documents` will be dropped in an attempt to construct a prompt that fits within the model's context length limit. During this process the order of the documents and chat history will be changed and ranked by relevance. - -With `prompt_truncation` set to "AUTO_PRESERVE_ORDER", some elements from `chat_history` and `documents` will be dropped in an attempt to construct a prompt that fits within the model's context length limit. During this process the order of the documents and chat history will be preserved as they are inputted into the API. - -With `prompt_truncation` set to "OFF", no elements will be dropped. If the sum of the inputs exceeds the model's context length limit, a `TooManyTokens` error will be returned. -Compatible Deployments: Cohere Platform Only AUTO_PRESERVE_ORDER: Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**connectors:** `typing.Optional[typing.Sequence[ChatConnector]]` - -Accepts `{"id": "web-search"}`, and/or the `"id"` for a custom [connector](https://docs.cohere.com/docs/connectors), if you've [created](https://docs.cohere.com/docs/creating-and-deploying-a-connector) one. - -When specified, the model's reply will be enriched with information found by querying each of the connectors (RAG). -Compatible Deployments: Cohere Platform - - -
-
- -
-
- -**search_queries_only:** `typing.Optional[bool]` - -Defaults to `false`. - -When `true`, the response will only contain a list of generated search queries, but no search will take place, and no reply from the model to the user's `message` will be generated. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**documents:** `typing.Optional[typing.Sequence[ChatDocument]]` - -A list of relevant documents that the model can cite to generate a more accurate reply. Each document is a string-string dictionary. - -Example: -`[ - { "title": "Tall penguins", "text": "Emperor penguins are the tallest." }, - { "title": "Penguin habitats", "text": "Emperor penguins only live in Antarctica." }, -]` - -Keys and values from each document will be serialized to a string and passed to the model. The resulting generation will include citations that reference some of these documents. - -Some suggested keys are "text", "author", and "date". For better generation quality, it is recommended to keep the total word count of the strings in the dictionary to under 300 words. - -An `id` field (string) can be optionally supplied to identify the document in the citations. This field will not be passed to the model. - -An `_excludes` field (array of strings) can be optionally supplied to omit some key-value pairs from being shown to the model. The omitted fields will still show up in the citation object. The "_excludes" field will not be passed to the model. - -See ['Document Mode'](https://docs.cohere.com/docs/retrieval-augmented-generation-rag#document-mode) in the guide for more information. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**citation_quality:** `typing.Optional[ChatStreamRequestCitationQuality]` - -Defaults to `"accurate"`. - -Dictates the approach taken to generating citations as part of the RAG flow by allowing the user to specify whether they want `"accurate"` results, `"fast"` results or no results. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**temperature:** `typing.Optional[float]` - -Defaults to `0.3`. - -A non-negative float that tunes the degree of randomness in generation. Lower temperatures mean less random generations, and higher temperatures mean more random generations. - -Randomness can be further maximized by increasing the value of the `p` parameter. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**max_tokens:** `typing.Optional[int]` - -The maximum number of tokens the model will generate as part of the response. Note: Setting a low value may result in incomplete generations. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**max_input_tokens:** `typing.Optional[int]` - -The maximum number of input tokens to send to the model. If not specified, `max_input_tokens` is the model's context length limit minus a small buffer. - -Input will be truncated according to the `prompt_truncation` parameter. -Compatible Deployments: Cohere Platform - - -
-
- -
-
- -**k:** `typing.Optional[int]` - -Ensures only the top `k` most likely tokens are considered for generation at each step. -Defaults to `0`, min value of `0`, max value of `500`. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**p:** `typing.Optional[float]` - -Ensures that only the most likely tokens, with total probability mass of `p`, are considered for generation at each step. If both `k` and `p` are enabled, `p` acts after `k`. -Defaults to `0.75`. min value of `0.01`, max value of `0.99`. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**seed:** `typing.Optional[int]` - -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, -determinism cannot be totally guaranteed. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**stop_sequences:** `typing.Optional[typing.Sequence[str]]` - -A list of up to 5 strings that the model will use to stop generation. If the model generates a string that matches any of the strings in the list, it will stop generating tokens and return the generated text up to that point not including the stop sequence. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**frequency_penalty:** `typing.Optional[float]` - -Defaults to `0.0`, min value of `0.0`, max value of `1.0`. - -Used to reduce repetitiveness of generated tokens. The higher the value, the stronger a penalty is applied to previously present tokens, proportional to how many times they have already appeared in the prompt or prior generation. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**presence_penalty:** `typing.Optional[float]` - -Defaults to `0.0`, min value of `0.0`, max value of `1.0`. - -Used to reduce repetitiveness of generated tokens. Similar to `frequency_penalty`, except that this penalty is applied equally to all tokens that have already appeared, regardless of their exact frequencies. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**raw_prompting:** `typing.Optional[bool]` - -When enabled, the user's prompt will be sent to the model without -any pre-processing. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**return_prompt:** `typing.Optional[bool]` β€” The prompt is returned in the `prompt` response field when this is enabled. - -
-
- -
-
- -**tools:** `typing.Optional[typing.Sequence[Tool]]` - -A list of available tools (functions) that the model may suggest invoking before producing a text response. - -When `tools` is passed (without `tool_results`), the `text` field in the response will be `""` and the `tool_calls` field in the response will be populated with a list of tool calls that need to be made. If no calls need to be made, the `tool_calls` array will be empty. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**tool_results:** `typing.Optional[typing.Sequence[ToolResult]]` - -A list of results from invoking tools recommended by the model in the previous chat turn. Results are used to produce a text response and will be referenced in citations. When using `tool_results`, `tools` must be passed as well. -Each tool_result contains information about how it was invoked, as well as a list of outputs in the form of dictionaries. - -**Note**: `outputs` must be a list of objects. If your tool returns a single object (eg `{"status": 200}`), make sure to wrap it in a list. -``` -tool_results = [ - { - "call": { - "name": , - "parameters": { - : - } - }, - "outputs": [{ - : - }] - }, - ... -] -``` -**Note**: Chat calls with `tool_results` should not be included in the Chat history to avoid duplication of the message text. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**force_single_step:** `typing.Optional[bool]` β€” Forces the chat to be single step. Defaults to `false`. - -
-
- -
-
- -**response_format:** `typing.Optional[ResponseFormat]` - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.chat(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -Generates a text response to a user message. -To learn how to use the Chat API with Streaming and RAG follow our [Text Generation guides](https://docs.cohere.com/docs/chat-api). -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.chat( - message="Can you give me a global market overview of solar panels?", - prompt_truncation="OFF", - temperature=0.3, -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**message:** `str` - -Text input for the model to respond to. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**model:** `typing.Optional[str]` - -Defaults to `command-r-plus`. - -The name of a compatible [Cohere model](https://docs.cohere.com/docs/models) or the ID of a [fine-tuned](https://docs.cohere.com/docs/chat-fine-tuning) model. -Compatible Deployments: Cohere Platform, Private Deployments - - -
-
- -
-
- -**preamble:** `typing.Optional[str]` - -When specified, the default Cohere preamble will be replaced with the provided one. Preambles are a part of the prompt used to adjust the model's overall behavior and conversation style, and use the `SYSTEM` role. - -The `SYSTEM` role is also used for the contents of the optional `chat_history=` parameter. When used with the `chat_history=` parameter it adds content throughout a conversation. Conversely, when used with the `preamble=` parameter it adds content at the start of the conversation only. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**chat_history:** `typing.Optional[typing.Sequence[Message]]` - -A list of previous messages between the user and the model, giving the model conversational context for responding to the user's `message`. - -Each item 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. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**conversation_id:** `typing.Optional[str]` - -An alternative to `chat_history`. - -Providing a `conversation_id` creates or resumes a persisted conversation with the specified ID. The ID can be any non empty string. -Compatible Deployments: Cohere Platform - - -
-
- -
-
- -**prompt_truncation:** `typing.Optional[ChatRequestPromptTruncation]` - -Defaults to `AUTO` when `connectors` are specified and `OFF` in all other cases. - -Dictates how the prompt will be constructed. - -With `prompt_truncation` set to "AUTO", some elements from `chat_history` and `documents` will be dropped in an attempt to construct a prompt that fits within the model's context length limit. During this process the order of the documents and chat history will be changed and ranked by relevance. - -With `prompt_truncation` set to "AUTO_PRESERVE_ORDER", some elements from `chat_history` and `documents` will be dropped in an attempt to construct a prompt that fits within the model's context length limit. During this process the order of the documents and chat history will be preserved as they are inputted into the API. - -With `prompt_truncation` set to "OFF", no elements will be dropped. If the sum of the inputs exceeds the model's context length limit, a `TooManyTokens` error will be returned. -Compatible Deployments: Cohere Platform Only AUTO_PRESERVE_ORDER: Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**connectors:** `typing.Optional[typing.Sequence[ChatConnector]]` - -Accepts `{"id": "web-search"}`, and/or the `"id"` for a custom [connector](https://docs.cohere.com/docs/connectors), if you've [created](https://docs.cohere.com/docs/creating-and-deploying-a-connector) one. - -When specified, the model's reply will be enriched with information found by querying each of the connectors (RAG). -Compatible Deployments: Cohere Platform - - -
-
- -
-
- -**search_queries_only:** `typing.Optional[bool]` - -Defaults to `false`. - -When `true`, the response will only contain a list of generated search queries, but no search will take place, and no reply from the model to the user's `message` will be generated. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**documents:** `typing.Optional[typing.Sequence[ChatDocument]]` - -A list of relevant documents that the model can cite to generate a more accurate reply. Each document is a string-string dictionary. - -Example: -`[ - { "title": "Tall penguins", "text": "Emperor penguins are the tallest." }, - { "title": "Penguin habitats", "text": "Emperor penguins only live in Antarctica." }, -]` - -Keys and values from each document will be serialized to a string and passed to the model. The resulting generation will include citations that reference some of these documents. - -Some suggested keys are "text", "author", and "date". For better generation quality, it is recommended to keep the total word count of the strings in the dictionary to under 300 words. - -An `id` field (string) can be optionally supplied to identify the document in the citations. This field will not be passed to the model. - -An `_excludes` field (array of strings) can be optionally supplied to omit some key-value pairs from being shown to the model. The omitted fields will still show up in the citation object. The "_excludes" field will not be passed to the model. - -See ['Document Mode'](https://docs.cohere.com/docs/retrieval-augmented-generation-rag#document-mode) in the guide for more information. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**citation_quality:** `typing.Optional[ChatRequestCitationQuality]` - -Defaults to `"accurate"`. - -Dictates the approach taken to generating citations as part of the RAG flow by allowing the user to specify whether they want `"accurate"` results, `"fast"` results or no results. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**temperature:** `typing.Optional[float]` - -Defaults to `0.3`. - -A non-negative float that tunes the degree of randomness in generation. Lower temperatures mean less random generations, and higher temperatures mean more random generations. - -Randomness can be further maximized by increasing the value of the `p` parameter. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**max_tokens:** `typing.Optional[int]` - -The maximum number of tokens the model will generate as part of the response. Note: Setting a low value may result in incomplete generations. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**max_input_tokens:** `typing.Optional[int]` - -The maximum number of input tokens to send to the model. If not specified, `max_input_tokens` is the model's context length limit minus a small buffer. - -Input will be truncated according to the `prompt_truncation` parameter. -Compatible Deployments: Cohere Platform - - -
-
- -
-
- -**k:** `typing.Optional[int]` - -Ensures only the top `k` most likely tokens are considered for generation at each step. -Defaults to `0`, min value of `0`, max value of `500`. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**p:** `typing.Optional[float]` - -Ensures that only the most likely tokens, with total probability mass of `p`, are considered for generation at each step. If both `k` and `p` are enabled, `p` acts after `k`. -Defaults to `0.75`. min value of `0.01`, max value of `0.99`. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**seed:** `typing.Optional[int]` - -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, -determinism cannot be totally guaranteed. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**stop_sequences:** `typing.Optional[typing.Sequence[str]]` - -A list of up to 5 strings that the model will use to stop generation. If the model generates a string that matches any of the strings in the list, it will stop generating tokens and return the generated text up to that point not including the stop sequence. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**frequency_penalty:** `typing.Optional[float]` - -Defaults to `0.0`, min value of `0.0`, max value of `1.0`. - -Used to reduce repetitiveness of generated tokens. The higher the value, the stronger a penalty is applied to previously present tokens, proportional to how many times they have already appeared in the prompt or prior generation. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**presence_penalty:** `typing.Optional[float]` - -Defaults to `0.0`, min value of `0.0`, max value of `1.0`. - -Used to reduce repetitiveness of generated tokens. Similar to `frequency_penalty`, except that this penalty is applied equally to all tokens that have already appeared, regardless of their exact frequencies. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**raw_prompting:** `typing.Optional[bool]` - -When enabled, the user's prompt will be sent to the model without -any pre-processing. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**return_prompt:** `typing.Optional[bool]` β€” The prompt is returned in the `prompt` response field when this is enabled. - -
-
- -
-
- -**tools:** `typing.Optional[typing.Sequence[Tool]]` - -A list of available tools (functions) that the model may suggest invoking before producing a text response. - -When `tools` is passed (without `tool_results`), the `text` field in the response will be `""` and the `tool_calls` field in the response will be populated with a list of tool calls that need to be made. If no calls need to be made, the `tool_calls` array will be empty. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**tool_results:** `typing.Optional[typing.Sequence[ToolResult]]` - -A list of results from invoking tools recommended by the model in the previous chat turn. Results are used to produce a text response and will be referenced in citations. When using `tool_results`, `tools` must be passed as well. -Each tool_result contains information about how it was invoked, as well as a list of outputs in the form of dictionaries. - -**Note**: `outputs` must be a list of objects. If your tool returns a single object (eg `{"status": 200}`), make sure to wrap it in a list. -``` -tool_results = [ - { - "call": { - "name": , - "parameters": { - : - } - }, - "outputs": [{ - : - }] - }, - ... -] -``` -**Note**: Chat calls with `tool_results` should not be included in the Chat history to avoid duplication of the message text. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**force_single_step:** `typing.Optional[bool]` β€” Forces the chat to be single step. Defaults to `false`. - -
-
- -
-
- -**response_format:** `typing.Optional[ResponseFormat]` - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.generate_stream(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -> 🚧 Warning -> -> This API is marked as "Legacy" and is no longer maintained. Follow the [migration guide](/docs/migrating-from-cogenerate-to-cochat) to start using the Chat API. - -Generates realistic text conditioned on a given input. -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -response = client.generate_stream( - prompt="string", - model="string", - num_generations=1, - max_tokens=1, - truncate="NONE", - temperature=1.1, - seed=1, - preset="string", - end_sequences=["string"], - stop_sequences=["string"], - k=1, - p=1.1, - frequency_penalty=1.1, - presence_penalty=1.1, - return_likelihoods="GENERATION", - raw_prompting=True, -) -for chunk in response: - yield chunk - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**prompt:** `str` - -The input text that serves as the starting point for generating the response. -Note: The prompt will be pre-processed and modified before reaching the model. - - -
-
- -
-
- -**model:** `typing.Optional[str]` - -The identifier of the model to generate with. Currently available models are `command` (default), `command-nightly` (experimental), `command-light`, and `command-light-nightly` (experimental). -Smaller, "light" models are faster, while larger models will perform better. [Custom models](/docs/training-custom-models) can also be supplied with their full ID. - -
-
- -
-
- -**num_generations:** `typing.Optional[int]` β€” The maximum number of generations that will be returned. Defaults to `1`, min value of `1`, max value of `5`. - - -
-
- -
-
- -**max_tokens:** `typing.Optional[int]` - -The maximum number of tokens the model will generate as part of the response. Note: Setting a low value may result in incomplete generations. - -This parameter is off by default, and if it's not specified, the model will continue generating until it emits an EOS completion token. See [BPE Tokens](/bpe-tokens-wiki) for more details. - -Can only be set to `0` if `return_likelihoods` is set to `ALL` to get the likelihood of the prompt. - - -
-
- -
-
- -**truncate:** `typing.Optional[GenerateStreamRequestTruncate]` - -One of `NONE|START|END` to specify how the API will handle inputs longer than the maximum token length. - -Passing `START` will discard the start of the input. `END` will discard the end of the input. In both cases, input is discarded until the remaining input is exactly the maximum input token length for the model. - -If `NONE` is selected, when the input exceeds the maximum input token length an error will be returned. - -
-
- -
-
- -**temperature:** `typing.Optional[float]` - -A non-negative float that tunes the degree of randomness in generation. Lower temperatures mean less random generations. See [Temperature](/temperature-wiki) for more details. -Defaults to `0.75`, min value of `0.0`, max value of `5.0`. - - -
-
- -
-
- -**seed:** `typing.Optional[int]` - -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, -determinism cannot be totally guaranteed. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**preset:** `typing.Optional[str]` - -Identifier of a custom preset. A preset is a combination of parameters, such as prompt, temperature etc. You can create presets in the [playground](https://dashboard.cohere.com/playground/generate). -When a preset is specified, the `prompt` parameter becomes optional, and any included parameters will override the preset's parameters. - - -
-
- -
-
- -**end_sequences:** `typing.Optional[typing.Sequence[str]]` β€” The generated text will be cut at the beginning of the earliest occurrence of an end sequence. The sequence will be excluded from the text. - -
-
- -
-
- -**stop_sequences:** `typing.Optional[typing.Sequence[str]]` β€” The generated text will be cut at the end of the earliest occurrence of a stop sequence. The sequence will be included the text. - -
-
- -
-
- -**k:** `typing.Optional[int]` - -Ensures only the top `k` most likely tokens are considered for generation at each step. -Defaults to `0`, min value of `0`, max value of `500`. - - -
-
- -
-
- -**p:** `typing.Optional[float]` - -Ensures that only the most likely tokens, with total probability mass of `p`, are considered for generation at each step. If both `k` and `p` are enabled, `p` acts after `k`. -Defaults to `0.75`. min value of `0.01`, max value of `0.99`. - - -
-
- -
-
- -**frequency_penalty:** `typing.Optional[float]` - -Used to reduce repetitiveness of generated tokens. The higher the value, the stronger a penalty is applied to previously present tokens, proportional to how many times they have already appeared in the prompt or prior generation. - -Using `frequency_penalty` in combination with `presence_penalty` is not supported on newer models. - - -
-
- -
-
- -**presence_penalty:** `typing.Optional[float]` - -Defaults to `0.0`, min value of `0.0`, max value of `1.0`. - -Can be used to reduce repetitiveness of generated tokens. Similar to `frequency_penalty`, except that this penalty is applied equally to all tokens that have already appeared, regardless of their exact frequencies. - -Using `frequency_penalty` in combination with `presence_penalty` is not supported on newer models. - - -
-
- -
-
- -**return_likelihoods:** `typing.Optional[GenerateStreamRequestReturnLikelihoods]` - -One of `GENERATION|ALL|NONE` to specify how and if the token likelihoods are returned with the response. Defaults to `NONE`. - -If `GENERATION` is selected, the token likelihoods will only be provided for generated text. - -If `ALL` is selected, the token likelihoods will be provided both for the prompt and the generated text. - -
-
- -
-
- -**raw_prompting:** `typing.Optional[bool]` β€” When enabled, the user's prompt will be sent to the model without any pre-processing. - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.generate(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -> 🚧 Warning -> -> This API is marked as "Legacy" and is no longer maintained. Follow the [migration guide](/docs/migrating-from-cogenerate-to-cochat) to start using the Chat API. - -Generates realistic text conditioned on a given input. -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.generate( - prompt="Please explain to me how LLMs work", -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**prompt:** `str` - -The input text that serves as the starting point for generating the response. -Note: The prompt will be pre-processed and modified before reaching the model. - - -
-
- -
-
- -**model:** `typing.Optional[str]` - -The identifier of the model to generate with. Currently available models are `command` (default), `command-nightly` (experimental), `command-light`, and `command-light-nightly` (experimental). -Smaller, "light" models are faster, while larger models will perform better. [Custom models](/docs/training-custom-models) can also be supplied with their full ID. - -
-
- -
-
- -**num_generations:** `typing.Optional[int]` β€” The maximum number of generations that will be returned. Defaults to `1`, min value of `1`, max value of `5`. - - -
-
- -
-
- -**max_tokens:** `typing.Optional[int]` - -The maximum number of tokens the model will generate as part of the response. Note: Setting a low value may result in incomplete generations. - -This parameter is off by default, and if it's not specified, the model will continue generating until it emits an EOS completion token. See [BPE Tokens](/bpe-tokens-wiki) for more details. - -Can only be set to `0` if `return_likelihoods` is set to `ALL` to get the likelihood of the prompt. - - -
-
- -
-
- -**truncate:** `typing.Optional[GenerateRequestTruncate]` - -One of `NONE|START|END` to specify how the API will handle inputs longer than the maximum token length. - -Passing `START` will discard the start of the input. `END` will discard the end of the input. In both cases, input is discarded until the remaining input is exactly the maximum input token length for the model. - -If `NONE` is selected, when the input exceeds the maximum input token length an error will be returned. - -
-
- -
-
- -**temperature:** `typing.Optional[float]` - -A non-negative float that tunes the degree of randomness in generation. Lower temperatures mean less random generations. See [Temperature](/temperature-wiki) for more details. -Defaults to `0.75`, min value of `0.0`, max value of `5.0`. - - -
-
- -
-
- -**seed:** `typing.Optional[int]` - -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, -determinism cannot be totally guaranteed. -Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments - - -
-
- -
-
- -**preset:** `typing.Optional[str]` - -Identifier of a custom preset. A preset is a combination of parameters, such as prompt, temperature etc. You can create presets in the [playground](https://dashboard.cohere.com/playground/generate). -When a preset is specified, the `prompt` parameter becomes optional, and any included parameters will override the preset's parameters. - - -
-
- -
-
- -**end_sequences:** `typing.Optional[typing.Sequence[str]]` β€” The generated text will be cut at the beginning of the earliest occurrence of an end sequence. The sequence will be excluded from the text. - -
-
- -
-
- -**stop_sequences:** `typing.Optional[typing.Sequence[str]]` β€” The generated text will be cut at the end of the earliest occurrence of a stop sequence. The sequence will be included the text. - -
-
- -
-
- -**k:** `typing.Optional[int]` - -Ensures only the top `k` most likely tokens are considered for generation at each step. -Defaults to `0`, min value of `0`, max value of `500`. - - -
-
- -
-
- -**p:** `typing.Optional[float]` - -Ensures that only the most likely tokens, with total probability mass of `p`, are considered for generation at each step. If both `k` and `p` are enabled, `p` acts after `k`. -Defaults to `0.75`. min value of `0.01`, max value of `0.99`. - - -
-
- -
-
- -**frequency_penalty:** `typing.Optional[float]` - -Used to reduce repetitiveness of generated tokens. The higher the value, the stronger a penalty is applied to previously present tokens, proportional to how many times they have already appeared in the prompt or prior generation. - -Using `frequency_penalty` in combination with `presence_penalty` is not supported on newer models. - - -
-
- -
-
- -**presence_penalty:** `typing.Optional[float]` - -Defaults to `0.0`, min value of `0.0`, max value of `1.0`. - -Can be used to reduce repetitiveness of generated tokens. Similar to `frequency_penalty`, except that this penalty is applied equally to all tokens that have already appeared, regardless of their exact frequencies. - -Using `frequency_penalty` in combination with `presence_penalty` is not supported on newer models. - - -
-
- -
-
- -**return_likelihoods:** `typing.Optional[GenerateRequestReturnLikelihoods]` - -One of `GENERATION|ALL|NONE` to specify how and if the token likelihoods are returned with the response. Defaults to `NONE`. - -If `GENERATION` is selected, the token likelihoods will only be provided for generated text. - -If `ALL` is selected, the token likelihoods will be provided both for the prompt and the generated text. - -
-
- -
-
- -**raw_prompting:** `typing.Optional[bool]` β€” When enabled, the user's prompt will be sent to the model without any pre-processing. - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.embed(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -This endpoint returns text embeddings. An embedding is a list of floating point numbers that captures semantic information about the text that it represents. - -Embeddings can be used to create text classifiers as well as empower semantic search. To learn more about embeddings, see the embedding page. - -If you want to learn more how to use the embedding model, have a look at the [Semantic Search Guide](/docs/semantic-search). -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.embed( - texts=["string"], - model="string", - input_type="search_document", - embedding_types=["float"], - truncate="NONE", -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**texts:** `typing.Sequence[str]` β€” An array of strings for the model to embed. Maximum number of texts per call is `96`. We recommend reducing the length of each text to be under `512` tokens for optimal quality. - -
-
- -
-
- -**model:** `typing.Optional[str]` - -Defaults to embed-english-v2.0 - -The identifier of the model. Smaller "light" models are faster, while larger models will perform better. [Custom models](/docs/training-custom-models) can also be supplied with their full ID. - -Available models and corresponding embedding dimensions: - -* `embed-english-v3.0` 1024 -* `embed-multilingual-v3.0` 1024 -* `embed-english-light-v3.0` 384 -* `embed-multilingual-light-v3.0` 384 - -* `embed-english-v2.0` 4096 -* `embed-english-light-v2.0` 1024 -* `embed-multilingual-v2.0` 768 - -
-
- -
-
- -**input_type:** `typing.Optional[EmbedInputType]` - -
-
- -
-
- -**embedding_types:** `typing.Optional[typing.Sequence[EmbeddingType]]` - -Specifies the types of embeddings you want to get back. Not required and default is None, which returns the Embed Floats response type. Can be one or more of the following types. - -* `"float"`: Use this when you want to get back the default float embeddings. Valid for all models. -* `"int8"`: Use this when you want to get back signed int8 embeddings. Valid for only v3 models. -* `"uint8"`: Use this when you want to get back unsigned int8 embeddings. Valid for only v3 models. -* `"binary"`: Use this when you want to get back signed binary embeddings. Valid for only v3 models. -* `"ubinary"`: Use this when you want to get back unsigned binary embeddings. Valid for only v3 models. - -
-
- -
-
- -**truncate:** `typing.Optional[EmbedRequestTruncate]` - -One of `NONE|START|END` to specify how the API will handle inputs longer than the maximum token length. - -Passing `START` will discard the start of the input. `END` will discard the end of the input. In both cases, input is discarded until the remaining input is exactly the maximum input token length for the model. - -If `NONE` is selected, when the input exceeds the maximum input token length an error will be returned. - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.rerank(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -This endpoint takes in a query and a list of texts and produces an ordered array with each text assigned a relevance score. -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.rerank( - model="rerank-english-v3.0", - query="What is the capital of the United States?", - documents=[ - "Carson City is the capital city of the American state of Nevada.", - "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.", - "Washington, D.C. (also known as simply Washington or D.C., and officially as the District of Columbia) is the capital of the United States. It is a federal district.", - "Capital punishment (the death penalty) has existed in the United States since beforethe United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states.", - ], -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**query:** `str` β€” The search query - -
-
- -
-
- -**documents:** `typing.Sequence[RerankRequestDocumentsItem]` - -A list of document objects or strings to rerank. -If a document is provided the text fields is required and all other fields will be preserved in the response. - -The total max chunks (length of documents * max_chunks_per_doc) must be less than 10000. - -We recommend a maximum of 1,000 documents for optimal endpoint performance. - -
-
- -
-
- -**model:** `typing.Optional[str]` β€” The identifier of the model to use, one of : `rerank-english-v3.0`, `rerank-multilingual-v3.0`, `rerank-english-v2.0`, `rerank-multilingual-v2.0` - -
-
- -
-
- -**top_n:** `typing.Optional[int]` β€” The number of most relevant documents or indices to return, defaults to the length of the documents - -
-
- -
-
- -**rank_fields:** `typing.Optional[typing.Sequence[str]]` β€” If a JSON object is provided, you can specify which keys you would like to have considered for reranking. The model will rerank based on order of the fields passed in (i.e. rank_fields=['title','author','text'] will rerank using the values in title, author, text sequentially. If the length of title, author, and text exceeds the context length of the model, the chunking will not re-consider earlier fields). If not provided, the model will use the default text field for ranking. - -
-
- -
-
- -**return_documents:** `typing.Optional[bool]` - -- If false, returns results without the doc text - the api will return a list of {index, relevance score} where index is inferred from the list passed into the request. -- If true, returns results with the doc text passed in - the api will return an ordered list of {index, text, relevance score} where index + text refers to the list passed into the request. - -
-
- -
-
- -**max_chunks_per_doc:** `typing.Optional[int]` β€” The maximum number of chunks to produce internally from a document - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.classify(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -This endpoint makes a prediction about which label fits the specified text inputs best. To make a prediction, Classify uses the provided `examples` of text + label pairs as a reference. -Note: [Fine-tuned models](https://docs.cohere.com/docs/classify-fine-tuning) trained on classification examples don't require the `examples` parameter to be passed in explicitly. -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere import ClassifyExample -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.classify( - inputs=["Confirm your email address", "hey i need u to send some $"], - examples=[ - ClassifyExample( - text="Dermatologists don't like her!", - label="Spam", - ), - ClassifyExample( - text="Hello, open to this?", - label="Spam", - ), - ClassifyExample( - text="I need help please wire me $1000 right now", - label="Spam", - ), - ClassifyExample( - text="Nice to know you ;)", - label="Spam", - ), - ClassifyExample( - text="Please help me?", - label="Spam", - ), - ClassifyExample( - text="Your parcel will be delivered today", - label="Not spam", - ), - ClassifyExample( - text="Review changes to our Terms and Conditions", - label="Not spam", - ), - ClassifyExample( - text="Weekly sync notes", - label="Not spam", - ), - ClassifyExample( - text="Re: Follow up from today’s meeting", - label="Not spam", - ), - ClassifyExample( - text="Pre-read for tomorrow", - label="Not spam", - ), - ], -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**inputs:** `typing.Sequence[str]` - -A list of up to 96 texts to be classified. Each one must be a non-empty string. -There is, however, no consistent, universal limit to the length a particular input can be. We perform classification on the first `x` tokens of each input, and `x` varies depending on which underlying model is powering classification. The maximum token length for each model is listed in the "max tokens" column [here](https://docs.cohere.com/docs/models). -Note: by default the `truncate` parameter is set to `END`, so tokens exceeding the limit will be automatically dropped. This behavior can be disabled by setting `truncate` to `NONE`, which will result in validation errors for longer texts. - -
-
- -
-
- -**examples:** `typing.Optional[typing.Sequence[ClassifyExample]]` - -An array of examples to provide context to the model. Each example is a text string and its associated label/class. Each unique label requires at least 2 examples associated with it; the maximum number of examples is 2500, and each example has a maximum length of 512 tokens. The values should be structured as `{text: "...",label: "..."}`. -Note: [Fine-tuned Models](https://docs.cohere.com/docs/classify-fine-tuning) trained on classification examples don't require the `examples` parameter to be passed in explicitly. - -
-
- -
-
- -**model:** `typing.Optional[str]` β€” The identifier of the model. Currently available models are `embed-multilingual-v2.0`, `embed-english-light-v2.0`, and `embed-english-v2.0` (default). Smaller "light" models are faster, while larger models will perform better. [Fine-tuned models](https://docs.cohere.com/docs/fine-tuning) can also be supplied with their full ID. - -
-
- -
-
- -**preset:** `typing.Optional[str]` β€” The ID of a custom playground preset. You can create presets in the [playground](https://dashboard.cohere.com/playground/classify?model=large). If you use a preset, all other parameters become optional, and any included parameters will override the preset's parameters. - -
-
- -
-
- -**truncate:** `typing.Optional[ClassifyRequestTruncate]` - -One of `NONE|START|END` to specify how the API will handle inputs longer than the maximum token length. -Passing `START` will discard the start of the input. `END` will discard the end of the input. In both cases, input is discarded until the remaining input is exactly the maximum input token length for the model. -If `NONE` is selected, when the input exceeds the maximum input token length an error will be returned. - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.summarize(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -> 🚧 Warning -> -> This API is marked as "Legacy" and is no longer maintained. Follow the [migration guide](/docs/migrating-from-cogenerate-to-cochat) to start using the Chat API. - -Generates a summary in English for a given text. -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.summarize( - text='Ice cream is a sweetened frozen food typically eaten as a snack or dessert. It may be made from milk or cream and is flavoured with a sweetener, either sugar or an alternative, and a spice, such as cocoa or vanilla, or with fruit such as strawberries or peaches. It can also be made by whisking a flavored cream base and liquid nitrogen together. Food coloring is sometimes added, in addition to stabilizers. The mixture is cooled below the freezing point of water and stirred to incorporate air spaces and to prevent detectable ice crystals from forming. The result is a smooth, semi-solid foam that is solid at very low temperatures (below 2 Β°C or 35 Β°F). It becomes more malleable as its temperature increases.\n\nThe meaning of the name "ice cream" varies from one country to another. In some countries, such as the United States, "ice cream" applies only to a specific variety, and most governments regulate the commercial use of the various terms according to the relative quantities of the main ingredients, notably the amount of cream. Products that do not meet the criteria to be called ice cream are sometimes labelled "frozen dairy dessert" instead. In other countries, such as Italy and Argentina, one word is used fo\r all variants. Analogues made from dairy alternatives, such as goat\'s or sheep\'s milk, or milk substitutes (e.g., soy, cashew, coconut, almond milk or tofu), are available for those who are lactose intolerant, allergic to dairy protein or vegan.', -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**text:** `str` β€” The text to generate a summary for. Can be up to 100,000 characters long. Currently the only supported language is English. - -
-
- -
-
- -**length:** `typing.Optional[SummarizeRequestLength]` β€” One of `short`, `medium`, `long`, or `auto` defaults to `auto`. Indicates the approximate length of the summary. If `auto` is selected, the best option will be picked based on the input text. - -
-
- -
-
- -**format:** `typing.Optional[SummarizeRequestFormat]` β€” One of `paragraph`, `bullets`, or `auto`, defaults to `auto`. Indicates the style in which the summary will be delivered - in a free form paragraph or in bullet points. If `auto` is selected, the best option will be picked based on the input text. - -
-
- -
-
- -**model:** `typing.Optional[str]` β€” The identifier of the model to generate the summary with. Currently available models are `command` (default), `command-nightly` (experimental), `command-light`, and `command-light-nightly` (experimental). Smaller, "light" models are faster, while larger models will perform better. - -
-
- -
-
- -**extractiveness:** `typing.Optional[SummarizeRequestExtractiveness]` β€” One of `low`, `medium`, `high`, or `auto`, defaults to `auto`. Controls how close to the original text the summary is. `high` extractiveness summaries will lean towards reusing sentences verbatim, while `low` extractiveness summaries will tend to paraphrase more. If `auto` is selected, the best option will be picked based on the input text. - -
-
- -
-
- -**temperature:** `typing.Optional[float]` β€” Ranges from 0 to 5. Controls the randomness of the output. Lower values tend to generate more β€œpredictable” output, while higher values tend to generate more β€œcreative” output. The sweet spot is typically between 0 and 1. - -
-
- -
-
- -**additional_command:** `typing.Optional[str]` β€” A free-form instruction for modifying how the summaries get generated. Should complete the sentence "Generate a summary _". Eg. "focusing on the next steps" or "written by Yoda" - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.tokenize(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -This endpoint splits input text into smaller units called tokens using byte-pair encoding (BPE). To learn more about tokenization and byte pair encoding, see the tokens page. -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.tokenize( - text="tokenize me! :D", - model="command", -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**text:** `str` β€” The string to be tokenized, the minimum text length is 1 character, and the maximum text length is 65536 characters. - -
-
- -
-
- -**model:** `str` β€” An optional parameter to provide the model name. This will ensure that the tokenization uses the tokenizer used by that model. - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.detokenize(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -This endpoint takes tokens using byte-pair encoding and returns their text representation. To learn more about tokenization and byte pair encoding, see the tokens page. -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.detokenize( - tokens=[10104, 12221, 1315, 34, 1420, 69], - model="command", -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**tokens:** `typing.Sequence[int]` β€” The list of tokens to be detokenized. - -
-
- -
-
- -**model:** `str` β€” An optional parameter to provide the model name. This will ensure that the detokenization is done by the tokenizer used by that model. - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.check_api_key() -
-
- -#### πŸ“ Description - -
-
- -
-
- -Checks that the api key in the Authorization header is valid and active -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.check_api_key() - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -## EmbedJobs -
client.embed_jobs.list() -
-
- -#### πŸ“ Description - -
-
- -
-
- -The list embed job endpoint allows users to view all embed jobs history for that specific user. -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.embed_jobs.list() - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.embed_jobs.create(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -This API launches an async Embed job for a [Dataset](https://docs.cohere.com/docs/datasets) of type `embed-input`. The result of a completed embed job is new Dataset of type `embed-output`, which contains the original text entries and the corresponding embeddings. -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.embed_jobs.create( - model="model", - dataset_id="dataset_id", - input_type="search_document", -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**model:** `str` - -ID of the embedding model. - -Available models and corresponding embedding dimensions: - -- `embed-english-v3.0` : 1024 -- `embed-multilingual-v3.0` : 1024 -- `embed-english-light-v3.0` : 384 -- `embed-multilingual-light-v3.0` : 384 - - -
-
- -
-
- -**dataset_id:** `str` β€” ID of a [Dataset](https://docs.cohere.com/docs/datasets). The Dataset must be of type `embed-input` and must have a validation status `Validated` - -
-
- -
-
- -**input_type:** `EmbedInputType` - -
-
- -
-
- -**name:** `typing.Optional[str]` β€” The name of the embed job. - -
-
- -
-
- -**embedding_types:** `typing.Optional[typing.Sequence[EmbeddingType]]` - -Specifies the types of embeddings you want to get back. Not required and default is None, which returns the Embed Floats response type. Can be one or more of the following types. - -* `"float"`: Use this when you want to get back the default float embeddings. Valid for all models. -* `"int8"`: Use this when you want to get back signed int8 embeddings. Valid for only v3 models. -* `"uint8"`: Use this when you want to get back unsigned int8 embeddings. Valid for only v3 models. -* `"binary"`: Use this when you want to get back signed binary embeddings. Valid for only v3 models. -* `"ubinary"`: Use this when you want to get back unsigned binary embeddings. Valid for only v3 models. - -
-
- -
-
- -**truncate:** `typing.Optional[CreateEmbedJobRequestTruncate]` - -One of `START|END` to specify how the API will handle inputs longer than the maximum token length. - -Passing `START` will discard the start of the input. `END` will discard the end of the input. In both cases, input is discarded until the remaining input is exactly the maximum input token length for the model. - - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.embed_jobs.get(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -This API retrieves the details about an embed job started by the same user. -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.embed_jobs.get( - id="id", -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**id:** `str` β€” The ID of the embed job to retrieve. - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.embed_jobs.cancel(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -This API allows users to cancel an active embed job. Once invoked, the embedding process will be terminated, and users will be charged for the embeddings processed up to the cancellation point. It's important to note that partial results will not be available to users after cancellation. -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.embed_jobs.cancel( - id="id", -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**id:** `str` β€” The ID of the embed job to cancel. - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -## Datasets -
client.datasets.list(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -List datasets that have been created. -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.datasets.list() - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**dataset_type:** `typing.Optional[str]` β€” optional filter by dataset type - -
-
- -
-
- -**before:** `typing.Optional[dt.datetime]` β€” optional filter before a date - -
-
- -
-
- -**after:** `typing.Optional[dt.datetime]` β€” optional filter after a date - -
-
- -
-
- -**limit:** `typing.Optional[float]` β€” optional limit to number of results - -
-
- -
-
- -**offset:** `typing.Optional[float]` β€” optional offset to start of results - -
-
- -
-
- -**validation_status:** `typing.Optional[DatasetValidationStatus]` β€” optional filter by validation status - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.datasets.create(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -Create a dataset by uploading a file. See ['Dataset Creation'](https://docs.cohere.com/docs/datasets#dataset-creation) for more information. -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.datasets.create( - name="name", - type="embed-input", -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**name:** `str` β€” The name of the uploaded dataset. - -
-
- -
-
- -**type:** `DatasetType` β€” The dataset type, which is used to validate the data. Valid types are `embed-input`, `reranker-finetune-input`, `single-label-classification-finetune-input`, `chat-finetune-input`, and `multi-label-classification-finetune-input`. - -
-
- -
-
- -**data:** `from __future__ import annotations - -core.File` β€” See core.File for more documentation - -
-
- -
-
- -**keep_original_file:** `typing.Optional[bool]` β€” Indicates if the original file should be stored. - -
-
- -
-
- -**skip_malformed_input:** `typing.Optional[bool]` β€” Indicates whether rows with malformed input should be dropped (instead of failing the validation check). Dropped rows will be returned in the warnings field. - -
-
- -
-
- -**keep_fields:** `typing.Optional[typing.Union[str, typing.Sequence[str]]]` β€” List of names of fields that will be persisted in the Dataset. By default the Dataset will retain only the required fields indicated in the [schema for the corresponding Dataset type](https://docs.cohere.com/docs/datasets#dataset-types). For example, datasets of type `embed-input` will drop all fields other than the required `text` field. If any of the fields in `keep_fields` are missing from the uploaded file, Dataset validation will fail. - -
-
- -
-
- -**optional_fields:** `typing.Optional[typing.Union[str, typing.Sequence[str]]]` β€” List of names of fields that will be persisted in the Dataset. By default the Dataset will retain only the required fields indicated in the [schema for the corresponding Dataset type](https://docs.cohere.com/docs/datasets#dataset-types). For example, Datasets of type `embed-input` will drop all fields other than the required `text` field. If any of the fields in `optional_fields` are missing from the uploaded file, Dataset validation will pass. - -
-
- -
-
- -**text_separator:** `typing.Optional[str]` β€” Raw .txt uploads will be split into entries using the text_separator value. - -
-
- -
-
- -**csv_delimiter:** `typing.Optional[str]` β€” The delimiter used for .csv uploads. - -
-
- -
-
- -**dry_run:** `typing.Optional[bool]` β€” flag to enable dry_run mode - -
-
- -
-
- -**eval_data:** `from __future__ import annotations - -typing.Optional[core.File]` β€” See core.File for more documentation - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.datasets.get_usage() -
-
- -#### πŸ“ Description - -
-
- -
-
- -View the dataset storage usage for your Organization. Each Organization can have up to 10GB of storage across all their users. -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.datasets.get_usage() - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.datasets.get(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -Retrieve a dataset by ID. See ['Datasets'](https://docs.cohere.com/docs/datasets) for more information. -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.datasets.get( - id="id", -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**id:** `str` - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.datasets.delete(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -Delete a dataset by ID. Datasets are automatically deleted after 30 days, but they can also be deleted manually. -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.datasets.delete( - id="id", -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**id:** `str` - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -## Connectors -
client.connectors.list(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -Returns a list of connectors ordered by descending creation date (newer first). See ['Managing your Connector'](https://docs.cohere.com/docs/managing-your-connector) for more information. -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.connectors.list() - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**limit:** `typing.Optional[float]` β€” Maximum number of connectors to return [0, 100]. - -
-
- -
-
- -**offset:** `typing.Optional[float]` β€” Number of connectors to skip before returning results [0, inf]. - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.connectors.create(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -Creates a new connector. The connector is tested during registration and will cancel registration when the test is unsuccessful. See ['Creating and Deploying a Connector'](https://docs.cohere.com/docs/creating-and-deploying-a-connector) for more information. -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.connectors.create( - name="name", - url="url", -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**name:** `str` β€” A human-readable name for the connector. - -
-
- -
-
- -**url:** `str` β€” The URL of the connector that will be used to search for documents. - -
-
- -
-
- -**description:** `typing.Optional[str]` β€” A description of the connector. - -
-
- -
-
- -**excludes:** `typing.Optional[typing.Sequence[str]]` β€” A list of fields to exclude from the prompt (fields remain in the document). - -
-
- -
-
- -**oauth:** `typing.Optional[CreateConnectorOAuth]` β€” The OAuth 2.0 configuration for the connector. Cannot be specified if service_auth is specified. - -
-
- -
-
- -**active:** `typing.Optional[bool]` β€” Whether the connector is active or not. - -
-
- -
-
- -**continue_on_failure:** `typing.Optional[bool]` β€” Whether a chat request should continue or not if the request to this connector fails. - -
-
- -
-
- -**service_auth:** `typing.Optional[CreateConnectorServiceAuth]` β€” The service to service authentication configuration for the connector. Cannot be specified if oauth is specified. - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.connectors.get(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -Retrieve a connector by ID. See ['Connectors'](https://docs.cohere.com/docs/connectors) for more information. -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.connectors.get( - id="id", -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**id:** `str` β€” The ID of the connector to retrieve. - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.connectors.delete(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -Delete a connector by ID. See ['Connectors'](https://docs.cohere.com/docs/connectors) for more information. -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.connectors.delete( - id="id", -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**id:** `str` β€” The ID of the connector to delete. - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.connectors.update(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -Update a connector by ID. Omitted fields will not be updated. See ['Managing your Connector'](https://docs.cohere.com/docs/managing-your-connector) for more information. -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.connectors.update( - id="id", -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**id:** `str` β€” The ID of the connector to update. - -
-
- -
-
- -**name:** `typing.Optional[str]` β€” A human-readable name for the connector. - -
-
- -
-
- -**url:** `typing.Optional[str]` β€” The URL of the connector that will be used to search for documents. - -
-
- -
-
- -**excludes:** `typing.Optional[typing.Sequence[str]]` β€” A list of fields to exclude from the prompt (fields remain in the document). - -
-
- -
-
- -**oauth:** `typing.Optional[CreateConnectorOAuth]` β€” The OAuth 2.0 configuration for the connector. Cannot be specified if service_auth is specified. - -
-
- -
-
- -**active:** `typing.Optional[bool]` - -
-
- -
-
- -**continue_on_failure:** `typing.Optional[bool]` - -
-
- -
-
- -**service_auth:** `typing.Optional[CreateConnectorServiceAuth]` β€” The service to service authentication configuration for the connector. Cannot be specified if oauth is specified. - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.connectors.o_auth_authorize(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -Authorize the connector with the given ID for the connector oauth app. See ['Connector Authentication'](https://docs.cohere.com/docs/connector-authentication) for more information. -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.connectors.o_auth_authorize( - id="id", -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**id:** `str` β€” The ID of the connector to authorize. - -
-
- -
-
- -**after_token_redirect:** `typing.Optional[str]` β€” The URL to redirect to after the connector has been authorized. - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -## Models -
client.models.get(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -Returns the details of a model, provided its name. -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.models.get( - model="command-r", -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**model:** `str` - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.models.list(...) -
-
- -#### πŸ“ Description - -
-
- -
-
- -Returns a list of models available for use. The list contains models from Cohere as well as your fine-tuned models. -
-
-
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.models.list() - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**page_size:** `typing.Optional[float]` - -Maximum number of models to include in a page -Defaults to `20`, min value of `1`, max value of `1000`. - -
-
- -
-
- -**page_token:** `typing.Optional[str]` β€” Page token provided in the `next_page_token` field of a previous response. - -
-
- -
-
- -**endpoint:** `typing.Optional[CompatibleEndpoint]` β€” When provided, filters the list of models to only those that are compatible with the specified endpoint. - -
-
- -
-
- -**default_only:** `typing.Optional[bool]` β€” When provided, filters the list of models to only the default model to the endpoint. This parameter is only valid when `endpoint` is provided. - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -## /finetuning -
client.finetuning.list_finetuned_models(...) -
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.finetuning.list_finetuned_models() - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**page_size:** `typing.Optional[int]` β€” Maximum number of results to be returned by the server. If 0, defaults to 50. - -
-
- -
-
- -**page_token:** `typing.Optional[str]` β€” Request a specific page of the list results. - -
-
- -
-
- -**order_by:** `typing.Optional[str]` - -Comma separated list of fields. For example: "created_at,name". The default -sorting order is ascending. To specify descending order for a field, append -" desc" to the field name. For example: "created_at desc,name". - -Supported sorting fields: - -- created_at (default) - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.finetuning.create_finetuned_model(...) -
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client -from cohere.finetuning import BaseModel, FinetunedModel, Settings - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.finetuning.create_finetuned_model( - request=FinetunedModel( - name="api-test", - settings=Settings( - base_model=BaseModel( - base_type="BASE_TYPE_GENERATIVE", - ), - dataset_id="my-dataset-id", - ), - ), -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**request:** `FinetunedModel` - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.finetuning.get_finetuned_model(...) -
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.finetuning.get_finetuned_model( - id="id", -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**id:** `str` β€” The fine-tuned model ID. - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.finetuning.delete_finetuned_model(...) -
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.finetuning.delete_finetuned_model( - id="id", -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**id:** `str` β€” The fine-tuned model ID. - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.finetuning.update_finetuned_model(...) -
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client -from cohere.finetuning import BaseModel, Settings - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.finetuning.update_finetuned_model( - id="id", - name="name", - settings=Settings( - base_model=BaseModel( - base_type="BASE_TYPE_UNSPECIFIED", - ), - dataset_id="dataset_id", - ), -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**id:** `str` β€” FinetunedModel ID. - -
-
- -
-
- -**name:** `str` β€” FinetunedModel name (e.g. `foobar`). - -
-
- -
-
- -**settings:** `Settings` β€” FinetunedModel settings such as dataset, hyperparameters... - -
-
- -
-
- -**creator_id:** `typing.Optional[str]` β€” User ID of the creator. - -
-
- -
-
- -**organization_id:** `typing.Optional[str]` β€” Organization ID. - -
-
- -
-
- -**status:** `typing.Optional[Status]` β€” Current stage in the life-cycle of the fine-tuned model. - -
-
- -
-
- -**created_at:** `typing.Optional[dt.datetime]` β€” Creation timestamp. - -
-
- -
-
- -**updated_at:** `typing.Optional[dt.datetime]` β€” Latest update timestamp. - -
-
- -
-
- -**completed_at:** `typing.Optional[dt.datetime]` β€” Timestamp for the completed fine-tuning. - -
-
- -
-
- -**last_used:** `typing.Optional[dt.datetime]` β€” Timestamp for the latest request to this fine-tuned model. - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.finetuning.list_events(...) -
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.finetuning.list_events( - finetuned_model_id="finetuned_model_id", -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**finetuned_model_id:** `str` β€” The parent fine-tuned model ID. - -
-
- -
-
- -**page_size:** `typing.Optional[int]` β€” Maximum number of results to be returned by the server. If 0, defaults to 50. - -
-
- -
-
- -**page_token:** `typing.Optional[str]` β€” Request a specific page of the list results. - -
-
- -
-
- -**order_by:** `typing.Optional[str]` - -Comma separated list of fields. For example: "created_at,name". The default -sorting order is ascending. To specify descending order for a field, append -" desc" to the field name. For example: "created_at desc,name". - -Supported sorting fields: - -- created_at (default) - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.finetuning.list_training_step_metrics(...) -
-
- -#### πŸ”Œ Usage - -
-
- -
-
- -```python -from cohere.client import Client - -client = Client( - client_name="YOUR_CLIENT_NAME", - token="YOUR_TOKEN", -) -client.finetuning.list_training_step_metrics( - finetuned_model_id="finetuned_model_id", -) - -``` -
-
-
-
- -#### βš™οΈ Parameters - -
-
- -
-
- -**finetuned_model_id:** `str` β€” The parent fine-tuned model ID. - -
-
- -
-
- -**page_size:** `typing.Optional[int]` β€” Maximum number of results to be returned by the server. If 0, defaults to 50. - -
-
- -
-
- -**page_token:** `typing.Optional[str]` β€” Request a specific page of the list results. - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` β€” Request-specific configuration. - -
-
-
-
- - -
-
-
- diff --git a/src/cohere/base_client.py b/src/cohere/base_client.py index 3e27ca693..346f88414 100644 --- a/src/cohere/base_client.py +++ b/src/cohere/base_client.py @@ -504,61 +504,58 @@ def chat_stream( request_options=request_options, omit=OMIT, ) as _response: + if 200 <= _response.status_code < 300: + for _text in _response.iter_lines(): + if len(_text) == 0: + continue + yield typing.cast(StreamedChatResponse, construct_type(type_=StreamedChatResponse, object_=json.loads(_text))) # type: ignore + return + _response.read() + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - for _text in _response.iter_lines(): - try: - if len(_text) == 0: - continue - yield typing.cast(StreamedChatResponse, construct_type(type_=StreamedChatResponse, object_=json.loads(_text))) # type: ignore - except: - pass - return - _response.read() - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -852,53 +849,53 @@ def chat( request_options=request_options, omit=OMIT, ) + if 200 <= _response.status_code < 300: + return typing.cast(NonStreamedChatResponse, construct_type(type_=NonStreamedChatResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(NonStreamedChatResponse, construct_type(type_=NonStreamedChatResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -1082,61 +1079,58 @@ def generate_stream( request_options=request_options, omit=OMIT, ) as _response: + if 200 <= _response.status_code < 300: + for _text in _response.iter_lines(): + if len(_text) == 0: + continue + yield typing.cast(GenerateStreamedResponse, construct_type(type_=GenerateStreamedResponse, object_=json.loads(_text))) # type: ignore + return + _response.read() + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - for _text in _response.iter_lines(): - try: - if len(_text) == 0: - continue - yield typing.cast(GenerateStreamedResponse, construct_type(type_=GenerateStreamedResponse, object_=json.loads(_text))) # type: ignore - except: - pass - return - _response.read() - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -1303,53 +1297,53 @@ def generate( request_options=request_options, omit=OMIT, ) + if 200 <= _response.status_code < 300: + return typing.cast(Generation, construct_type(type_=Generation, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(Generation, construct_type(type_=Generation, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -1448,53 +1442,53 @@ def embed( request_options=request_options, omit=OMIT, ) + if 200 <= _response.status_code < 300: + return typing.cast(EmbedResponse, construct_type(type_=EmbedResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(EmbedResponse, construct_type(type_=EmbedResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -1586,53 +1580,53 @@ def rerank( request_options=request_options, omit=OMIT, ) + if 200 <= _response.status_code < 300: + return typing.cast(RerankResponse, construct_type(type_=RerankResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(RerankResponse, construct_type(type_=RerankResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -1744,53 +1738,53 @@ def classify( request_options=request_options, omit=OMIT, ) + if 200 <= _response.status_code < 300: + return typing.cast(ClassifyResponse, construct_type(type_=ClassifyResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(ClassifyResponse, construct_type(type_=ClassifyResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -1873,53 +1867,53 @@ def summarize( request_options=request_options, omit=OMIT, ) + if 200 <= _response.status_code < 300: + return typing.cast(SummarizeResponse, construct_type(type_=SummarizeResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(SummarizeResponse, construct_type(type_=SummarizeResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -1963,53 +1957,53 @@ def tokenize( _response = self._client_wrapper.httpx_client.request( "tokenize", method="POST", json={"text": text, "model": model}, request_options=request_options, omit=OMIT ) + if 200 <= _response.status_code < 300: + return typing.cast(TokenizeResponse, construct_type(type_=TokenizeResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(TokenizeResponse, construct_type(type_=TokenizeResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -2057,53 +2051,53 @@ def detokenize( request_options=request_options, omit=OMIT, ) + if 200 <= _response.status_code < 300: + return typing.cast(DetokenizeResponse, construct_type(type_=DetokenizeResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(DetokenizeResponse, construct_type(type_=DetokenizeResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -2136,53 +2130,53 @@ def check_api_key(self, *, request_options: typing.Optional[RequestOptions] = No _response = self._client_wrapper.httpx_client.request( "check-api-key", method="POST", request_options=request_options ) + if 200 <= _response.status_code < 300: + return typing.cast(CheckApiKeyResponse, construct_type(type_=CheckApiKeyResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(CheckApiKeyResponse, construct_type(type_=CheckApiKeyResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -2501,8 +2495,6 @@ async def chat_stream( Examples -------- - import asyncio - from cohere import ( ChatConnector, ChatStreamRequestConnectorsSearchOptions, @@ -2519,81 +2511,75 @@ async def chat_stream( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - response = await client.chat_stream( - message="string", - model="string", - preamble="string", - chat_history=[ - Message_Chatbot( - message="string", - tool_calls=[ - ToolCall( - name="string", - parameters={"string": {"key": "value"}}, - ) - ], - ) - ], - conversation_id="string", - prompt_truncation="OFF", - connectors=[ - ChatConnector( - id="string", - user_access_token="string", - continue_on_failure=True, - options={"string": {"key": "value"}}, - ) - ], - search_queries_only=True, - documents=[{"string": {"key": "value"}}], - citation_quality="fast", - temperature=1.1, - max_tokens=1, - max_input_tokens=1, - k=1, - p=1.1, - seed=1, - stop_sequences=["string"], - connectors_search_options=ChatStreamRequestConnectorsSearchOptions( - seed=1, - ), - frequency_penalty=1.1, - presence_penalty=1.1, - raw_prompting=True, - return_prompt=True, - tools=[ - Tool( - name="string", - description="string", - parameter_definitions={ - "string": ToolParameterDefinitionsValue( - description="string", - type="string", - required=True, - ) - }, - ) - ], - tool_results=[ - ToolResult( - call=ToolCall( + response = await client.chat_stream( + message="string", + model="string", + preamble="string", + chat_history=[ + Message_Chatbot( + message="string", + tool_calls=[ + ToolCall( name="string", parameters={"string": {"key": "value"}}, - ), - outputs=[{"string": {"key": "value"}}], - ) - ], - force_single_step=True, - response_format=ResponseFormat_Text(), - ) - async for chunk in response: - yield chunk - - - asyncio.run(main()) + ) + ], + ) + ], + conversation_id="string", + prompt_truncation="OFF", + connectors=[ + ChatConnector( + id="string", + user_access_token="string", + continue_on_failure=True, + options={"string": {"key": "value"}}, + ) + ], + search_queries_only=True, + documents=[{"string": {"key": "value"}}], + citation_quality="fast", + temperature=1.1, + max_tokens=1, + max_input_tokens=1, + k=1, + p=1.1, + seed=1, + stop_sequences=["string"], + connectors_search_options=ChatStreamRequestConnectorsSearchOptions( + seed=1, + ), + frequency_penalty=1.1, + presence_penalty=1.1, + raw_prompting=True, + return_prompt=True, + tools=[ + Tool( + name="string", + description="string", + parameter_definitions={ + "string": ToolParameterDefinitionsValue( + description="string", + type="string", + required=True, + ) + }, + ) + ], + tool_results=[ + ToolResult( + call=ToolCall( + name="string", + parameters={"string": {"key": "value"}}, + ), + outputs=[{"string": {"key": "value"}}], + ) + ], + force_single_step=True, + response_format=ResponseFormat_Text(), + ) + async for chunk in response: + yield chunk """ async with self._client_wrapper.httpx_client.stream( "chat", @@ -2629,61 +2615,58 @@ async def main() -> None: request_options=request_options, omit=OMIT, ) as _response: + if 200 <= _response.status_code < 300: + async for _text in _response.aiter_lines(): + if len(_text) == 0: + continue + yield typing.cast(StreamedChatResponse, construct_type(type_=StreamedChatResponse, object_=json.loads(_text))) # type: ignore + return + await _response.aread() + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - async for _text in _response.aiter_lines(): - try: - if len(_text) == 0: - continue - yield typing.cast(StreamedChatResponse, construct_type(type_=StreamedChatResponse, object_=json.loads(_text))) # type: ignore - except: - pass - return - await _response.aread() - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -2931,25 +2914,17 @@ async def chat( Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.chat( - message="Can you give me a global market overview of solar panels?", - prompt_truncation="OFF", - temperature=0.3, - ) - - - asyncio.run(main()) + await client.chat( + message="Can you give me a global market overview of solar panels?", + prompt_truncation="OFF", + temperature=0.3, + ) """ _response = await self._client_wrapper.httpx_client.request( "chat", @@ -2985,53 +2960,53 @@ async def main() -> None: request_options=request_options, omit=OMIT, ) + if 200 <= _response.status_code < 300: + return typing.cast(NonStreamedChatResponse, construct_type(type_=NonStreamedChatResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(NonStreamedChatResponse, construct_type(type_=NonStreamedChatResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -3163,40 +3138,32 @@ async def generate_stream( Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - response = await client.generate_stream( - prompt="string", - model="string", - num_generations=1, - max_tokens=1, - truncate="NONE", - temperature=1.1, - seed=1, - preset="string", - end_sequences=["string"], - stop_sequences=["string"], - k=1, - p=1.1, - frequency_penalty=1.1, - presence_penalty=1.1, - return_likelihoods="GENERATION", - raw_prompting=True, - ) - async for chunk in response: - yield chunk - - - asyncio.run(main()) + response = await client.generate_stream( + prompt="string", + model="string", + num_generations=1, + max_tokens=1, + truncate="NONE", + temperature=1.1, + seed=1, + preset="string", + end_sequences=["string"], + stop_sequences=["string"], + k=1, + p=1.1, + frequency_penalty=1.1, + presence_penalty=1.1, + return_likelihoods="GENERATION", + raw_prompting=True, + ) + async for chunk in response: + yield chunk """ async with self._client_wrapper.httpx_client.stream( "generate", @@ -3223,61 +3190,58 @@ async def main() -> None: request_options=request_options, omit=OMIT, ) as _response: + if 200 <= _response.status_code < 300: + async for _text in _response.aiter_lines(): + if len(_text) == 0: + continue + yield typing.cast(GenerateStreamedResponse, construct_type(type_=GenerateStreamedResponse, object_=json.loads(_text))) # type: ignore + return + await _response.aread() + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - async for _text in _response.aiter_lines(): - try: - if len(_text) == 0: - continue - yield typing.cast(GenerateStreamedResponse, construct_type(type_=GenerateStreamedResponse, object_=json.loads(_text))) # type: ignore - except: - pass - return - await _response.aread() - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -3409,23 +3373,15 @@ async def generate( Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.generate( - prompt="Please explain to me how LLMs work", - ) - - - asyncio.run(main()) + await client.generate( + prompt="Please explain to me how LLMs work", + ) """ _response = await self._client_wrapper.httpx_client.request( "generate", @@ -3452,53 +3408,53 @@ async def main() -> None: request_options=request_options, omit=OMIT, ) + if 200 <= _response.status_code < 300: + return typing.cast(Generation, construct_type(type_=Generation, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(Generation, construct_type(type_=Generation, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -3570,27 +3526,19 @@ async def embed( Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.embed( - texts=["string"], - model="string", - input_type="search_document", - embedding_types=["float"], - truncate="NONE", - ) - - - asyncio.run(main()) + await client.embed( + texts=["string"], + model="string", + input_type="search_document", + embedding_types=["float"], + truncate="NONE", + ) """ _response = await self._client_wrapper.httpx_client.request( "embed", @@ -3605,53 +3553,53 @@ async def main() -> None: request_options=request_options, omit=OMIT, ) + if 200 <= _response.status_code < 300: + return typing.cast(EmbedResponse, construct_type(type_=EmbedResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(EmbedResponse, construct_type(type_=EmbedResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -3711,30 +3659,22 @@ async def rerank( Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.rerank( - model="rerank-english-v3.0", - query="What is the capital of the United States?", - documents=[ - "Carson City is the capital city of the American state of Nevada.", - "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.", - "Washington, D.C. (also known as simply Washington or D.C., and officially as the District of Columbia) is the capital of the United States. It is a federal district.", - "Capital punishment (the death penalty) has existed in the United States since beforethe United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states.", - ], - ) - - - asyncio.run(main()) + await client.rerank( + model="rerank-english-v3.0", + query="What is the capital of the United States?", + documents=[ + "Carson City is the capital city of the American state of Nevada.", + "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.", + "Washington, D.C. (also known as simply Washington or D.C., and officially as the District of Columbia) is the capital of the United States. It is a federal district.", + "Capital punishment (the death penalty) has existed in the United States since beforethe United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states.", + ], + ) """ _response = await self._client_wrapper.httpx_client.request( "rerank", @@ -3751,53 +3691,53 @@ async def main() -> None: request_options=request_options, omit=OMIT, ) + if 200 <= _response.status_code < 300: + return typing.cast(RerankResponse, construct_type(type_=RerankResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(RerankResponse, construct_type(type_=RerankResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -3849,8 +3789,6 @@ async def classify( Examples -------- - import asyncio - from cohere import ClassifyExample from cohere.client import AsyncClient @@ -3858,57 +3796,51 @@ async def classify( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.classify( - inputs=["Confirm your email address", "hey i need u to send some $"], - examples=[ - ClassifyExample( - text="Dermatologists don't like her!", - label="Spam", - ), - ClassifyExample( - text="Hello, open to this?", - label="Spam", - ), - ClassifyExample( - text="I need help please wire me $1000 right now", - label="Spam", - ), - ClassifyExample( - text="Nice to know you ;)", - label="Spam", - ), - ClassifyExample( - text="Please help me?", - label="Spam", - ), - ClassifyExample( - text="Your parcel will be delivered today", - label="Not spam", - ), - ClassifyExample( - text="Review changes to our Terms and Conditions", - label="Not spam", - ), - ClassifyExample( - text="Weekly sync notes", - label="Not spam", - ), - ClassifyExample( - text="Re: Follow up from today’s meeting", - label="Not spam", - ), - ClassifyExample( - text="Pre-read for tomorrow", - label="Not spam", - ), - ], - ) - - - asyncio.run(main()) + await client.classify( + inputs=["Confirm your email address", "hey i need u to send some $"], + examples=[ + ClassifyExample( + text="Dermatologists don't like her!", + label="Spam", + ), + ClassifyExample( + text="Hello, open to this?", + label="Spam", + ), + ClassifyExample( + text="I need help please wire me $1000 right now", + label="Spam", + ), + ClassifyExample( + text="Nice to know you ;)", + label="Spam", + ), + ClassifyExample( + text="Please help me?", + label="Spam", + ), + ClassifyExample( + text="Your parcel will be delivered today", + label="Not spam", + ), + ClassifyExample( + text="Review changes to our Terms and Conditions", + label="Not spam", + ), + ClassifyExample( + text="Weekly sync notes", + label="Not spam", + ), + ClassifyExample( + text="Re: Follow up from today’s meeting", + label="Not spam", + ), + ClassifyExample( + text="Pre-read for tomorrow", + label="Not spam", + ), + ], + ) """ _response = await self._client_wrapper.httpx_client.request( "classify", @@ -3917,53 +3849,53 @@ async def main() -> None: request_options=request_options, omit=OMIT, ) + if 200 <= _response.status_code < 300: + return typing.cast(ClassifyResponse, construct_type(type_=ClassifyResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(ClassifyResponse, construct_type(type_=ClassifyResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -4021,23 +3953,15 @@ async def summarize( Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.summarize( - text='Ice cream is a sweetened frozen food typically eaten as a snack or dessert. It may be made from milk or cream and is flavoured with a sweetener, either sugar or an alternative, and a spice, such as cocoa or vanilla, or with fruit such as strawberries or peaches. It can also be made by whisking a flavored cream base and liquid nitrogen together. Food coloring is sometimes added, in addition to stabilizers. The mixture is cooled below the freezing point of water and stirred to incorporate air spaces and to prevent detectable ice crystals from forming. The result is a smooth, semi-solid foam that is solid at very low temperatures (below 2 Β°C or 35 Β°F). It becomes more malleable as its temperature increases.\n\nThe meaning of the name "ice cream" varies from one country to another. In some countries, such as the United States, "ice cream" applies only to a specific variety, and most governments regulate the commercial use of the various terms according to the relative quantities of the main ingredients, notably the amount of cream. Products that do not meet the criteria to be called ice cream are sometimes labelled "frozen dairy dessert" instead. In other countries, such as Italy and Argentina, one word is used fo\r all variants. Analogues made from dairy alternatives, such as goat\'s or sheep\'s milk, or milk substitutes (e.g., soy, cashew, coconut, almond milk or tofu), are available for those who are lactose intolerant, allergic to dairy protein or vegan.', - ) - - - asyncio.run(main()) + await client.summarize( + text='Ice cream is a sweetened frozen food typically eaten as a snack or dessert. It may be made from milk or cream and is flavoured with a sweetener, either sugar or an alternative, and a spice, such as cocoa or vanilla, or with fruit such as strawberries or peaches. It can also be made by whisking a flavored cream base and liquid nitrogen together. Food coloring is sometimes added, in addition to stabilizers. The mixture is cooled below the freezing point of water and stirred to incorporate air spaces and to prevent detectable ice crystals from forming. The result is a smooth, semi-solid foam that is solid at very low temperatures (below 2 Β°C or 35 Β°F). It becomes more malleable as its temperature increases.\n\nThe meaning of the name "ice cream" varies from one country to another. In some countries, such as the United States, "ice cream" applies only to a specific variety, and most governments regulate the commercial use of the various terms according to the relative quantities of the main ingredients, notably the amount of cream. Products that do not meet the criteria to be called ice cream are sometimes labelled "frozen dairy dessert" instead. In other countries, such as Italy and Argentina, one word is used fo\r all variants. Analogues made from dairy alternatives, such as goat\'s or sheep\'s milk, or milk substitutes (e.g., soy, cashew, coconut, almond milk or tofu), are available for those who are lactose intolerant, allergic to dairy protein or vegan.', + ) """ _response = await self._client_wrapper.httpx_client.request( "summarize", @@ -4054,53 +3978,53 @@ async def main() -> None: request_options=request_options, omit=OMIT, ) + if 200 <= _response.status_code < 300: + return typing.cast(SummarizeResponse, construct_type(type_=SummarizeResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(SummarizeResponse, construct_type(type_=SummarizeResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -4130,75 +4054,67 @@ async def tokenize( Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.tokenize( - text="tokenize me! :D", - model="command", - ) - - - asyncio.run(main()) + await client.tokenize( + text="tokenize me! :D", + model="command", + ) """ _response = await self._client_wrapper.httpx_client.request( "tokenize", method="POST", json={"text": text, "model": model}, request_options=request_options, omit=OMIT ) + if 200 <= _response.status_code < 300: + return typing.cast(TokenizeResponse, construct_type(type_=TokenizeResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(TokenizeResponse, construct_type(type_=TokenizeResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -4228,24 +4144,16 @@ async def detokenize( Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.detokenize( - tokens=[10104, 12221, 1315, 34, 1420, 69], - model="command", - ) - - - asyncio.run(main()) + await client.detokenize( + tokens=[10104, 12221, 1315, 34, 1420, 69], + model="command", + ) """ _response = await self._client_wrapper.httpx_client.request( "detokenize", @@ -4254,53 +4162,53 @@ async def main() -> None: request_options=request_options, omit=OMIT, ) + if 200 <= _response.status_code < 300: + return typing.cast(DetokenizeResponse, construct_type(type_=DetokenizeResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(DetokenizeResponse, construct_type(type_=DetokenizeResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -4322,72 +4230,64 @@ async def check_api_key(self, *, request_options: typing.Optional[RequestOptions Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.check_api_key() - - - asyncio.run(main()) + await client.check_api_key() """ _response = await self._client_wrapper.httpx_client.request( "check-api-key", method="POST", request_options=request_options ) + if 200 <= _response.status_code < 300: + return typing.cast(CheckApiKeyResponse, construct_type(type_=CheckApiKeyResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(CheckApiKeyResponse, construct_type(type_=CheckApiKeyResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) diff --git a/src/cohere/connectors/client.py b/src/cohere/connectors/client.py index 637021122..abc168c49 100644 --- a/src/cohere/connectors/client.py +++ b/src/cohere/connectors/client.py @@ -80,53 +80,53 @@ def list( _response = self._client_wrapper.httpx_client.request( "connectors", method="GET", params={"limit": limit, "offset": offset}, request_options=request_options ) + if 200 <= _response.status_code < 300: + return typing.cast(ListConnectorsResponse, construct_type(type_=ListConnectorsResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(ListConnectorsResponse, construct_type(type_=ListConnectorsResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -211,53 +211,53 @@ def create( request_options=request_options, omit=OMIT, ) + if 200 <= _response.status_code < 300: + return typing.cast(CreateConnectorResponse, construct_type(type_=CreateConnectorResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(CreateConnectorResponse, construct_type(type_=CreateConnectorResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -295,53 +295,53 @@ def get(self, id: str, *, request_options: typing.Optional[RequestOptions] = Non _response = self._client_wrapper.httpx_client.request( f"connectors/{jsonable_encoder(id)}", method="GET", request_options=request_options ) + if 200 <= _response.status_code < 300: + return typing.cast(GetConnectorResponse, construct_type(type_=GetConnectorResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(GetConnectorResponse, construct_type(type_=GetConnectorResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -379,53 +379,53 @@ def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = _response = self._client_wrapper.httpx_client.request( f"connectors/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) + if 200 <= _response.status_code < 300: + return typing.cast(DeleteConnectorResponse, construct_type(type_=DeleteConnectorResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(DeleteConnectorResponse, construct_type(type_=DeleteConnectorResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -506,53 +506,53 @@ def update( request_options=request_options, omit=OMIT, ) + if 200 <= _response.status_code < 300: + return typing.cast(UpdateConnectorResponse, construct_type(type_=UpdateConnectorResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(UpdateConnectorResponse, construct_type(type_=UpdateConnectorResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -602,53 +602,53 @@ def o_auth_authorize( params={"after_token_redirect": after_token_redirect}, request_options=request_options, ) + if 200 <= _response.status_code < 300: + return typing.cast(OAuthAuthorizeResponse, construct_type(type_=OAuthAuthorizeResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(OAuthAuthorizeResponse, construct_type(type_=OAuthAuthorizeResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -687,72 +687,64 @@ async def list( Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.connectors.list() - - - asyncio.run(main()) + await client.connectors.list() """ _response = await self._client_wrapper.httpx_client.request( "connectors", method="GET", params={"limit": limit, "offset": offset}, request_options=request_options ) + if 200 <= _response.status_code < 300: + return typing.cast(ListConnectorsResponse, construct_type(type_=ListConnectorsResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(ListConnectorsResponse, construct_type(type_=ListConnectorsResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -810,24 +802,16 @@ async def create( Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.connectors.create( - name="name", - url="url", - ) - - - asyncio.run(main()) + await client.connectors.create( + name="name", + url="url", + ) """ _response = await self._client_wrapper.httpx_client.request( "connectors", @@ -845,53 +829,53 @@ async def main() -> None: request_options=request_options, omit=OMIT, ) + if 200 <= _response.status_code < 300: + return typing.cast(CreateConnectorResponse, construct_type(type_=CreateConnectorResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(CreateConnectorResponse, construct_type(type_=CreateConnectorResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -916,74 +900,66 @@ async def get(self, id: str, *, request_options: typing.Optional[RequestOptions] Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.connectors.get( - id="id", - ) - - - asyncio.run(main()) + await client.connectors.get( + id="id", + ) """ _response = await self._client_wrapper.httpx_client.request( f"connectors/{jsonable_encoder(id)}", method="GET", request_options=request_options ) + if 200 <= _response.status_code < 300: + return typing.cast(GetConnectorResponse, construct_type(type_=GetConnectorResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(GetConnectorResponse, construct_type(type_=GetConnectorResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -1010,74 +986,66 @@ async def delete( Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.connectors.delete( - id="id", - ) - - - asyncio.run(main()) + await client.connectors.delete( + id="id", + ) """ _response = await self._client_wrapper.httpx_client.request( f"connectors/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) + if 200 <= _response.status_code < 300: + return typing.cast(DeleteConnectorResponse, construct_type(type_=DeleteConnectorResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(DeleteConnectorResponse, construct_type(type_=DeleteConnectorResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -1133,23 +1101,15 @@ async def update( Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.connectors.update( - id="id", - ) - - - asyncio.run(main()) + await client.connectors.update( + id="id", + ) """ _response = await self._client_wrapper.httpx_client.request( f"connectors/{jsonable_encoder(id)}", @@ -1166,53 +1126,53 @@ async def main() -> None: request_options=request_options, omit=OMIT, ) + if 200 <= _response.status_code < 300: + return typing.cast(UpdateConnectorResponse, construct_type(type_=UpdateConnectorResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(UpdateConnectorResponse, construct_type(type_=UpdateConnectorResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -1246,23 +1206,15 @@ async def o_auth_authorize( Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.connectors.o_auth_authorize( - id="id", - ) - - - asyncio.run(main()) + await client.connectors.o_auth_authorize( + id="id", + ) """ _response = await self._client_wrapper.httpx_client.request( f"connectors/{jsonable_encoder(id)}/oauth/authorize", @@ -1270,53 +1222,53 @@ async def main() -> None: params={"after_token_redirect": after_token_redirect}, request_options=request_options, ) + if 200 <= _response.status_code < 300: + return typing.cast(OAuthAuthorizeResponse, construct_type(type_=OAuthAuthorizeResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(OAuthAuthorizeResponse, construct_type(type_=OAuthAuthorizeResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) diff --git a/src/cohere/core/__init__.py b/src/cohere/core/__init__.py index 1a86ed174..e4d00ce0e 100644 --- a/src/cohere/core/__init__.py +++ b/src/cohere/core/__init__.py @@ -6,16 +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 ( - IS_PYDANTIC_V2, - UniversalBaseModel, - UniversalRootModel, - deep_union_pydantic_dicts, - parse_obj_as, - universal_field_validator, - universal_root_validator, - update_forward_refs, -) +from .pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .query_encoder import encode_query from .remove_none_from_dict import remove_none_from_dict from .request_options import RequestOptions @@ -28,22 +19,16 @@ "BaseClientWrapper", "File", "HttpClient", - "IS_PYDANTIC_V2", "RequestOptions", "SyncClientWrapper", "UncheckedBaseModel", "UnionMetadata", - "UniversalBaseModel", - "UniversalRootModel", "construct_type", "convert_file_dict_to_httpx_tuples", "deep_union_pydantic_dicts", "encode_query", "jsonable_encoder", - "parse_obj_as", + "pydantic_v1", "remove_none_from_dict", "serialize_datetime", - "universal_field_validator", - "universal_root_validator", - "update_forward_refs", ] diff --git a/src/cohere/core/client_wrapper.py b/src/cohere/core/client_wrapper.py index e8fbe702b..c53534f75 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.7.0", + "X-Fern-SDK-Version": "5.6.2", } if self._client_name is not None: headers["X-Client-Name"] = self._client_name diff --git a/src/cohere/core/http_client.py b/src/cohere/core/http_client.py index 9333d8a7f..ed7cf5d3d 100644 --- a/src/cohere/core/http_client.py +++ b/src/cohere/core/http_client.py @@ -2,7 +2,6 @@ import asyncio import email.utils -import json import re import time import typing @@ -108,7 +107,7 @@ def maybe_filter_request_body( ) -> typing.Optional[typing.Any]: if data is None: return ( - jsonable_encoder(request_options.get("additional_body_parameters", {})) or {} + jsonable_encoder(request_options.get("additional_body_parameters", {})) if request_options is not None else None ) @@ -118,7 +117,7 @@ def maybe_filter_request_body( data_content = { **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore **( - jsonable_encoder(request_options.get("additional_body_parameters", {})) or {} + jsonable_encoder(request_options.get("additional_body_parameters", {})) if request_options is not None else {} ), @@ -126,25 +125,6 @@ def maybe_filter_request_body( return data_content -# Abstracted out for testing purposes -def get_request_body( - *, - json: typing.Optional[typing.Any], - data: typing.Optional[typing.Any], - request_options: typing.Optional[RequestOptions], - omit: typing.Optional[typing.Any], -) -> typing.Tuple[typing.Optional[typing.Any], typing.Optional[typing.Any]]: - json_body = None - data_body = None - if data is not None: - data_body = maybe_filter_request_body(data, request_options, omit) - else: - # If both data and json are None, we send json data in the event extra properties are specified - json_body = maybe_filter_request_body(json, request_options, omit) - - return json_body, data_body - - class HttpClient: def __init__( self, @@ -188,8 +168,6 @@ def request( else self.base_timeout ) - json_body, data_body = get_request_body(json=json, data=data, request_options=request_options, omit=omit) - response = self.httpx_client.request( method=method, url=urllib.parse.urljoin(f"{base_url}/", path), @@ -198,7 +176,7 @@ def request( { **self.base_headers, **(headers if headers is not None else {}), - **(request_options.get("additional_headers", {}) or {} if request_options is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), } ) ), @@ -209,7 +187,7 @@ def request( { **(params if params is not None else {}), **( - request_options.get("additional_query_parameters", {}) or {} + request_options.get("additional_query_parameters", {}) if request_options is not None else {} ), @@ -219,8 +197,8 @@ def request( ) ) ), - json=json_body, - data=data_body, + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), content=content, files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, timeout=timeout, @@ -270,8 +248,6 @@ def stream( else self.base_timeout ) - json_body, data_body = get_request_body(json=json, data=data, request_options=request_options, omit=omit) - with self.httpx_client.stream( method=method, url=urllib.parse.urljoin(f"{base_url}/", path), @@ -301,8 +277,8 @@ def stream( ) ) ), - json=json_body, - data=data_body, + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), content=content, files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, timeout=timeout, @@ -353,8 +329,6 @@ async def request( else self.base_timeout ) - json_body, data_body = get_request_body(json=json, data=data, request_options=request_options, omit=omit) - # Add the input to each of these and do None-safety checks response = await self.httpx_client.request( method=method, @@ -364,7 +338,7 @@ async def request( { **self.base_headers, **(headers if headers is not None else {}), - **(request_options.get("additional_headers", {}) or {} if request_options is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), } ) ), @@ -375,7 +349,7 @@ async def request( { **(params if params is not None else {}), **( - request_options.get("additional_query_parameters", {}) or {} + request_options.get("additional_query_parameters", {}) if request_options is not None else {} ), @@ -385,8 +359,8 @@ async def request( ) ) ), - json=json_body, - data=data_body, + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), content=content, files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, timeout=timeout, @@ -435,8 +409,6 @@ async def stream( else self.base_timeout ) - json_body, data_body = get_request_body(json=json, data=data, request_options=request_options, omit=omit) - async with self.httpx_client.stream( method=method, url=urllib.parse.urljoin(f"{base_url}/", path), @@ -466,8 +438,8 @@ async def stream( ) ) ), - json=json_body, - data=data_body, + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), content=content, files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, timeout=timeout, diff --git a/src/cohere/core/jsonable_encoder.py b/src/cohere/core/jsonable_encoder.py index 9251cd589..7f4827326 100644 --- a/src/cohere/core/jsonable_encoder.py +++ b/src/cohere/core/jsonable_encoder.py @@ -8,23 +8,33 @@ https://github.com/tiangolo/fastapi/blob/master/fastapi/encoders.py """ -import base64 import dataclasses import datetime as dt +from collections import defaultdict from enum import Enum from pathlib import PurePath from types import GeneratorType -from typing import Any, Callable, Dict, List, Optional, Set, Union - -import pydantic +from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union from .datetime_utils import serialize_datetime -from .pydantic_utilities import IS_PYDANTIC_V2, encode_by_type, to_jsonable_with_fallback +from .pydantic_utilities import pydantic_v1 SetIntStr = Set[Union[int, str]] DictIntStrAny = Dict[Union[int, str], Any] +def generate_encoders_by_class_tuples( + type_encoder_map: Dict[Any, Callable[[Any], Any]] +) -> Dict[Callable[[Any], Any], Tuple[Any, ...]]: + encoders_by_class_tuples: Dict[Callable[[Any], Any], Tuple[Any, ...]] = defaultdict(tuple) + for type_, encoder in type_encoder_map.items(): + encoders_by_class_tuples[encoder] += (type_,) + return encoders_by_class_tuples + + +encoders_by_class_tuples = generate_encoders_by_class_tuples(pydantic_v1.json.ENCODERS_BY_TYPE) + + def jsonable_encoder(obj: Any, custom_encoder: Optional[Dict[Any, Callable[[Any], Any]]] = None) -> Any: custom_encoder = custom_encoder or {} if custom_encoder: @@ -34,24 +44,17 @@ def jsonable_encoder(obj: Any, custom_encoder: Optional[Dict[Any, Callable[[Any] for encoder_type, encoder_instance in custom_encoder.items(): if isinstance(obj, encoder_type): return encoder_instance(obj) - if isinstance(obj, pydantic.BaseModel): - if IS_PYDANTIC_V2: - encoder = getattr(obj.model_config, "json_encoders", {}) # type: ignore # Pydantic v2 - else: - encoder = getattr(obj.__config__, "json_encoders", {}) # type: ignore # Pydantic v1 + if isinstance(obj, pydantic_v1.BaseModel): + encoder = getattr(obj.__config__, "json_encoders", {}) if custom_encoder: encoder.update(custom_encoder) obj_dict = obj.dict(by_alias=True) if "__root__" in obj_dict: obj_dict = obj_dict["__root__"] - if "root" in obj_dict: - obj_dict = obj_dict["root"] return jsonable_encoder(obj_dict, custom_encoder=encoder) if dataclasses.is_dataclass(obj): obj_dict = dataclasses.asdict(obj) return jsonable_encoder(obj_dict, custom_encoder=custom_encoder) - if isinstance(obj, bytes): - return base64.b64encode(obj).decode("utf-8") if isinstance(obj, Enum): return obj.value if isinstance(obj, PurePath): @@ -77,21 +80,20 @@ def jsonable_encoder(obj: Any, custom_encoder: Optional[Dict[Any, Callable[[Any] encoded_list.append(jsonable_encoder(item, custom_encoder=custom_encoder)) return encoded_list - def fallback_serializer(o: Any) -> Any: - attempt_encode = encode_by_type(o) - if attempt_encode is not None: - return attempt_encode + if type(obj) in pydantic_v1.json.ENCODERS_BY_TYPE: + return pydantic_v1.json.ENCODERS_BY_TYPE[type(obj)](obj) + for encoder, classes_tuple in encoders_by_class_tuples.items(): + if isinstance(obj, classes_tuple): + return encoder(obj) + try: + data = dict(obj) + except Exception as e: + errors: List[Exception] = [] + errors.append(e) try: - data = dict(o) + data = vars(obj) except Exception as e: - errors: List[Exception] = [] errors.append(e) - try: - data = vars(o) - except Exception as e: - errors.append(e) - raise ValueError(errors) from e - return jsonable_encoder(data, custom_encoder=custom_encoder) - - return to_jsonable_with_fallback(obj, fallback_serializer) + raise ValueError(errors) from e + return jsonable_encoder(data, custom_encoder=custom_encoder) diff --git a/src/cohere/core/pydantic_utilities.py b/src/cohere/core/pydantic_utilities.py index 0f24b0ea8..a72c1a52f 100644 --- a/src/cohere/core/pydantic_utilities.py +++ b/src/cohere/core/pydantic_utilities.py @@ -1,53 +1,15 @@ # This file was auto-generated by Fern from our API Definition. -# nopycln: file -import datetime as dt import typing -from collections import defaultdict -from functools import wraps import pydantic -from .datetime_utils import serialize_datetime - IS_PYDANTIC_V2 = pydantic.VERSION.startswith("2.") if IS_PYDANTIC_V2: - # isort will try to reformat the comments on these imports, which breaks mypy - # isort: off - from pydantic.v1.datetime_parse import ( # type: ignore # pyright: ignore[reportMissingImports] # Pydantic v2 - parse_date as parse_date, - ) - from pydantic.v1.datetime_parse import ( # pyright: ignore[reportMissingImports] # Pydantic v2 - parse_datetime as parse_datetime, - ) - from pydantic.v1.json import ( # type: ignore # pyright: ignore[reportMissingImports] # Pydantic v2 - ENCODERS_BY_TYPE as encoders_by_type, - ) - from pydantic.v1.typing import ( # type: ignore # pyright: ignore[reportMissingImports] # Pydantic v2 - get_args as get_args, - ) - from pydantic.v1.typing import get_origin as get_origin # pyright: ignore[reportMissingImports] # Pydantic v2 - from pydantic.v1.typing import ( # pyright: ignore[reportMissingImports] # Pydantic v2 - is_literal_type as is_literal_type, - ) - from pydantic.v1.typing import is_union as is_union # pyright: ignore[reportMissingImports] # Pydantic v2 - from pydantic.v1.fields import ModelField as ModelField # type: ignore # pyright: ignore[reportMissingImports] # Pydantic v2 + import pydantic.v1 as pydantic_v1 # type: ignore # nopycln: import else: - from pydantic.datetime_parse import parse_date as parse_date # type: ignore # Pydantic v1 - from pydantic.datetime_parse import parse_datetime as parse_datetime # type: ignore # Pydantic v1 - from pydantic.fields import ModelField as ModelField # type: ignore # Pydantic v1 - from pydantic.json import ENCODERS_BY_TYPE as encoders_by_type # type: ignore # Pydantic v1 - from pydantic.typing import get_args as get_args # type: ignore # Pydantic v1 - from pydantic.typing import get_origin as get_origin # type: ignore # Pydantic v1 - from pydantic.typing import is_literal_type as is_literal_type # type: ignore # Pydantic v1 - from pydantic.typing import is_union as is_union # type: ignore # Pydantic v1 - - # isort: on - - -T = typing.TypeVar("T") -Model = typing.TypeVar("Model", bound=pydantic.BaseModel) + import pydantic as pydantic_v1 # type: ignore # nopycln: import def deep_union_pydantic_dicts( @@ -63,117 +25,4 @@ def deep_union_pydantic_dicts( return destination -def parse_obj_as(type_: typing.Type[T], object_: typing.Any) -> T: - if IS_PYDANTIC_V2: - adapter = pydantic.TypeAdapter(type_) # type: ignore # Pydantic v2 - return adapter.validate_python(object_) - else: - return pydantic.parse_obj_as(type_, object_) - - -def to_jsonable_with_fallback( - obj: typing.Any, fallback_serializer: typing.Callable[[typing.Any], typing.Any] -) -> typing.Any: - if IS_PYDANTIC_V2: - from pydantic_core import to_jsonable_python - - return to_jsonable_python(obj, fallback=fallback_serializer) - else: - return fallback_serializer(obj) - - -class UniversalBaseModel(pydantic.BaseModel): - class Config: - populate_by_name = True - smart_union = True - allow_population_by_field_name = True - json_encoders = {dt.datetime: serialize_datetime} - - def json(self, **kwargs: typing.Any) -> str: - kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} - if IS_PYDANTIC_V2: - return super().model_dump_json(**kwargs_with_defaults) # type: ignore # Pydantic v2 - else: - return super().json(**kwargs_with_defaults) - - def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: - kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} - kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} - - if IS_PYDANTIC_V2: - return deep_union_pydantic_dicts( - super().model_dump(**kwargs_with_defaults_exclude_unset), # type: ignore # Pydantic v2 - super().model_dump(**kwargs_with_defaults_exclude_none), # type: ignore # Pydantic v2 - ) - else: - return deep_union_pydantic_dicts( - super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) - ) - - -UniversalRootModel: typing.Type[typing.Any] -if IS_PYDANTIC_V2: - - class V2RootModel(UniversalBaseModel, pydantic.RootModel): # type: ignore # Pydantic v2 - pass - - UniversalRootModel = V2RootModel -else: - UniversalRootModel = UniversalBaseModel - - -def encode_by_type(o: typing.Any) -> typing.Any: - encoders_by_class_tuples: typing.Dict[ - typing.Callable[[typing.Any], typing.Any], typing.Tuple[typing.Any, ...] - ] = defaultdict(tuple) - for type_, encoder in encoders_by_type.items(): - encoders_by_class_tuples[encoder] += (type_,) - - if type(o) in encoders_by_type: - return encoders_by_type[type(o)](o) - for encoder, classes_tuple in encoders_by_class_tuples.items(): - if isinstance(o, classes_tuple): - return encoder(o) - - -def update_forward_refs(model: typing.Type["Model"], **localns: typing.Any) -> None: - if IS_PYDANTIC_V2: - model.model_rebuild(force=True) # type: ignore # Pydantic v2 - else: - model.update_forward_refs(**localns) - - -# Mirrors Pydantic's internal typing -AnyCallable = typing.Callable[..., typing.Any] - - -def universal_root_validator(pre: bool = False) -> typing.Callable[[AnyCallable], AnyCallable]: - def decorator(func: AnyCallable) -> AnyCallable: - @wraps(func) - def validate(*args: typing.Any, **kwargs: typing.Any) -> AnyCallable: - if IS_PYDANTIC_V2: - wrapped_func = pydantic.model_validator("before" if pre else "after")(func) # type: ignore # Pydantic v2 - else: - wrapped_func = pydantic.root_validator(pre=pre)(func) # type: ignore # Pydantic v1 - - return wrapped_func(*args, **kwargs) - - return validate - - return decorator - - -def universal_field_validator(field_name: str, pre: bool = False) -> typing.Callable[[AnyCallable], AnyCallable]: - def decorator(func: AnyCallable) -> AnyCallable: - @wraps(func) - def validate(*args: typing.Any, **kwargs: typing.Any) -> AnyCallable: - if IS_PYDANTIC_V2: - wrapped_func = pydantic.field_validator(field_name, mode="before" if pre else "after")(func) # type: ignore # Pydantic v2 - else: - wrapped_func = pydantic.validator(field_name, pre=pre)(func) - - return wrapped_func(*args, **kwargs) - - return validate - - return decorator +__all__ = ["pydantic_v1"] diff --git a/src/cohere/core/query_encoder.py b/src/cohere/core/query_encoder.py index 24076d72e..1f5f766b4 100644 --- a/src/cohere/core/query_encoder.py +++ b/src/cohere/core/query_encoder.py @@ -3,7 +3,7 @@ from collections import ChainMap from typing import Any, Dict, Optional -import pydantic +from .pydantic_utilities import pydantic_v1 # Flattens dicts to be of the form {"key[subkey][subkey2]": value} where value is not a dict @@ -19,8 +19,8 @@ def traverse_query_dict(dict_flat: Dict[str, Any], key_prefix: Optional[str] = N def single_query_encoder(query_key: str, query_value: Any) -> Dict[str, Any]: - if isinstance(query_value, pydantic.BaseModel) or isinstance(query_value, dict): - if isinstance(query_value, pydantic.BaseModel): + if isinstance(query_value, pydantic_v1.BaseModel) or isinstance(query_value, dict): + if isinstance(query_value, pydantic_v1.BaseModel): obj_dict = query_value.dict(by_alias=True) else: obj_dict = query_value diff --git a/src/cohere/core/request_options.py b/src/cohere/core/request_options.py index d0bf0dbce..cd6f27a7e 100644 --- a/src/cohere/core/request_options.py +++ b/src/cohere/core/request_options.py @@ -5,10 +5,10 @@ try: from typing import NotRequired # type: ignore except ImportError: - from typing_extensions import NotRequired + from typing_extensions import NotRequired # type: ignore -class RequestOptions(typing.TypedDict, total=False): +class RequestOptions(typing.TypedDict): """ Additional options for request-specific configuration when calling APIs via the SDK. This is used primarily as an optional final parameter for service functions. diff --git a/src/cohere/core/unchecked_base_model.py b/src/cohere/core/unchecked_base_model.py index 7a832d0a0..a29d39c24 100644 --- a/src/cohere/core/unchecked_base_model.py +++ b/src/cohere/core/unchecked_base_model.py @@ -5,22 +5,10 @@ import typing import uuid -import pydantic import typing_extensions -from pydantic_core import PydanticUndefined - -from .pydantic_utilities import ( - IS_PYDANTIC_V2, - ModelField, - UniversalBaseModel, - get_args, - get_origin, - is_literal_type, - is_union, - parse_date, - parse_datetime, - parse_obj_as, -) + +from .datetime_utils import serialize_datetime +from .pydantic_utilities import pydantic_v1 class UnionMetadata: @@ -30,23 +18,18 @@ def __init__(self, *, discriminant: str) -> None: self.discriminant = discriminant -Model = typing.TypeVar("Model", bound=pydantic.BaseModel) - - -class UncheckedBaseModel(UniversalBaseModel): - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow") # type: ignore # Pydantic v2 - else: +Model = typing.TypeVar("Model", bound=pydantic_v1.BaseModel) - class Config: - extra = pydantic.Extra.allow - @classmethod - def model_construct( - cls: typing.Type["Model"], _fields_set: typing.Optional[typing.Set[str]] = None, **values: typing.Any - ) -> "Model": - # Fallback construct function to the specified override below. - return cls.construct(_fields_set=_fields_set, **values) +class UncheckedBaseModel(pydantic_v1.BaseModel): + # Allow extra fields + class Config: + extra = pydantic_v1.Extra.allow + smart_union = True + allow_population_by_field_name = True + populate_by_name = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} # Allow construct to not validate model # Implementation taken from: https://github.com/pydantic/pydantic/issues/1168#issuecomment-817742836 @@ -54,76 +37,61 @@ def model_construct( def construct( cls: typing.Type["Model"], _fields_set: typing.Optional[typing.Set[str]] = None, **values: typing.Any ) -> "Model": - m = cls.__new__(cls) + m = cls.__new__(cls) # type: ignore fields_values = {} + config = cls.__config__ + if _fields_set is None: _fields_set = set(values.keys()) - fields = _get_model_fields(cls) - populate_by_name = _get_is_populate_by_name(cls) - - for name, field in fields.items(): + for name, field in cls.__fields__.items(): # Key here is only used to pull data from the values dict # you should always use the NAME of the field to for field_values, etc. # because that's how the object is constructed from a pydantic perspective key = field.alias - if key is None or (key not in values and populate_by_name): # Added this to allow population by field name + if key is None or ( + key not in values and config.allow_population_by_field_name + ): # Added this to allow population by field name key = name if key in values: - if IS_PYDANTIC_V2: - type_ = field.annotation # type: ignore # Pydantic v2 - else: - type_ = typing.cast(typing.Type, field.outer_type_) # type: ignore # Pydantic < v1.10.15 - - fields_values[name] = ( - construct_type(object_=values[key], type_=type_) if type_ is not None else values[key] - ) + type_ = typing.cast(typing.Type, field.outer_type_) # type: ignore + fields_values[name] = construct_type(object_=values[key], type_=type_) _fields_set.add(name) else: - default = _get_field_default(field) + default = field.get_default() fields_values[name] = default # If the default values are non-null act like they've been set # This effectively allows exclude_unset to work like exclude_none where # the latter passes through intentionally set none values. - if default != None and default != PydanticUndefined: + if default != None: _fields_set.add(name) # Add extras back in - extras = {} - alias_fields = [field.alias for field in fields.values()] + alias_fields = [field.alias for field in cls.__fields__.values()] for key, value in values.items(): - if key not in alias_fields and key not in fields: - if IS_PYDANTIC_V2: - extras[key] = value - else: - _fields_set.add(key) - fields_values[key] = value + if key not in alias_fields and key not in cls.__fields__: + _fields_set.add(key) + fields_values[key] = value object.__setattr__(m, "__dict__", fields_values) - - if IS_PYDANTIC_V2: - object.__setattr__(m, "__pydantic_private__", None) - object.__setattr__(m, "__pydantic_extra__", extras) - object.__setattr__(m, "__pydantic_fields_set__", _fields_set) - else: - object.__setattr__(m, "__fields_set__", _fields_set) - m._init_private_attributes() # type: ignore # Pydantic v1 + m._init_private_attributes() + object.__setattr__(m, "__fields_set__", _fields_set) return m def _convert_undiscriminated_union_type(union_type: typing.Type[typing.Any], object_: typing.Any) -> typing.Any: - inner_types = get_args(union_type) + inner_types = pydantic_v1.typing.get_args(union_type) if typing.Any in inner_types: return object_ for inner_type in inner_types: try: - if inspect.isclass(inner_type) and issubclass(inner_type, pydantic.BaseModel): + if inspect.isclass(inner_type) and issubclass(inner_type, pydantic_v1.BaseModel): # Attempt a validated parse until one works - return parse_obj_as(inner_type, object_) + return pydantic_v1.parse_obj_as(inner_type, object_) except Exception: continue @@ -136,16 +104,16 @@ def _convert_undiscriminated_union_type(union_type: typing.Type[typing.Any], obj def _convert_union_type(type_: typing.Type[typing.Any], object_: typing.Any) -> typing.Any: - base_type = get_origin(type_) or type_ + base_type = pydantic_v1.typing.get_origin(type_) or type_ union_type = type_ if base_type == typing_extensions.Annotated: - union_type = get_args(type_)[0] - annotated_metadata = get_args(type_)[1:] + union_type = pydantic_v1.typing.get_args(type_)[0] + annotated_metadata = pydantic_v1.typing.get_args(type_)[1:] for metadata in annotated_metadata: if isinstance(metadata, UnionMetadata): try: # Cast to the correct type, based on the discriminant - for inner_type in get_args(union_type): + for inner_type in pydantic_v1.typing.get_args(union_type): try: objects_discriminant = getattr(object_, metadata.discriminant) except: @@ -164,14 +132,12 @@ def construct_type(*, type_: typing.Type[typing.Any], object_: typing.Any) -> ty Pydantic models. The idea is to essentially attempt to coerce object_ to type_ (recursively) """ - # Short circuit when dealing with optionals, don't try to coerces None to a type - if object_ is None: - return None - - base_type = get_origin(type_) or type_ + base_type = pydantic_v1.typing.get_origin(type_) or type_ is_annotated = base_type == typing_extensions.Annotated - maybe_annotation_members = get_args(type_) - is_annotated_union = is_annotated and is_union(get_origin(maybe_annotation_members[0])) + maybe_annotation_members = pydantic_v1.typing.get_args(type_) + is_annotated_union = is_annotated and pydantic_v1.typing.is_union( + pydantic_v1.typing.get_origin(maybe_annotation_members[0]) + ) if base_type == typing.Any: return object_ @@ -180,7 +146,7 @@ def construct_type(*, type_: typing.Type[typing.Any], object_: typing.Any) -> ty if not isinstance(object_, typing.Mapping): return object_ - key_type, items_type = get_args(type_) + key_type, items_type = pydantic_v1.typing.get_args(type_) d = { construct_type(object_=key, type_=key_type): construct_type(object_=item, type_=items_type) for key, item in object_.items() @@ -191,39 +157,36 @@ def construct_type(*, type_: typing.Type[typing.Any], object_: typing.Any) -> ty if not isinstance(object_, list): return object_ - inner_type = get_args(type_)[0] + inner_type = pydantic_v1.typing.get_args(type_)[0] return [construct_type(object_=entry, type_=inner_type) for entry in object_] if base_type == set: if not isinstance(object_, set) and not isinstance(object_, list): return object_ - inner_type = get_args(type_)[0] + inner_type = pydantic_v1.typing.get_args(type_)[0] return {construct_type(object_=entry, type_=inner_type) for entry in object_} - if is_union(base_type) or is_annotated_union: + if pydantic_v1.typing.is_union(base_type) or is_annotated_union: return _convert_union_type(type_, object_) # Cannot do an `issubclass` with a literal type, let's also just confirm we have a class before this call if ( object_ is not None - and not is_literal_type(type_) - and (inspect.isclass(base_type) and issubclass(base_type, pydantic.BaseModel)) + and not pydantic_v1.typing.is_literal_type(type_) + and (inspect.isclass(base_type) and issubclass(base_type, pydantic_v1.BaseModel)) ): - if IS_PYDANTIC_V2: - return type_.model_construct(**object_) - else: - return type_.construct(**object_) + return type_.construct(**object_) if base_type == dt.datetime: try: - return parse_datetime(object_) + return pydantic_v1.datetime_parse.parse_datetime(object_) except Exception: return object_ if base_type == dt.date: try: - return parse_date(object_) + return pydantic_v1.datetime_parse.parse_date(object_) except Exception: return object_ @@ -250,35 +213,3 @@ def construct_type(*, type_: typing.Type[typing.Any], object_: typing.Any) -> ty return object_ return object_ - - -def _get_is_populate_by_name(model: typing.Type["Model"]) -> bool: - if IS_PYDANTIC_V2: - return model.model_config.get("populate_by_name", False) # type: ignore # Pydantic v2 - return model.__config__.allow_population_by_field_name # type: ignore # Pydantic v1 - - -PydanticField = typing.Union[ModelField, pydantic.fields.FieldInfo] - - -# Pydantic V1 swapped the typing of __fields__'s values from ModelField to FieldInfo -# And so we try to handle both V1 cases, as well as V2 (FieldInfo from model.model_fields) -def _get_model_fields(model: typing.Type["Model"]) -> typing.Mapping[str, PydanticField]: - if IS_PYDANTIC_V2: - return model.model_fields # type: ignore # Pydantic v2 - else: - return model.__fields__ - - -def _get_field_default(field: PydanticField) -> typing.Any: - try: - value = field.get_default() # type: ignore # Pydantic < v1.10.15 - except: - value = field.default - if IS_PYDANTIC_V2: - from pydantic_core import PydanticUndefined - - if value == PydanticUndefined: - return None - return value - return value diff --git a/src/cohere/datasets/client.py b/src/cohere/datasets/client.py index 044ddeb39..e1bec9ad0 100644 --- a/src/cohere/datasets/client.py +++ b/src/cohere/datasets/client.py @@ -107,53 +107,53 @@ def list( }, request_options=request_options, ) + if 200 <= _response.status_code < 300: + return typing.cast(DatasetsListResponse, construct_type(type_=DatasetsListResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(DatasetsListResponse, construct_type(type_=DatasetsListResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -253,53 +253,53 @@ def create( request_options=request_options, omit=OMIT, ) + if 200 <= _response.status_code < 300: + return typing.cast(DatasetsCreateResponse, construct_type(type_=DatasetsCreateResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(DatasetsCreateResponse, construct_type(type_=DatasetsCreateResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -332,53 +332,53 @@ def get_usage(self, *, request_options: typing.Optional[RequestOptions] = None) _response = self._client_wrapper.httpx_client.request( "datasets/usage", method="GET", request_options=request_options ) + if 200 <= _response.status_code < 300: + return typing.cast(DatasetsGetUsageResponse, construct_type(type_=DatasetsGetUsageResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(DatasetsGetUsageResponse, construct_type(type_=DatasetsGetUsageResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -415,53 +415,53 @@ def get(self, id: str, *, request_options: typing.Optional[RequestOptions] = Non _response = self._client_wrapper.httpx_client.request( f"datasets/{jsonable_encoder(id)}", method="GET", request_options=request_options ) + if 200 <= _response.status_code < 300: + return typing.cast(DatasetsGetResponse, construct_type(type_=DatasetsGetResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(DatasetsGetResponse, construct_type(type_=DatasetsGetResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -500,53 +500,53 @@ def delete( _response = self._client_wrapper.httpx_client.request( f"datasets/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) + if 200 <= _response.status_code < 300: + return typing.cast(typing.Dict[str, typing.Any], construct_type(type_=typing.Dict[str, typing.Any], object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(typing.Dict[str, typing.Any], construct_type(type_=typing.Dict[str, typing.Any], object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -601,21 +601,13 @@ async def list( Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.datasets.list() - - - asyncio.run(main()) + await client.datasets.list() """ _response = await self._client_wrapper.httpx_client.request( "datasets", @@ -630,53 +622,53 @@ async def main() -> None: }, request_options=request_options, ) + if 200 <= _response.status_code < 300: + return typing.cast(DatasetsListResponse, construct_type(type_=DatasetsListResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(DatasetsListResponse, construct_type(type_=DatasetsListResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -746,24 +738,16 @@ async def create( Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.datasets.create( - name="name", - type="embed-input", - ) - - - asyncio.run(main()) + await client.datasets.create( + name="name", + type="embed-input", + ) """ _response = await self._client_wrapper.httpx_client.request( "datasets", @@ -784,53 +768,53 @@ async def main() -> None: request_options=request_options, omit=OMIT, ) + if 200 <= _response.status_code < 300: + return typing.cast(DatasetsCreateResponse, construct_type(type_=DatasetsCreateResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(DatasetsCreateResponse, construct_type(type_=DatasetsCreateResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -852,72 +836,64 @@ async def get_usage(self, *, request_options: typing.Optional[RequestOptions] = Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.datasets.get_usage() - - - asyncio.run(main()) + await client.datasets.get_usage() """ _response = await self._client_wrapper.httpx_client.request( "datasets/usage", method="GET", request_options=request_options ) + if 200 <= _response.status_code < 300: + return typing.cast(DatasetsGetUsageResponse, construct_type(type_=DatasetsGetUsageResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(DatasetsGetUsageResponse, construct_type(type_=DatasetsGetUsageResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -941,74 +917,66 @@ async def get(self, id: str, *, request_options: typing.Optional[RequestOptions] Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.datasets.get( - id="id", - ) - - - asyncio.run(main()) + await client.datasets.get( + id="id", + ) """ _response = await self._client_wrapper.httpx_client.request( f"datasets/{jsonable_encoder(id)}", method="GET", request_options=request_options ) + if 200 <= _response.status_code < 300: + return typing.cast(DatasetsGetResponse, construct_type(type_=DatasetsGetResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(DatasetsGetResponse, construct_type(type_=DatasetsGetResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -1034,74 +1002,66 @@ async def delete( Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.datasets.delete( - id="id", - ) - - - asyncio.run(main()) + await client.datasets.delete( + id="id", + ) """ _response = await self._client_wrapper.httpx_client.request( f"datasets/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) + if 200 <= _response.status_code < 300: + return typing.cast(typing.Dict[str, typing.Any], construct_type(type_=typing.Dict[str, typing.Any], object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(typing.Dict[str, typing.Any], construct_type(type_=typing.Dict[str, typing.Any], object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) diff --git a/src/cohere/datasets/types/datasets_create_response.py b/src/cohere/datasets/types/datasets_create_response.py index a76981445..bc2e4c0b4 100644 --- a/src/cohere/datasets/types/datasets_create_response.py +++ b/src/cohere/datasets/types/datasets_create_response.py @@ -1,24 +1,33 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ...core.pydantic_utilities import IS_PYDANTIC_V2 +from ...core.datetime_utils import serialize_datetime +from ...core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ...core.unchecked_base_model import UncheckedBaseModel class DatasetsCreateResponse(UncheckedBaseModel): - id: typing.Optional[str] = pydantic.Field(default=None) + id: typing.Optional[str] = pydantic_v1.Field(default=None) """ The dataset ID """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/datasets/types/datasets_create_response_dataset_parts_item.py b/src/cohere/datasets/types/datasets_create_response_dataset_parts_item.py index e4e40caef..ee537de8b 100644 --- a/src/cohere/datasets/types/datasets_create_response_dataset_parts_item.py +++ b/src/cohere/datasets/types/datasets_create_response_dataset_parts_item.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ...core.pydantic_utilities import IS_PYDANTIC_V2 +from ...core.datetime_utils import serialize_datetime +from ...core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ...core.unchecked_base_model import UncheckedBaseModel @@ -13,27 +13,36 @@ class DatasetsCreateResponseDatasetPartsItem(UncheckedBaseModel): the underlying files that make up the dataset """ - name: typing.Optional[str] = pydantic.Field(default=None) + name: typing.Optional[str] = pydantic_v1.Field(default=None) """ the name of the dataset part """ - num_rows: typing.Optional[float] = pydantic.Field(default=None) + num_rows: typing.Optional[float] = pydantic_v1.Field(default=None) """ the number of rows in the dataset part """ samples: typing.Optional[typing.List[str]] = None - part_kind: typing.Optional[str] = pydantic.Field(default=None) + part_kind: typing.Optional[str] = pydantic_v1.Field(default=None) """ the kind of dataset part """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 9105e71ee..6fb54e57d 100644 --- a/src/cohere/datasets/types/datasets_get_response.py +++ b/src/cohere/datasets/types/datasets_get_response.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ...core.pydantic_utilities import IS_PYDANTIC_V2 +from ...core.datetime_utils import serialize_datetime +from ...core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ...core.unchecked_base_model import UncheckedBaseModel from ...types.dataset import Dataset @@ -12,11 +12,20 @@ class DatasetsGetResponse(UncheckedBaseModel): dataset: Dataset - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 307c5f2d5..e9cdb9a28 100644 --- a/src/cohere/datasets/types/datasets_get_usage_response.py +++ b/src/cohere/datasets/types/datasets_get_usage_response.py @@ -1,24 +1,33 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ...core.pydantic_utilities import IS_PYDANTIC_V2 +from ...core.datetime_utils import serialize_datetime +from ...core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ...core.unchecked_base_model import UncheckedBaseModel class DatasetsGetUsageResponse(UncheckedBaseModel): - organization_usage: typing.Optional[int] = pydantic.Field(default=None) + organization_usage: typing.Optional[int] = pydantic_v1.Field(default=None) """ The total number of bytes used by the organization. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 11619ad9d..532de3d8b 100644 --- a/src/cohere/datasets/types/datasets_list_response.py +++ b/src/cohere/datasets/types/datasets_list_response.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ...core.pydantic_utilities import IS_PYDANTIC_V2 +from ...core.datetime_utils import serialize_datetime +from ...core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ...core.unchecked_base_model import UncheckedBaseModel from ...types.dataset import Dataset @@ -12,11 +12,20 @@ class DatasetsListResponse(UncheckedBaseModel): datasets: typing.Optional[typing.List[Dataset]] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 bbeeaab2b..397744d77 100644 --- a/src/cohere/embed_jobs/client.py +++ b/src/cohere/embed_jobs/client.py @@ -66,53 +66,53 @@ def list(self, *, request_options: typing.Optional[RequestOptions] = None) -> Li _response = self._client_wrapper.httpx_client.request( "embed-jobs", method="GET", request_options=request_options ) + if 200 <= _response.status_code < 300: + return typing.cast(ListEmbedJobResponse, construct_type(type_=ListEmbedJobResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(ListEmbedJobResponse, construct_type(type_=ListEmbedJobResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -204,53 +204,53 @@ def create( request_options=request_options, omit=OMIT, ) + if 200 <= _response.status_code < 300: + return typing.cast(CreateEmbedJobResponse, construct_type(type_=CreateEmbedJobResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(CreateEmbedJobResponse, construct_type(type_=CreateEmbedJobResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -288,53 +288,53 @@ def get(self, id: str, *, request_options: typing.Optional[RequestOptions] = Non _response = self._client_wrapper.httpx_client.request( f"embed-jobs/{jsonable_encoder(id)}", method="GET", request_options=request_options ) + if 200 <= _response.status_code < 300: + return typing.cast(EmbedJob, construct_type(type_=EmbedJob, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(EmbedJob, construct_type(type_=EmbedJob, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -371,53 +371,53 @@ def cancel(self, id: str, *, request_options: typing.Optional[RequestOptions] = _response = self._client_wrapper.httpx_client.request( f"embed-jobs/{jsonable_encoder(id)}/cancel", method="POST", request_options=request_options ) + if 200 <= _response.status_code < 300: + return + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -444,72 +444,64 @@ async def list(self, *, request_options: typing.Optional[RequestOptions] = None) Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.embed_jobs.list() - - - asyncio.run(main()) + await client.embed_jobs.list() """ _response = await self._client_wrapper.httpx_client.request( "embed-jobs", method="GET", request_options=request_options ) + if 200 <= _response.status_code < 300: + return typing.cast(ListEmbedJobResponse, construct_type(type_=ListEmbedJobResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(ListEmbedJobResponse, construct_type(type_=ListEmbedJobResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -575,25 +567,17 @@ async def create( Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.embed_jobs.create( - model="model", - dataset_id="dataset_id", - input_type="search_document", - ) - - - asyncio.run(main()) + await client.embed_jobs.create( + model="model", + dataset_id="dataset_id", + input_type="search_document", + ) """ _response = await self._client_wrapper.httpx_client.request( "embed-jobs", @@ -609,53 +593,53 @@ async def main() -> None: request_options=request_options, omit=OMIT, ) + if 200 <= _response.status_code < 300: + return typing.cast(CreateEmbedJobResponse, construct_type(type_=CreateEmbedJobResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(CreateEmbedJobResponse, construct_type(type_=CreateEmbedJobResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -680,74 +664,66 @@ async def get(self, id: str, *, request_options: typing.Optional[RequestOptions] Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.embed_jobs.get( - id="id", - ) - - - asyncio.run(main()) + await client.embed_jobs.get( + id="id", + ) """ _response = await self._client_wrapper.httpx_client.request( f"embed-jobs/{jsonable_encoder(id)}", method="GET", request_options=request_options ) + if 200 <= _response.status_code < 300: + return typing.cast(EmbedJob, construct_type(type_=EmbedJob, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(EmbedJob, construct_type(type_=EmbedJob, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -771,74 +747,66 @@ async def cancel(self, id: str, *, request_options: typing.Optional[RequestOptio Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.embed_jobs.cancel( - id="id", - ) - - - asyncio.run(main()) + await client.embed_jobs.cancel( + id="id", + ) """ _response = await self._client_wrapper.httpx_client.request( f"embed-jobs/{jsonable_encoder(id)}/cancel", method="POST", request_options=request_options ) + if 200 <= _response.status_code < 300: + return + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) diff --git a/src/cohere/finetuning/client.py b/src/cohere/finetuning/client.py index 00f3e522f..a157c228a 100644 --- a/src/cohere/finetuning/client.py +++ b/src/cohere/finetuning/client.py @@ -84,33 +84,33 @@ def list_finetuned_models( params={"page_size": page_size, "page_token": page_token, "order_by": order_by}, request_options=request_options, ) + if 200 <= _response.status_code < 300: + return typing.cast(ListFinetunedModelsResponse, construct_type(type_=ListFinetunedModelsResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(ListFinetunedModelsResponse, construct_type(type_=ListFinetunedModelsResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -156,33 +156,33 @@ def create_finetuned_model( _response = self._client_wrapper.httpx_client.request( "finetuning/finetuned-models", method="POST", json=request, request_options=request_options, omit=OMIT ) + if 200 <= _response.status_code < 300: + return typing.cast(CreateFinetunedModelResponse, construct_type(type_=CreateFinetunedModelResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(CreateFinetunedModelResponse, construct_type(type_=CreateFinetunedModelResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -220,33 +220,33 @@ def get_finetuned_model( _response = self._client_wrapper.httpx_client.request( f"finetuning/finetuned-models/{jsonable_encoder(id)}", method="GET", request_options=request_options ) + if 200 <= _response.status_code < 300: + return typing.cast(GetFinetunedModelResponse, construct_type(type_=GetFinetunedModelResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(GetFinetunedModelResponse, construct_type(type_=GetFinetunedModelResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -284,33 +284,33 @@ def delete_finetuned_model( _response = self._client_wrapper.httpx_client.request( f"finetuning/finetuned-models/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) + if 200 <= _response.status_code < 300: + return typing.cast(DeleteFinetunedModelResponse, construct_type(type_=DeleteFinetunedModelResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(DeleteFinetunedModelResponse, construct_type(type_=DeleteFinetunedModelResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -409,33 +409,33 @@ def update_finetuned_model( request_options=request_options, omit=OMIT, ) + if 200 <= _response.status_code < 300: + return typing.cast(UpdateFinetunedModelResponse, construct_type(type_=UpdateFinetunedModelResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(UpdateFinetunedModelResponse, construct_type(type_=UpdateFinetunedModelResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -497,33 +497,33 @@ def list_events( params={"page_size": page_size, "page_token": page_token, "order_by": order_by}, request_options=request_options, ) + if 200 <= _response.status_code < 300: + return typing.cast(ListEventsResponse, construct_type(type_=ListEventsResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(ListEventsResponse, construct_type(type_=ListEventsResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -575,33 +575,33 @@ def list_training_step_metrics( params={"page_size": page_size, "page_token": page_token}, request_options=request_options, ) + if 200 <= _response.status_code < 300: + return typing.cast(ListTrainingStepMetricsResponse, construct_type(type_=ListTrainingStepMetricsResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(ListTrainingStepMetricsResponse, construct_type(type_=ListTrainingStepMetricsResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -648,21 +648,13 @@ async def list_finetuned_models( Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.finetuning.list_finetuned_models() - - - asyncio.run(main()) + await client.finetuning.list_finetuned_models() """ _response = await self._client_wrapper.httpx_client.request( "finetuning/finetuned-models", @@ -670,33 +662,33 @@ async def main() -> None: params={"page_size": page_size, "page_token": page_token, "order_by": order_by}, request_options=request_options, ) + if 200 <= _response.status_code < 300: + return typing.cast(ListFinetunedModelsResponse, construct_type(type_=ListFinetunedModelsResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(ListFinetunedModelsResponse, construct_type(type_=ListFinetunedModelsResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -720,8 +712,6 @@ async def create_finetuned_model( Examples -------- - import asyncio - from cohere.client import AsyncClient from cohere.finetuning import BaseModel, FinetunedModel, Settings @@ -729,54 +719,48 @@ async def create_finetuned_model( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.finetuning.create_finetuned_model( - request=FinetunedModel( - name="api-test", - settings=Settings( - base_model=BaseModel( - base_type="BASE_TYPE_GENERATIVE", - ), - dataset_id="my-dataset-id", + await client.finetuning.create_finetuned_model( + request=FinetunedModel( + name="api-test", + settings=Settings( + base_model=BaseModel( + base_type="BASE_TYPE_GENERATIVE", ), + dataset_id="my-dataset-id", ), - ) - - - asyncio.run(main()) + ), + ) """ _response = await self._client_wrapper.httpx_client.request( "finetuning/finetuned-models", method="POST", json=request, request_options=request_options, omit=OMIT ) + if 200 <= _response.status_code < 300: + return typing.cast(CreateFinetunedModelResponse, construct_type(type_=CreateFinetunedModelResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(CreateFinetunedModelResponse, construct_type(type_=CreateFinetunedModelResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -801,54 +785,46 @@ async def get_finetuned_model( Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.finetuning.get_finetuned_model( - id="id", - ) - - - asyncio.run(main()) + await client.finetuning.get_finetuned_model( + id="id", + ) """ _response = await self._client_wrapper.httpx_client.request( f"finetuning/finetuned-models/{jsonable_encoder(id)}", method="GET", request_options=request_options ) + if 200 <= _response.status_code < 300: + return typing.cast(GetFinetunedModelResponse, construct_type(type_=GetFinetunedModelResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(GetFinetunedModelResponse, construct_type(type_=GetFinetunedModelResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -873,54 +849,46 @@ async def delete_finetuned_model( Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.finetuning.delete_finetuned_model( - id="id", - ) - - - asyncio.run(main()) + await client.finetuning.delete_finetuned_model( + id="id", + ) """ _response = await self._client_wrapper.httpx_client.request( f"finetuning/finetuned-models/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) + if 200 <= _response.status_code < 300: + return typing.cast(DeleteFinetunedModelResponse, construct_type(type_=DeleteFinetunedModelResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(DeleteFinetunedModelResponse, construct_type(type_=DeleteFinetunedModelResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -984,8 +952,6 @@ async def update_finetuned_model( Examples -------- - import asyncio - from cohere.client import AsyncClient from cohere.finetuning import BaseModel, Settings @@ -993,22 +959,16 @@ async def update_finetuned_model( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.finetuning.update_finetuned_model( - id="id", - name="name", - settings=Settings( - base_model=BaseModel( - base_type="BASE_TYPE_UNSPECIFIED", - ), - dataset_id="dataset_id", + await client.finetuning.update_finetuned_model( + id="id", + name="name", + settings=Settings( + base_model=BaseModel( + base_type="BASE_TYPE_UNSPECIFIED", ), - ) - - - asyncio.run(main()) + dataset_id="dataset_id", + ), + ) """ _response = await self._client_wrapper.httpx_client.request( f"finetuning/finetuned-models/{jsonable_encoder(id)}", @@ -1027,33 +987,33 @@ async def main() -> None: request_options=request_options, omit=OMIT, ) + if 200 <= _response.status_code < 300: + return typing.cast(UpdateFinetunedModelResponse, construct_type(type_=UpdateFinetunedModelResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(UpdateFinetunedModelResponse, construct_type(type_=UpdateFinetunedModelResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -1099,23 +1059,15 @@ async def list_events( Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.finetuning.list_events( - finetuned_model_id="finetuned_model_id", - ) - - - asyncio.run(main()) + await client.finetuning.list_events( + finetuned_model_id="finetuned_model_id", + ) """ _response = await self._client_wrapper.httpx_client.request( f"finetuning/finetuned-models/{jsonable_encoder(finetuned_model_id)}/events", @@ -1123,33 +1075,33 @@ async def main() -> None: params={"page_size": page_size, "page_token": page_token, "order_by": order_by}, request_options=request_options, ) + if 200 <= _response.status_code < 300: + return typing.cast(ListEventsResponse, construct_type(type_=ListEventsResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(ListEventsResponse, construct_type(type_=ListEventsResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -1185,23 +1137,15 @@ async def list_training_step_metrics( Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.finetuning.list_training_step_metrics( - finetuned_model_id="finetuned_model_id", - ) - - - asyncio.run(main()) + await client.finetuning.list_training_step_metrics( + finetuned_model_id="finetuned_model_id", + ) """ _response = await self._client_wrapper.httpx_client.request( f"finetuning/finetuned-models/{jsonable_encoder(finetuned_model_id)}/training-step-metrics", @@ -1209,33 +1153,33 @@ async def main() -> None: params={"page_size": page_size, "page_token": page_token}, request_options=request_options, ) + if 200 <= _response.status_code < 300: + return typing.cast(ListTrainingStepMetricsResponse, construct_type(type_=ListTrainingStepMetricsResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(ListTrainingStepMetricsResponse, construct_type(type_=ListTrainingStepMetricsResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) diff --git a/src/cohere/finetuning/finetuning/types/base_model.py b/src/cohere/finetuning/finetuning/types/base_model.py index 85420c0e6..6b8f04e52 100644 --- a/src/cohere/finetuning/finetuning/types/base_model.py +++ b/src/cohere/finetuning/finetuning/types/base_model.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ....core.pydantic_utilities import IS_PYDANTIC_V2 +from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ....core.unchecked_base_model import UncheckedBaseModel from .base_type import BaseType from .strategy import Strategy @@ -15,31 +15,40 @@ class BaseModel(UncheckedBaseModel): 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 7357c61e9..ce59eed31 100644 --- a/src/cohere/finetuning/finetuning/types/create_finetuned_model_response.py +++ b/src/cohere/finetuning/finetuning/types/create_finetuned_model_response.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ....core.pydantic_utilities import IS_PYDANTIC_V2 +from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ....core.unchecked_base_model import UncheckedBaseModel from .finetuned_model import FinetunedModel @@ -14,16 +14,25 @@ class CreateFinetunedModelResponse(UncheckedBaseModel): 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 310249054..c9c5b8a84 100644 --- a/src/cohere/finetuning/finetuning/types/event.py +++ b/src/cohere/finetuning/finetuning/types/event.py @@ -3,9 +3,8 @@ import datetime as dt import typing -import pydantic - -from ....core.pydantic_utilities import IS_PYDANTIC_V2 +from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ....core.unchecked_base_model import UncheckedBaseModel from .status import Status @@ -15,26 +14,35 @@ class Event(UncheckedBaseModel): 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 9bffdde1b..527175c7c 100644 --- a/src/cohere/finetuning/finetuning/types/finetuned_model.py +++ b/src/cohere/finetuning/finetuning/types/finetuned_model.py @@ -3,9 +3,8 @@ import datetime as dt import typing -import pydantic - -from ....core.pydantic_utilities import IS_PYDANTIC_V2 +from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ....core.unchecked_base_model import UncheckedBaseModel from .settings import Settings from .status import Status @@ -16,61 +15,70 @@ class FinetunedModel(UncheckedBaseModel): 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 cb723452f..37a18e10e 100644 --- a/src/cohere/finetuning/finetuning/types/get_finetuned_model_response.py +++ b/src/cohere/finetuning/finetuning/types/get_finetuned_model_response.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ....core.pydantic_utilities import IS_PYDANTIC_V2 +from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ....core.unchecked_base_model import UncheckedBaseModel from .finetuned_model import FinetunedModel @@ -14,16 +14,25 @@ class GetFinetunedModelResponse(UncheckedBaseModel): 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 3875b2d2f..89c374f42 100644 --- a/src/cohere/finetuning/finetuning/types/hyperparameters.py +++ b/src/cohere/finetuning/finetuning/types/hyperparameters.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ....core.pydantic_utilities import IS_PYDANTIC_V2 +from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ....core.unchecked_base_model import UncheckedBaseModel @@ -13,38 +13,47 @@ class Hyperparameters(UncheckedBaseModel): 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 01a30903e..2a9d6d870 100644 --- a/src/cohere/finetuning/finetuning/types/list_events_response.py +++ b/src/cohere/finetuning/finetuning/types/list_events_response.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ....core.pydantic_utilities import IS_PYDANTIC_V2 +from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ....core.unchecked_base_model import UncheckedBaseModel from .event import Event @@ -14,27 +14,36 @@ class ListEventsResponse(UncheckedBaseModel): 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 df082a12a..83c4575b7 100644 --- a/src/cohere/finetuning/finetuning/types/list_finetuned_models_response.py +++ b/src/cohere/finetuning/finetuning/types/list_finetuned_models_response.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ....core.pydantic_utilities import IS_PYDANTIC_V2 +from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ....core.unchecked_base_model import UncheckedBaseModel from .finetuned_model import FinetunedModel @@ -14,27 +14,36 @@ class ListFinetunedModelsResponse(UncheckedBaseModel): 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 996ffc98c..e15acbc87 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 @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ....core.pydantic_utilities import IS_PYDANTIC_V2 +from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ....core.unchecked_base_model import UncheckedBaseModel from .training_step_metrics import TrainingStepMetrics @@ -14,22 +14,31 @@ class ListTrainingStepMetricsResponse(UncheckedBaseModel): 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 ca709d202..ef4619beb 100644 --- a/src/cohere/finetuning/finetuning/types/settings.py +++ b/src/cohere/finetuning/finetuning/types/settings.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ....core.pydantic_utilities import IS_PYDANTIC_V2 +from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ....core.unchecked_base_model import UncheckedBaseModel from .base_model import BaseModel from .hyperparameters import Hyperparameters @@ -15,31 +15,40 @@ class Settings(UncheckedBaseModel): 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). """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 ffd418b30..466f5e0a6 100644 --- a/src/cohere/finetuning/finetuning/types/training_step_metrics.py +++ b/src/cohere/finetuning/finetuning/types/training_step_metrics.py @@ -3,9 +3,8 @@ import datetime as dt import typing -import pydantic - -from ....core.pydantic_utilities import IS_PYDANTIC_V2 +from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ....core.unchecked_base_model import UncheckedBaseModel @@ -14,26 +13,35 @@ class TrainingStepMetrics(UncheckedBaseModel): 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 d8baadb37..3222e5595 100644 --- a/src/cohere/finetuning/finetuning/types/update_finetuned_model_response.py +++ b/src/cohere/finetuning/finetuning/types/update_finetuned_model_response.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ....core.pydantic_utilities import IS_PYDANTIC_V2 +from ....core.datetime_utils import serialize_datetime +from ....core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ....core.unchecked_base_model import UncheckedBaseModel from .finetuned_model import FinetunedModel @@ -14,16 +14,25 @@ class UpdateFinetunedModelResponse(UncheckedBaseModel): 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 644b6d8fb..ed56b49ab 100644 --- a/src/cohere/models/client.py +++ b/src/cohere/models/client.py @@ -64,53 +64,53 @@ def get(self, model: str, *, request_options: typing.Optional[RequestOptions] = _response = self._client_wrapper.httpx_client.request( f"models/{jsonable_encoder(model)}", method="GET", request_options=request_options ) + if 200 <= _response.status_code < 300: + return typing.cast(GetModelResponse, construct_type(type_=GetModelResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(GetModelResponse, construct_type(type_=GetModelResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -172,53 +172,53 @@ def list( }, request_options=request_options, ) + if 200 <= _response.status_code < 300: + return typing.cast(ListModelsResponse, construct_type(type_=ListModelsResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(ListModelsResponse, construct_type(type_=ListModelsResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -247,74 +247,66 @@ async def get(self, model: str, *, request_options: typing.Optional[RequestOptio Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.models.get( - model="command-r", - ) - - - asyncio.run(main()) + await client.models.get( + model="command-r", + ) """ _response = await self._client_wrapper.httpx_client.request( f"models/{jsonable_encoder(model)}", method="GET", request_options=request_options ) + if 200 <= _response.status_code < 300: + return typing.cast(GetModelResponse, construct_type(type_=GetModelResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(GetModelResponse, construct_type(type_=GetModelResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) @@ -357,21 +349,13 @@ async def list( Examples -------- - import asyncio - from cohere.client import AsyncClient client = AsyncClient( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - - - async def main() -> None: - await client.models.list() - - - asyncio.run(main()) + await client.models.list() """ _response = await self._client_wrapper.httpx_client.request( "models", @@ -384,53 +368,53 @@ async def main() -> None: }, request_options=request_options, ) + if 200 <= _response.status_code < 300: + return typing.cast(ListModelsResponse, construct_type(type_=ListModelsResponse, object_=_response.json())) # type: ignore + if _response.status_code == 400: + raise BadRequestError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 404: + raise NotFoundError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 422: + raise UnprocessableEntityError( + typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 429: + raise TooManyRequestsError( + typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 499: + raise ClientClosedRequestError( + typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 501: + raise NotImplementedError( + typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore + ) + if _response.status_code == 503: + raise ServiceUnavailableError( + typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore + ) + if _response.status_code == 504: + raise GatewayTimeoutError( + typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore + ) try: - if 200 <= _response.status_code < 300: - return typing.cast(ListModelsResponse, construct_type(type_=ListModelsResponse, object_=_response.json())) # type: ignore - if _response.status_code == 400: - raise BadRequestError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 401: - raise UnauthorizedError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 403: - raise ForbiddenError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 404: - raise NotFoundError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast(UnprocessableEntityErrorBody, construct_type(type_=UnprocessableEntityErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 429: - raise TooManyRequestsError( - typing.cast(TooManyRequestsErrorBody, construct_type(type_=TooManyRequestsErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 499: - raise ClientClosedRequestError( - typing.cast(ClientClosedRequestErrorBody, construct_type(type_=ClientClosedRequestErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 500: - raise InternalServerError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 501: - raise NotImplementedError( - typing.cast(NotImplementedErrorBody, construct_type(type_=NotImplementedErrorBody, object_=_response.json())) # type: ignore - ) - if _response.status_code == 503: - raise ServiceUnavailableError( - typing.cast(typing.Any, construct_type(type_=typing.Any, object_=_response.json())) # type: ignore - ) - if _response.status_code == 504: - raise GatewayTimeoutError( - typing.cast(GatewayTimeoutErrorBody, construct_type(type_=GatewayTimeoutErrorBody, object_=_response.json())) # type: ignore - ) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, body=_response.text) diff --git a/src/cohere/types/api_meta.py b/src/cohere/types/api_meta.py index cfd06cfa7..8c95c3187 100644 --- a/src/cohere/types/api_meta.py +++ b/src/cohere/types/api_meta.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .api_meta_api_version import ApiMetaApiVersion from .api_meta_billed_units import ApiMetaBilledUnits @@ -17,11 +17,20 @@ class ApiMeta(UncheckedBaseModel): tokens: typing.Optional[ApiMetaTokens] = None warnings: typing.Optional[typing.List[str]] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 62d412cca..19b0fe28a 100644 --- a/src/cohere/types/api_meta_api_version.py +++ b/src/cohere/types/api_meta_api_version.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel @@ -13,11 +13,20 @@ class ApiMetaApiVersion(UncheckedBaseModel): is_deprecated: typing.Optional[bool] = None is_experimental: typing.Optional[bool] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 ea10d2bcb..6f9a8e0c2 100644 --- a/src/cohere/types/api_meta_billed_units.py +++ b/src/cohere/types/api_meta_billed_units.py @@ -1,39 +1,48 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel class ApiMetaBilledUnits(UncheckedBaseModel): - input_tokens: typing.Optional[float] = pydantic.Field(default=None) + 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/api_meta_tokens.py b/src/cohere/types/api_meta_tokens.py index a146803bd..d1a5d7d7a 100644 --- a/src/cohere/types/api_meta_tokens.py +++ b/src/cohere/types/api_meta_tokens.py @@ -1,29 +1,38 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel class ApiMetaTokens(UncheckedBaseModel): - input_tokens: typing.Optional[float] = pydantic.Field(default=None) + input_tokens: typing.Optional[float] = pydantic_v1.Field(default=None) """ The number of tokens used as input to the model. """ - output_tokens: typing.Optional[float] = pydantic.Field(default=None) + output_tokens: typing.Optional[float] = pydantic_v1.Field(default=None) """ The number of tokens produced by the model. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 970f08234..aa15bdb2e 100644 --- a/src/cohere/types/chat_citation.py +++ b/src/cohere/types/chat_citation.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel @@ -13,31 +13,40 @@ class ChatCitation(UncheckedBaseModel): 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 59e1cf823..e62e2420d 100644 --- a/src/cohere/types/chat_citation_generation_event.py +++ b/src/cohere/types/chat_citation_generation_event.py @@ -1,25 +1,36 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .chat_citation import ChatCitation from .chat_stream_event import ChatStreamEvent class ChatCitationGenerationEvent(ChatStreamEvent): - citations: typing.List[ChatCitation] = pydantic.Field() + citations: typing.List[ChatCitation] = pydantic_v1.Field() """ Citations for the generated reply. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + allow_population_by_field_name = True + populate_by_name = True + 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 1b2445393..64c3cbe70 100644 --- a/src/cohere/types/chat_connector.py +++ b/src/cohere/types/chat_connector.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel @@ -13,35 +13,44 @@ class ChatConnector(UncheckedBaseModel): 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. For example, the connector `web-search` supports the `site` option, which limits search results to the specified domain. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 a3ad5c985..b50ffa1c9 100644 --- a/src/cohere/types/chat_data_metrics.py +++ b/src/cohere/types/chat_data_metrics.py @@ -1,34 +1,43 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel class ChatDataMetrics(UncheckedBaseModel): - num_train_turns: typing.Optional[int] = pydantic.Field(default=None) + num_train_turns: typing.Optional[int] = pydantic_v1.Field(default=None) """ The sum of all turns of valid train examples. """ - num_eval_turns: typing.Optional[int] = pydantic.Field(default=None) + num_eval_turns: typing.Optional[int] = pydantic_v1.Field(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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 afc05e1f9..ba723baca 100644 --- a/src/cohere/types/chat_message.py +++ b/src/cohere/types/chat_message.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .tool_call import ToolCall @@ -16,18 +16,27 @@ class ChatMessage(UncheckedBaseModel): 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. """ - message: str = pydantic.Field() + message: str = pydantic_v1.Field() """ Contents of the chat message. """ tool_calls: typing.Optional[typing.List[ToolCall]] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 8de5ff0ef..ef21973e1 100644 --- a/src/cohere/types/chat_request_connectors_search_options.py +++ b/src/cohere/types/chat_request_connectors_search_options.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel @@ -13,7 +13,7 @@ class ChatRequestConnectorsSearchOptions(UncheckedBaseModel): (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=). """ - seed: typing.Optional[int] = pydantic.Field(default=None) + seed: typing.Optional[int] = 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 @@ -22,11 +22,20 @@ class ChatRequestConnectorsSearchOptions(UncheckedBaseModel): Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 226dcba5d..8f295af3d 100644 --- a/src/cohere/types/chat_search_queries_generation_event.py +++ b/src/cohere/types/chat_search_queries_generation_event.py @@ -1,25 +1,36 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .chat_search_query import ChatSearchQuery from .chat_stream_event import ChatStreamEvent 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + allow_population_by_field_name = True + populate_by_name = True + 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 63b855130..7b2095260 100644 --- a/src/cohere/types/chat_search_query.py +++ b/src/cohere/types/chat_search_query.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel @@ -13,21 +13,30 @@ class ChatSearchQuery(UncheckedBaseModel): 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 21f285846..dc1417796 100644 --- a/src/cohere/types/chat_search_result.py +++ b/src/cohere/types/chat_search_result.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .chat_search_query import ChatSearchQuery from .chat_search_result_connector import ChatSearchResultConnector @@ -12,31 +12,40 @@ class ChatSearchResult(UncheckedBaseModel): 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 029c6acd5..6b3183cf7 100644 --- a/src/cohere/types/chat_search_result_connector.py +++ b/src/cohere/types/chat_search_result_connector.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel @@ -13,16 +13,25 @@ class ChatSearchResultConnector(UncheckedBaseModel): The connector used for fetching documents. """ - id: str = pydantic.Field() + id: str = pydantic_v1.Field() """ The identifier of the connector. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 a9c0bbd8b..790c4551e 100644 --- a/src/cohere/types/chat_search_results_event.py +++ b/src/cohere/types/chat_search_results_event.py @@ -1,31 +1,42 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .chat_document import ChatDocument from .chat_search_result import ChatSearchResult from .chat_stream_event import ChatStreamEvent 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: - - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) + + class Config: + frozen = True + smart_union = True + allow_population_by_field_name = True + populate_by_name = True + 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 e14c79bcd..bbe70b7fb 100644 --- a/src/cohere/types/chat_stream_end_event.py +++ b/src/cohere/types/chat_stream_end_event.py @@ -1,17 +1,17 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .chat_stream_end_event_finish_reason import ChatStreamEndEventFinishReason from .chat_stream_event import ChatStreamEvent from .non_streamed_chat_response import NonStreamedChatResponse 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 @@ -20,16 +20,27 @@ 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: - - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) + + class Config: + frozen = True + smart_union = True + allow_population_by_field_name = True + populate_by_name = True + 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 cac6d7e85..0350727ae 100644 --- a/src/cohere/types/chat_stream_event.py +++ b/src/cohere/types/chat_stream_event.py @@ -1,19 +1,28 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel class ChatStreamEvent(UncheckedBaseModel): - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 a1e9031c0..a5416f6c9 100644 --- a/src/cohere/types/chat_stream_request_connectors_search_options.py +++ b/src/cohere/types/chat_stream_request_connectors_search_options.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel @@ -13,7 +13,7 @@ class ChatStreamRequestConnectorsSearchOptions(UncheckedBaseModel): (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=). """ - seed: typing.Optional[int] = pydantic.Field(default=None) + seed: typing.Optional[int] = 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 @@ -22,11 +22,20 @@ class ChatStreamRequestConnectorsSearchOptions(UncheckedBaseModel): Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 314796d68..edd4ee509 100644 --- a/src/cohere/types/chat_stream_start_event.py +++ b/src/cohere/types/chat_stream_start_event.py @@ -1,24 +1,35 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .chat_stream_event import ChatStreamEvent class ChatStreamStartEvent(ChatStreamEvent): - generation_id: str = pydantic.Field() + generation_id: str = pydantic_v1.Field() """ Unique identifier for the generated reply. Useful for submitting feedback. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + allow_population_by_field_name = True + populate_by_name = True + 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 f1e40b61a..9270913d1 100644 --- a/src/cohere/types/chat_text_generation_event.py +++ b/src/cohere/types/chat_text_generation_event.py @@ -1,24 +1,35 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .chat_stream_event import ChatStreamEvent class ChatTextGenerationEvent(ChatStreamEvent): - text: str = pydantic.Field() + text: str = pydantic_v1.Field() """ The next batch of text generated by the model. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + allow_population_by_field_name = True + populate_by_name = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/chat_tool_calls_chunk_event.py b/src/cohere/types/chat_tool_calls_chunk_event.py index a0af91a9d..9846b66de 100644 --- a/src/cohere/types/chat_tool_calls_chunk_event.py +++ b/src/cohere/types/chat_tool_calls_chunk_event.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .chat_stream_event import ChatStreamEvent from .tool_call_delta import ToolCallDelta @@ -12,11 +12,22 @@ class ChatToolCallsChunkEvent(ChatStreamEvent): tool_call_delta: ToolCallDelta - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + allow_population_by_field_name = True + populate_by_name = True + 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 8011a1691..efec658f3 100644 --- a/src/cohere/types/chat_tool_calls_generation_event.py +++ b/src/cohere/types/chat_tool_calls_generation_event.py @@ -1,27 +1,38 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .chat_stream_event import ChatStreamEvent from .tool_call import ToolCall class ChatToolCallsGenerationEvent(ChatStreamEvent): - text: typing.Optional[str] = pydantic.Field(default=None) + text: typing.Optional[str] = pydantic_v1.Field(default=None) """ The text generated related to the tool calls generated """ tool_calls: typing.List[ToolCall] - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: - - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) + + class Config: + frozen = True + smart_union = True + allow_population_by_field_name = True + populate_by_name = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/check_api_key_response.py b/src/cohere/types/check_api_key_response.py index db51c9c36..32baf478f 100644 --- a/src/cohere/types/check_api_key_response.py +++ b/src/cohere/types/check_api_key_response.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel @@ -13,11 +13,20 @@ class CheckApiKeyResponse(UncheckedBaseModel): organization_id: typing.Optional[str] = None owner_id: typing.Optional[str] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 c2ea4784b..e3018baf8 100644 --- a/src/cohere/types/classify_data_metrics.py +++ b/src/cohere/types/classify_data_metrics.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .label_metric import LabelMetric @@ -12,11 +12,20 @@ class ClassifyDataMetrics(UncheckedBaseModel): label_metrics: typing.Optional[typing.List[LabelMetric]] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 c83906c25..5ba22a5c1 100644 --- a/src/cohere/types/classify_example.py +++ b/src/cohere/types/classify_example.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel @@ -12,11 +12,20 @@ class ClassifyExample(UncheckedBaseModel): text: typing.Optional[str] = None label: typing.Optional[str] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 fa5f2b889..a01f466ed 100644 --- a/src/cohere/types/classify_response.py +++ b/src/cohere/types/classify_response.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .api_meta import ApiMeta from .classify_response_classifications_item import ClassifyResponseClassificationsItem @@ -15,11 +15,20 @@ class ClassifyResponse(UncheckedBaseModel): classifications: typing.List[ClassifyResponseClassificationsItem] meta: typing.Optional[ApiMeta] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 09c7319be..2c246dace 100644 --- a/src/cohere/types/classify_response_classifications_item.py +++ b/src/cohere/types/classify_response_classifications_item.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .classify_response_classifications_item_classification_type import ( ClassifyResponseClassificationsItemClassificationType, @@ -14,46 +14,55 @@ class ClassifyResponseClassificationsItem(UncheckedBaseModel): 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 """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 55563ad27..b5c4ab9b4 100644 --- a/src/cohere/types/classify_response_classifications_item_labels_value.py +++ b/src/cohere/types/classify_response_classifications_item_labels_value.py @@ -1,21 +1,30 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel class ClassifyResponseClassificationsItemLabelsValue(UncheckedBaseModel): confidence: typing.Optional[float] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/client_closed_request_error_body.py b/src/cohere/types/client_closed_request_error_body.py index 881c2c338..e1bf5580f 100644 --- a/src/cohere/types/client_closed_request_error_body.py +++ b/src/cohere/types/client_closed_request_error_body.py @@ -1,21 +1,30 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel class ClientClosedRequestErrorBody(UncheckedBaseModel): data: typing.Optional[str] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 1f8e0da8f..527ae8de5 100644 --- a/src/cohere/types/connector.py +++ b/src/cohere/types/connector.py @@ -3,9 +3,8 @@ import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .connector_auth_status import ConnectorAuthStatus from .connector_o_auth import ConnectorOAuth @@ -17,78 +16,87 @@ class Connector(UncheckedBaseModel): 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 a46ead44a..16a29ed30 100644 --- a/src/cohere/types/connector_o_auth.py +++ b/src/cohere/types/connector_o_auth.py @@ -1,44 +1,53 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel class ConnectorOAuth(UncheckedBaseModel): - client_id: typing.Optional[str] = pydantic.Field(default=None) + 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 81205dfc2..6c3e67898 100644 --- a/src/cohere/types/create_connector_o_auth.py +++ b/src/cohere/types/create_connector_o_auth.py @@ -1,44 +1,53 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel class CreateConnectorOAuth(UncheckedBaseModel): - client_id: typing.Optional[str] = pydantic.Field(default=None) + 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 45ea4dbfb..e77812680 100644 --- a/src/cohere/types/create_connector_response.py +++ b/src/cohere/types/create_connector_response.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .connector import Connector @@ -12,11 +12,20 @@ class CreateConnectorResponse(UncheckedBaseModel): connector: Connector - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 d99dab33b..e2cc6eb3d 100644 --- a/src/cohere/types/create_connector_service_auth.py +++ b/src/cohere/types/create_connector_service_auth.py @@ -1,26 +1,35 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .auth_token_type import AuthTokenType class CreateConnectorServiceAuth(UncheckedBaseModel): 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 521276dbe..4fe514ccf 100644 --- a/src/cohere/types/create_embed_job_response.py +++ b/src/cohere/types/create_embed_job_response.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .api_meta import ApiMeta @@ -17,11 +17,20 @@ class CreateEmbedJobResponse(UncheckedBaseModel): job_id: str meta: typing.Optional[ApiMeta] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 189b17f25..fe45eb14e 100644 --- a/src/cohere/types/dataset.py +++ b/src/cohere/types/dataset.py @@ -3,9 +3,8 @@ import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .dataset_part import DatasetPart from .dataset_type import DatasetType @@ -13,55 +12,66 @@ class Dataset(UncheckedBaseModel): - id: str = pydantic.Field() + 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 """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + allow_population_by_field_name = True + populate_by_name = True + 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 c43ff19cb..814186bc2 100644 --- a/src/cohere/types/dataset_part.py +++ b/src/cohere/types/dataset_part.py @@ -1,59 +1,68 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel class DatasetPart(UncheckedBaseModel): - id: str = pydantic.Field() + 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 """ - samples: typing.Optional[typing.List[str]] = pydantic.Field(default=None) + samples: typing.Optional[typing.List[str]] = pydantic_v1.Field(default=None) """ The first few rows of the parsed file """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 9174139ef..9d5186ed8 100644 --- a/src/cohere/types/detokenize_response.py +++ b/src/cohere/types/detokenize_response.py @@ -1,27 +1,36 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .api_meta import ApiMeta class DetokenizeResponse(UncheckedBaseModel): - text: str = pydantic.Field() + text: str = pydantic_v1.Field() """ A string representing the list of tokens. """ meta: typing.Optional[ApiMeta] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 a3ca6db94..e038dc451 100644 --- a/src/cohere/types/embed_by_type_response.py +++ b/src/cohere/types/embed_by_type_response.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .api_meta import ApiMeta from .embed_by_type_response_embeddings import EmbedByTypeResponseEmbeddings @@ -12,23 +12,32 @@ class EmbedByTypeResponse(UncheckedBaseModel): 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. """ meta: typing.Optional[ApiMeta] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 55a33c510..36728d4b4 100644 --- a/src/cohere/types/embed_by_type_response_embeddings.py +++ b/src/cohere/types/embed_by_type_response_embeddings.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel @@ -13,36 +13,47 @@ class EmbedByTypeResponseEmbeddings(UncheckedBaseModel): 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[int]]] = pydantic.Field(default=None) + int8: typing.Optional[typing.List[typing.List[int]]] = 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[int]]] = pydantic.Field(default=None) + uint8: typing.Optional[typing.List[typing.List[int]]] = 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[int]]] = pydantic.Field(default=None) + binary: typing.Optional[typing.List[typing.List[int]]] = 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[int]]] = pydantic.Field(default=None) + ubinary: typing.Optional[typing.List[typing.List[int]]] = 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + allow_population_by_field_name = True + populate_by_name = True + 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 f23f0b41a..aa53ad22d 100644 --- a/src/cohere/types/embed_floats_response.py +++ b/src/cohere/types/embed_floats_response.py @@ -1,33 +1,42 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .api_meta import ApiMeta class EmbedFloatsResponse(UncheckedBaseModel): 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. """ meta: typing.Optional[ApiMeta] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 0b7768f4d..bcab9bdd0 100644 --- a/src/cohere/types/embed_job.py +++ b/src/cohere/types/embed_job.py @@ -3,9 +3,8 @@ import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .api_meta import ApiMeta from .embed_job_status import EmbedJobStatus @@ -13,53 +12,62 @@ class EmbedJob(UncheckedBaseModel): - job_id: str = pydantic.Field() + 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 """ meta: typing.Optional[ApiMeta] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 842e5a3dd..cca071d25 100644 --- a/src/cohere/types/embed_response.py +++ b/src/cohere/types/embed_response.py @@ -2,12 +2,13 @@ from __future__ import annotations +import datetime as dt import typing -import pydantic import typing_extensions -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel, UnionMetadata from .api_meta import ApiMeta from .embed_by_type_response_embeddings import EmbedByTypeResponseEmbeddings @@ -20,14 +21,23 @@ class EmbedResponse_EmbeddingsFloats(UncheckedBaseModel): meta: typing.Optional[ApiMeta] = None response_type: typing.Literal["embeddings_floats"] = "embeddings_floats" - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) + + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} class EmbedResponse_EmbeddingsByType(UncheckedBaseModel): @@ -37,14 +47,23 @@ class EmbedResponse_EmbeddingsByType(UncheckedBaseModel): meta: typing.Optional[ApiMeta] = None response_type: typing.Literal["embeddings_by_type"] = "embeddings_by_type" - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} EmbedResponse = typing_extensions.Annotated[ diff --git a/src/cohere/types/finetune_dataset_metrics.py b/src/cohere/types/finetune_dataset_metrics.py index b2b23642f..713a7324f 100644 --- a/src/cohere/types/finetune_dataset_metrics.py +++ b/src/cohere/types/finetune_dataset_metrics.py @@ -1,49 +1,58 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel class FinetuneDatasetMetrics(UncheckedBaseModel): - trainable_token_count: typing.Optional[int] = pydantic.Field(default=None) + trainable_token_count: typing.Optional[int] = pydantic_v1.Field(default=None) """ The number of tokens of valid examples that can be used for training. """ - total_examples: typing.Optional[int] = pydantic.Field(default=None) + total_examples: typing.Optional[int] = pydantic_v1.Field(default=None) """ The overall number of examples. """ - train_examples: typing.Optional[int] = pydantic.Field(default=None) + train_examples: typing.Optional[int] = pydantic_v1.Field(default=None) """ The number of training examples. """ - train_size_bytes: typing.Optional[int] = pydantic.Field(default=None) + train_size_bytes: typing.Optional[int] = pydantic_v1.Field(default=None) """ The size in bytes of all training examples. """ - eval_examples: typing.Optional[int] = pydantic.Field(default=None) + eval_examples: typing.Optional[int] = pydantic_v1.Field(default=None) """ Number of evaluation examples. """ - eval_size_bytes: typing.Optional[int] = pydantic.Field(default=None) + eval_size_bytes: typing.Optional[int] = pydantic_v1.Field(default=None) """ The size in bytes of all eval examples. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/gateway_timeout_error_body.py b/src/cohere/types/gateway_timeout_error_body.py index 22921624e..dd8de6bff 100644 --- a/src/cohere/types/gateway_timeout_error_body.py +++ b/src/cohere/types/gateway_timeout_error_body.py @@ -1,21 +1,30 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel class GatewayTimeoutErrorBody(UncheckedBaseModel): data: typing.Optional[str] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 4f26047da..f302c6ddf 100644 --- a/src/cohere/types/generate_stream_end.py +++ b/src/cohere/types/generate_stream_end.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .finish_reason import FinishReason from .generate_stream_end_response import GenerateStreamEndResponse from .generate_stream_event import GenerateStreamEvent @@ -15,11 +15,22 @@ class GenerateStreamEnd(GenerateStreamEvent): finish_reason: typing.Optional[FinishReason] = None response: GenerateStreamEndResponse - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + allow_population_by_field_name = True + populate_by_name = True + 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 321465579..0d1c4891f 100644 --- a/src/cohere/types/generate_stream_end_response.py +++ b/src/cohere/types/generate_stream_end_response.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .single_generation_in_stream import SingleGenerationInStream @@ -14,11 +14,20 @@ class GenerateStreamEndResponse(UncheckedBaseModel): prompt: typing.Optional[str] = None generations: typing.Optional[typing.List[SingleGenerationInStream]] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 b2e9a7c76..3053a7596 100644 --- a/src/cohere/types/generate_stream_error.py +++ b/src/cohere/types/generate_stream_error.py @@ -1,32 +1,43 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .finish_reason import FinishReason from .generate_stream_event import GenerateStreamEvent 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 """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: - - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) + + class Config: + frozen = True + smart_union = True + allow_population_by_field_name = True + populate_by_name = True + 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 bb4394329..588510be7 100644 --- a/src/cohere/types/generate_stream_event.py +++ b/src/cohere/types/generate_stream_event.py @@ -1,19 +1,28 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel class GenerateStreamEvent(UncheckedBaseModel): - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 7234ba49c..05981550a 100644 --- a/src/cohere/types/generate_stream_text.py +++ b/src/cohere/types/generate_stream_text.py @@ -1,31 +1,42 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from .generate_stream_event import GenerateStreamEvent 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. """ is_finished: bool - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: - - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) + + class Config: + frozen = True + smart_union = True + allow_population_by_field_name = True + populate_by_name = True + 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 795903111..0f1264538 100644 --- a/src/cohere/types/generate_streamed_response.py +++ b/src/cohere/types/generate_streamed_response.py @@ -2,12 +2,13 @@ from __future__ import annotations +import datetime as dt import typing -import pydantic import typing_extensions -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel, UnionMetadata from .finish_reason import FinishReason from .generate_stream_end_response import GenerateStreamEndResponse @@ -23,14 +24,23 @@ class GenerateStreamedResponse_TextGeneration(UncheckedBaseModel): is_finished: bool event_type: typing.Literal["text-generation"] = "text-generation" - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) + + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} class GenerateStreamedResponse_StreamEnd(UncheckedBaseModel): @@ -43,14 +53,23 @@ class GenerateStreamedResponse_StreamEnd(UncheckedBaseModel): response: GenerateStreamEndResponse event_type: typing.Literal["stream-end"] = "stream-end" - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) + + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} class GenerateStreamedResponse_StreamError(UncheckedBaseModel): @@ -64,14 +83,23 @@ class GenerateStreamedResponse_StreamError(UncheckedBaseModel): err: str event_type: typing.Literal["stream-error"] = "stream-error" - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} GenerateStreamedResponse = typing_extensions.Annotated[ diff --git a/src/cohere/types/generation.py b/src/cohere/types/generation.py index 8f29e052d..01158d4d9 100644 --- a/src/cohere/types/generation.py +++ b/src/cohere/types/generation.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .api_meta import ApiMeta from .single_generation import SingleGeneration @@ -12,23 +12,32 @@ class Generation(UncheckedBaseModel): 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 """ meta: typing.Optional[ApiMeta] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 d09580154..153baac7e 100644 --- a/src/cohere/types/get_connector_response.py +++ b/src/cohere/types/get_connector_response.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .connector import Connector @@ -12,11 +12,20 @@ class GetConnectorResponse(UncheckedBaseModel): connector: Connector - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 b254a7052..6ac3daa39 100644 --- a/src/cohere/types/get_model_response.py +++ b/src/cohere/types/get_model_response.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .compatible_endpoint import CompatibleEndpoint @@ -14,41 +14,50 @@ class GetModelResponse(UncheckedBaseModel): 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_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. """ - default_endpoints: typing.Optional[typing.List[CompatibleEndpoint]] = pydantic.Field(default=None) + default_endpoints: typing.Optional[typing.List[CompatibleEndpoint]] = pydantic_v1.Field(default=None) """ The API endpoints that the model is default to. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/json_response_format.py b/src/cohere/types/json_response_format.py index eb5da691d..6e41d29f3 100644 --- a/src/cohere/types/json_response_format.py +++ b/src/cohere/types/json_response_format.py @@ -1,15 +1,15 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel class JsonResponseFormat(UncheckedBaseModel): - schema_: typing.Optional[typing.Dict[str, typing.Any]] = pydantic.Field(alias="schema", default=None) + schema_: typing.Optional[typing.Dict[str, typing.Any]] = pydantic_v1.Field(alias="schema", default=None) """ [BETA] A JSON schema object that the output will adhere to. There are some restrictions we have on the schema, refer to [our guide](/docs/structured-outputs-json#schema-constraints) for more information. Example (required name and age object): @@ -28,11 +28,22 @@ class JsonResponseFormat(UncheckedBaseModel): **Note**: This field must not be specified when the `type` is set to `"text"`. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + allow_population_by_field_name = True + populate_by_name = True + 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 5eb63d8d4..ac57efdbd 100644 --- a/src/cohere/types/label_metric.py +++ b/src/cohere/types/label_metric.py @@ -1,34 +1,43 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel class LabelMetric(UncheckedBaseModel): - total_examples: typing.Optional[int] = pydantic.Field(default=None) + total_examples: typing.Optional[int] = pydantic_v1.Field(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 """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 c581707a9..a7e8dfe91 100644 --- a/src/cohere/types/list_connectors_response.py +++ b/src/cohere/types/list_connectors_response.py @@ -1,26 +1,35 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .connector import Connector class ListConnectorsResponse(UncheckedBaseModel): 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 b70091761..eb5bca112 100644 --- a/src/cohere/types/list_embed_job_response.py +++ b/src/cohere/types/list_embed_job_response.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .embed_job import EmbedJob @@ -12,11 +12,20 @@ class ListEmbedJobResponse(UncheckedBaseModel): embed_jobs: typing.Optional[typing.List[EmbedJob]] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 911145079..eea1a1481 100644 --- a/src/cohere/types/list_models_response.py +++ b/src/cohere/types/list_models_response.py @@ -1,26 +1,35 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .get_model_response import GetModelResponse class ListModelsResponse(UncheckedBaseModel): 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/message.py b/src/cohere/types/message.py index 6b9309d14..429e96e43 100644 --- a/src/cohere/types/message.py +++ b/src/cohere/types/message.py @@ -2,12 +2,13 @@ from __future__ import annotations +import datetime as dt import typing -import pydantic import typing_extensions -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel, UnionMetadata from .tool_call import ToolCall from .tool_result import ToolResult @@ -18,14 +19,23 @@ class Message_Chatbot(UncheckedBaseModel): tool_calls: typing.Optional[typing.List[ToolCall]] = None role: typing.Literal["CHATBOT"] = "CHATBOT" - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) + + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} class Message_System(UncheckedBaseModel): @@ -33,14 +43,23 @@ class Message_System(UncheckedBaseModel): tool_calls: typing.Optional[typing.List[ToolCall]] = None role: typing.Literal["SYSTEM"] = "SYSTEM" - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} class Message_User(UncheckedBaseModel): @@ -48,28 +67,46 @@ class Message_User(UncheckedBaseModel): tool_calls: typing.Optional[typing.List[ToolCall]] = None role: typing.Literal["USER"] = "USER" - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) + + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} class Message_Tool(UncheckedBaseModel): tool_results: typing.Optional[typing.List[ToolResult]] = None role: typing.Literal["TOOL"] = "TOOL" - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} Message = typing_extensions.Annotated[ diff --git a/src/cohere/types/metrics.py b/src/cohere/types/metrics.py index 57c439a8b..a41684d3f 100644 --- a/src/cohere/types/metrics.py +++ b/src/cohere/types/metrics.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .finetune_dataset_metrics import FinetuneDatasetMetrics from .metrics_embed_data import MetricsEmbedData @@ -14,11 +14,20 @@ class Metrics(UncheckedBaseModel): finetune_dataset_metrics: typing.Optional[FinetuneDatasetMetrics] = None embed_data: typing.Optional[MetricsEmbedData] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/metrics_embed_data.py b/src/cohere/types/metrics_embed_data.py index b37d46340..353926f58 100644 --- a/src/cohere/types/metrics_embed_data.py +++ b/src/cohere/types/metrics_embed_data.py @@ -1,25 +1,34 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .metrics_embed_data_fields_item import MetricsEmbedDataFieldsItem class MetricsEmbedData(UncheckedBaseModel): - fields: typing.Optional[typing.List[MetricsEmbedDataFieldsItem]] = pydantic.Field(default=None) + fields: typing.Optional[typing.List[MetricsEmbedDataFieldsItem]] = pydantic_v1.Field(default=None) """ the fields in the dataset """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/metrics_embed_data_fields_item.py b/src/cohere/types/metrics_embed_data_fields_item.py index a2af69e46..c41002d51 100644 --- a/src/cohere/types/metrics_embed_data_fields_item.py +++ b/src/cohere/types/metrics_embed_data_fields_item.py @@ -1,29 +1,38 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel class MetricsEmbedDataFieldsItem(UncheckedBaseModel): - name: typing.Optional[str] = pydantic.Field(default=None) + name: typing.Optional[str] = pydantic_v1.Field(default=None) """ the name of the field """ - count: typing.Optional[float] = pydantic.Field(default=None) + count: typing.Optional[float] = pydantic_v1.Field(default=None) """ the number of times the field appears in the dataset """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 6dac3cf71..fb602b4aa 100644 --- a/src/cohere/types/non_streamed_chat_response.py +++ b/src/cohere/types/non_streamed_chat_response.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .api_meta import ApiMeta from .chat_citation import ChatCitation @@ -17,60 +17,69 @@ class NonStreamedChatResponse(UncheckedBaseModel): - text: str = pydantic.Field() + 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[Message]] = pydantic.Field(default=None) + chat_history: typing.Optional[typing.List[Message]] = 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`. """ - prompt: typing.Optional[str] = pydantic.Field(default=None) + prompt: typing.Optional[str] = pydantic_v1.Field(default=None) """ The prompt that was used. Only present when `return_prompt` in the request is set to true. """ meta: typing.Optional[ApiMeta] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/not_implemented_error_body.py b/src/cohere/types/not_implemented_error_body.py index e5bfc4fa7..4a6834dcf 100644 --- a/src/cohere/types/not_implemented_error_body.py +++ b/src/cohere/types/not_implemented_error_body.py @@ -1,21 +1,30 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel class NotImplementedErrorBody(UncheckedBaseModel): data: typing.Optional[str] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 66d132aee..1d2971fa1 100644 --- a/src/cohere/types/o_auth_authorize_response.py +++ b/src/cohere/types/o_auth_authorize_response.py @@ -1,24 +1,33 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel class OAuthAuthorizeResponse(UncheckedBaseModel): - redirect_url: typing.Optional[str] = pydantic.Field(default=None) + 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 336536ae1..33ed467ca 100644 --- a/src/cohere/types/parse_info.py +++ b/src/cohere/types/parse_info.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel @@ -12,11 +12,20 @@ class ParseInfo(UncheckedBaseModel): separator: typing.Optional[str] = None delimiter: typing.Optional[str] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 9cfb3c8da..3708d530e 100644 --- a/src/cohere/types/rerank_response.py +++ b/src/cohere/types/rerank_response.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .api_meta import ApiMeta from .rerank_response_results_item import RerankResponseResultsItem @@ -12,18 +12,27 @@ class RerankResponse(UncheckedBaseModel): id: typing.Optional[str] = None - results: typing.List[RerankResponseResultsItem] = pydantic.Field() + results: typing.List[RerankResponseResultsItem] = pydantic_v1.Field() """ An ordered list of ranked documents """ meta: typing.Optional[ApiMeta] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 41ab256a2..d8c686f2d 100644 --- a/src/cohere/types/rerank_response_results_item.py +++ b/src/cohere/types/rerank_response_results_item.py @@ -1,35 +1,44 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .rerank_response_results_item_document import RerankResponseResultsItemDocument class RerankResponseResultsItem(UncheckedBaseModel): - document: typing.Optional[RerankResponseResultsItemDocument] = pydantic.Field(default=None) + document: typing.Optional[RerankResponseResultsItemDocument] = pydantic_v1.Field(default=None) """ If `return_documents` is set as `false` this will return none, if `true` it will return the documents passed in """ - index: int = pydantic.Field() + index: int = pydantic_v1.Field() """ Corresponds to the index in the original list of documents to which the ranked document belongs. (i.e. if the first value in the `results` object has an `index` value of 3, it means in the list of documents passed in, the document at `index=3` had the highest relevance) """ - relevance_score: float = pydantic.Field() + relevance_score: float = pydantic_v1.Field() """ Relevance scores are normalized to be in the range `[0, 1]`. Scores close to `1` indicate a high relevance to the query, and scores closer to `0` indicate low relevance. It is not accurate to assume a score of 0.9 means the document is 2x more relevant than a document with a score of 0.45 """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 d28dafc44..c4bc398d7 100644 --- a/src/cohere/types/rerank_response_results_item_document.py +++ b/src/cohere/types/rerank_response_results_item_document.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel @@ -13,16 +13,25 @@ class RerankResponseResultsItemDocument(UncheckedBaseModel): If `return_documents` is set as `false` this will return none, if `true` it will return the documents passed in """ - text: str = pydantic.Field() + text: str = pydantic_v1.Field() """ The text of the document to rerank """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 5237ddfc6..7f69ca877 100644 --- a/src/cohere/types/reranker_data_metrics.py +++ b/src/cohere/types/reranker_data_metrics.py @@ -1,49 +1,58 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel class RerankerDataMetrics(UncheckedBaseModel): - num_train_queries: typing.Optional[int] = pydantic.Field(default=None) + num_train_queries: typing.Optional[int] = pydantic_v1.Field(default=None) """ The number of training queries. """ - num_train_relevant_passages: typing.Optional[int] = pydantic.Field(default=None) + num_train_relevant_passages: typing.Optional[int] = pydantic_v1.Field(default=None) """ The sum of all relevant passages of valid training examples. """ - num_train_hard_negatives: typing.Optional[int] = pydantic.Field(default=None) + num_train_hard_negatives: typing.Optional[int] = pydantic_v1.Field(default=None) """ The sum of all hard negatives of valid training examples. """ - num_eval_queries: typing.Optional[int] = pydantic.Field(default=None) + num_eval_queries: typing.Optional[int] = pydantic_v1.Field(default=None) """ The number of evaluation queries. """ - num_eval_relevant_passages: typing.Optional[int] = pydantic.Field(default=None) + num_eval_relevant_passages: typing.Optional[int] = pydantic_v1.Field(default=None) """ The sum of all relevant passages of valid eval examples. """ - num_eval_hard_negatives: typing.Optional[int] = pydantic.Field(default=None) + num_eval_hard_negatives: typing.Optional[int] = pydantic_v1.Field(default=None) """ The sum of all hard negatives of valid eval examples. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/response_format.py b/src/cohere/types/response_format.py index 3b1b75d7e..f97e95bae 100644 --- a/src/cohere/types/response_format.py +++ b/src/cohere/types/response_format.py @@ -2,12 +2,13 @@ from __future__ import annotations +import datetime as dt import typing -import pydantic import typing_extensions -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel, UnionMetadata @@ -25,14 +26,23 @@ class ResponseFormat_Text(UncheckedBaseModel): type: typing.Literal["text"] = "text" - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) + + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} class ResponseFormat_JsonObject(UncheckedBaseModel): @@ -47,17 +57,28 @@ class ResponseFormat_JsonObject(UncheckedBaseModel): **Limitation**: The parameter is not supported in RAG mode (when any of `connectors`, `documents`, `tools`, `tool_results` are provided). """ - schema_: typing.Optional[typing.Dict[str, typing.Any]] = pydantic.Field(alias="schema", default=None) + schema_: typing.Optional[typing.Dict[str, typing.Any]] = pydantic_v1.Field(alias="schema", default=None) type: typing.Literal["json_object"] = "json_object" - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: - - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) + + class Config: + frozen = True + smart_union = True + allow_population_by_field_name = True + populate_by_name = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} ResponseFormat = typing_extensions.Annotated[ diff --git a/src/cohere/types/single_generation.py b/src/cohere/types/single_generation.py index 0f8019b2a..c54707edf 100644 --- a/src/cohere/types/single_generation.py +++ b/src/cohere/types/single_generation.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .single_generation_token_likelihoods_item import SingleGenerationTokenLikelihoodsItem @@ -12,22 +12,33 @@ class SingleGeneration(UncheckedBaseModel): 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 6f9b8ef28..712c7f7ac 100644 --- a/src/cohere/types/single_generation_in_stream.py +++ b/src/cohere/types/single_generation_in_stream.py @@ -1,33 +1,42 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .finish_reason import FinishReason class SingleGenerationInStream(UncheckedBaseModel): 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. """ finish_reason: FinishReason - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 16259f649..3e675a1cb 100644 --- a/src/cohere/types/single_generation_token_likelihoods_item.py +++ b/src/cohere/types/single_generation_token_likelihoods_item.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel @@ -12,11 +12,20 @@ class SingleGenerationTokenLikelihoodsItem(UncheckedBaseModel): token: str likelihood: float - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 bf4d78c89..33ecb1763 100644 --- a/src/cohere/types/streamed_chat_response.py +++ b/src/cohere/types/streamed_chat_response.py @@ -2,12 +2,13 @@ from __future__ import annotations +import datetime as dt import typing -import pydantic import typing_extensions -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel, UnionMetadata from .chat_citation import ChatCitation from .chat_document import ChatDocument @@ -27,14 +28,23 @@ class StreamedChatResponse_StreamStart(UncheckedBaseModel): generation_id: str event_type: typing.Literal["stream-start"] = "stream-start" - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) + + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} class StreamedChatResponse_SearchQueriesGeneration(UncheckedBaseModel): @@ -45,14 +55,23 @@ class StreamedChatResponse_SearchQueriesGeneration(UncheckedBaseModel): search_queries: typing.List[ChatSearchQuery] event_type: typing.Literal["search-queries-generation"] = "search-queries-generation" - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} class StreamedChatResponse_SearchResults(UncheckedBaseModel): @@ -64,14 +83,23 @@ class StreamedChatResponse_SearchResults(UncheckedBaseModel): documents: typing.Optional[typing.List[ChatDocument]] = None event_type: typing.Literal["search-results"] = "search-results" - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) + + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} class StreamedChatResponse_TextGeneration(UncheckedBaseModel): @@ -82,14 +110,23 @@ class StreamedChatResponse_TextGeneration(UncheckedBaseModel): text: str event_type: typing.Literal["text-generation"] = "text-generation" - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} class StreamedChatResponse_CitationGeneration(UncheckedBaseModel): @@ -100,14 +137,23 @@ class StreamedChatResponse_CitationGeneration(UncheckedBaseModel): citations: typing.List[ChatCitation] event_type: typing.Literal["citation-generation"] = "citation-generation" - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) + + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} class StreamedChatResponse_ToolCallsGeneration(UncheckedBaseModel): @@ -119,14 +165,23 @@ class StreamedChatResponse_ToolCallsGeneration(UncheckedBaseModel): tool_calls: typing.List[ToolCall] event_type: typing.Literal["tool-calls-generation"] = "tool-calls-generation" - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} class StreamedChatResponse_StreamEnd(UncheckedBaseModel): @@ -138,14 +193,23 @@ class StreamedChatResponse_StreamEnd(UncheckedBaseModel): response: NonStreamedChatResponse event_type: typing.Literal["stream-end"] = "stream-end" - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) + + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} class StreamedChatResponse_ToolCallsChunk(UncheckedBaseModel): @@ -156,14 +220,23 @@ class StreamedChatResponse_ToolCallsChunk(UncheckedBaseModel): tool_call_delta: ToolCallDelta event_type: typing.Literal["tool-calls-chunk"] = "tool-calls-chunk" - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} StreamedChatResponse = typing_extensions.Annotated[ diff --git a/src/cohere/types/summarize_response.py b/src/cohere/types/summarize_response.py index 52ad61808..3dab355b7 100644 --- a/src/cohere/types/summarize_response.py +++ b/src/cohere/types/summarize_response.py @@ -1,32 +1,41 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .api_meta import ApiMeta class SummarizeResponse(UncheckedBaseModel): - id: typing.Optional[str] = pydantic.Field(default=None) + 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 """ meta: typing.Optional[ApiMeta] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/text_response_format.py b/src/cohere/types/text_response_format.py index e34935b5d..31351515b 100644 --- a/src/cohere/types/text_response_format.py +++ b/src/cohere/types/text_response_format.py @@ -1,19 +1,28 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel class TextResponseFormat(UncheckedBaseModel): - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 d1d128829..11345928b 100644 --- a/src/cohere/types/tokenize_response.py +++ b/src/cohere/types/tokenize_response.py @@ -1,16 +1,16 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .api_meta import ApiMeta class TokenizeResponse(UncheckedBaseModel): - tokens: typing.List[int] = pydantic.Field() + tokens: typing.List[int] = pydantic_v1.Field() """ An array of tokens, where each token is an integer. """ @@ -18,11 +18,20 @@ class TokenizeResponse(UncheckedBaseModel): token_strings: typing.List[str] meta: typing.Optional[ApiMeta] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/too_many_requests_error_body.py b/src/cohere/types/too_many_requests_error_body.py index 56ecef2df..dc3fb65c7 100644 --- a/src/cohere/types/too_many_requests_error_body.py +++ b/src/cohere/types/too_many_requests_error_body.py @@ -1,21 +1,30 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel class TooManyRequestsErrorBody(UncheckedBaseModel): data: typing.Optional[str] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 0aa5c896a..fa8b5a686 100644 --- a/src/cohere/types/tool.py +++ b/src/cohere/types/tool.py @@ -1,26 +1,26 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .tool_parameter_definitions_value import ToolParameterDefinitionsValue class Tool(UncheckedBaseModel): - name: str = pydantic.Field() + 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 ) """ @@ -37,11 +37,20 @@ class Tool(UncheckedBaseModel): ``` """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 f51797b87..c02117246 100644 --- a/src/cohere/types/tool_call.py +++ b/src/cohere/types/tool_call.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel @@ -13,21 +13,30 @@ class ToolCall(UncheckedBaseModel): 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/tool_call_delta.py b/src/cohere/types/tool_call_delta.py index dd04b0c0c..7c56613c3 100644 --- a/src/cohere/types/tool_call_delta.py +++ b/src/cohere/types/tool_call_delta.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel @@ -13,31 +13,40 @@ class ToolCallDelta(UncheckedBaseModel): Contains the chunk of the tool call generation in the stream. """ - name: typing.Optional[str] = pydantic.Field(default=None) + name: typing.Optional[str] = pydantic_v1.Field(default=None) """ Name of the tool call """ - index: typing.Optional[float] = pydantic.Field(default=None) + index: typing.Optional[float] = pydantic_v1.Field(default=None) """ Index of the tool call generated """ - parameters: typing.Optional[str] = pydantic.Field(default=None) + parameters: typing.Optional[str] = pydantic_v1.Field(default=None) """ Chunk of the tool parameters """ - text: typing.Optional[str] = pydantic.Field(default=None) + text: typing.Optional[str] = pydantic_v1.Field(default=None) """ Chunk of the tool plan text """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/tool_message.py b/src/cohere/types/tool_message.py index 3516ae49a..875f93626 100644 --- a/src/cohere/types/tool_message.py +++ b/src/cohere/types/tool_message.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .tool_result import ToolResult @@ -16,11 +16,20 @@ class ToolMessage(UncheckedBaseModel): tool_results: typing.Optional[typing.List[ToolResult]] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 448e6a296..b7e622dd2 100644 --- a/src/cohere/types/tool_parameter_definitions_value.py +++ b/src/cohere/types/tool_parameter_definitions_value.py @@ -1,34 +1,43 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel class ToolParameterDefinitionsValue(UncheckedBaseModel): - description: typing.Optional[str] = pydantic.Field(default=None) + 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. """ - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/tool_result.py b/src/cohere/types/tool_result.py index 602a2283d..700d95e38 100644 --- a/src/cohere/types/tool_result.py +++ b/src/cohere/types/tool_result.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .tool_call import ToolCall @@ -13,11 +13,20 @@ class ToolResult(UncheckedBaseModel): call: ToolCall outputs: typing.List[typing.Dict[str, typing.Any]] - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/cohere/types/unprocessable_entity_error_body.py b/src/cohere/types/unprocessable_entity_error_body.py index 422a8c916..296c0c4f7 100644 --- a/src/cohere/types/unprocessable_entity_error_body.py +++ b/src/cohere/types/unprocessable_entity_error_body.py @@ -1,21 +1,30 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel class UnprocessableEntityErrorBody(UncheckedBaseModel): data: typing.Optional[str] = None - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + 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 35741136a..d0ed1f9d1 100644 --- a/src/cohere/types/update_connector_response.py +++ b/src/cohere/types/update_connector_response.py @@ -1,10 +1,10 @@ # This file was auto-generated by Fern from our API Definition. +import datetime as dt import typing -import pydantic - -from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.datetime_utils import serialize_datetime +from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1 from ..core.unchecked_base_model import UncheckedBaseModel from .connector import Connector @@ -12,11 +12,20 @@ class UpdateConnectorResponse(UncheckedBaseModel): connector: Connector - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: + 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) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs} + + return deep_union_pydantic_dicts( + super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none) + ) - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow + class Config: + frozen = True + smart_union = True + extra = pydantic_v1.Extra.allow + json_encoders = {dt.datetime: serialize_datetime}