From 775da0ec15792198a97e919ad159d38b11a194ec Mon Sep 17 00:00:00 2001 From: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Date: Thu, 19 Sep 2024 15:49:50 +0000 Subject: [PATCH] SDK regeneration --- reference.md | 90 ++--------- src/cohere/__init__.py | 20 +-- src/cohere/base_client.py | 142 +++-------------- src/cohere/finetuning/__init__.py | 2 + src/cohere/finetuning/finetuning/__init__.py | 2 + .../finetuning/finetuning/types/__init__.py | 2 + .../finetuning/finetuning/types/base_model.py | 2 +- .../finetuning/types/hyperparameters.py | 18 +++ .../finetuning/types/lora_target_modules.py | 13 ++ src/cohere/types/__init__.py | 32 ++-- src/cohere/types/embed_request_truncate.py | 5 - src/cohere/types/embed_request_v2.py | 144 +++++++----------- src/cohere/types/embed_request_v2truncate.py | 5 + src/cohere/types/images.py | 50 ------ src/cohere/types/texts.py | 62 -------- src/cohere/types/texts_truncate.py | 5 - src/cohere/v2/client.py | 14 +- 17 files changed, 145 insertions(+), 463 deletions(-) create mode 100644 src/cohere/finetuning/finetuning/types/lora_target_modules.py delete mode 100644 src/cohere/types/embed_request_truncate.py create mode 100644 src/cohere/types/embed_request_v2truncate.py delete mode 100644 src/cohere/types/images.py delete mode 100644 src/cohere/types/texts.py delete mode 100644 src/cohere/types/texts_truncate.py diff --git a/reference.md b/reference.md index c91398c36..4500e8a94 100644 --- a/reference.md +++ b/reference.md @@ -1603,13 +1603,17 @@ If you want to learn more how to use the embedding model, have a look at the [Se
```python -from cohere import Client +from cohere import Client, EmbedRequestV2 client = Client( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) -client.embed() +client.embed( + request=EmbedRequestV2( + model="model", + ), +) ```
@@ -1625,80 +1629,7 @@ client.embed()
-**texts:** `typing.Optional[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. - -
-
- -
-
- -**images:** `typing.Optional[typing.Sequence[str]]` - -An array of image data URIs for the model to embed. Maximum number of images per call is `1`. - -The image must be a valid [data URI](https://developer.mozilla.org/en-US/docs/Web/URI/Schemes/data). The image must be in either `image/jpeg` or `image/png` format and has a maximum size of 5MB. - -
-
- -
-
- -**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:** `EmbedRequestV2`
@@ -2858,16 +2789,15 @@ If you want to learn more how to use the embedding model, have a look at the [Se
```python -from cohere import Client, ImageEmbedRequestV2 +from cohere import Client, EmbedRequestV2 client = Client( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) client.v2.embed( - request=ImageEmbedRequestV2( - images=["string"], - model="string", + request=EmbedRequestV2( + model="model", ), ) diff --git a/src/cohere/__init__.py b/src/cohere/__init__.py index dd374d7d6..197c1863f 100644 --- a/src/cohere/__init__.py +++ b/src/cohere/__init__.py @@ -80,7 +80,6 @@ CitationStartEventDelta, CitationStartEventDeltaMessage, CitationStartStreamedChatResponseV2, - ClassificationEmbedRequestV2, ClassifyDataMetrics, ClassifyExample, ClassifyRequestTruncate, @@ -89,7 +88,6 @@ ClassifyResponseClassificationsItemClassificationType, ClassifyResponseClassificationsItemLabelsValue, ClientClosedRequestErrorBody, - ClusteringEmbedRequestV2, CompatibleEndpoint, Connector, ConnectorAuthStatus, @@ -119,8 +117,8 @@ EmbedJob, EmbedJobStatus, EmbedJobTruncate, - EmbedRequestTruncate, EmbedRequestV2, + EmbedRequestV2Truncate, EmbedResponse, EmbeddingType, EmbeddingsByTypeEmbedResponse, @@ -141,8 +139,6 @@ Generation, GetConnectorResponse, GetModelResponse, - ImageEmbedRequestV2, - Images, JsonObjectResponseFormat, JsonObjectResponseFormatV2, JsonResponseFormat, @@ -169,9 +165,7 @@ RerankerDataMetrics, ResponseFormat, ResponseFormatV2, - SearchDocumentEmbedRequestV2, SearchQueriesGenerationStreamedChatResponse, - SearchQueryEmbedRequestV2, SearchResultsStreamedChatResponse, SingleGeneration, SingleGenerationInStream, @@ -200,8 +194,6 @@ TextResponseFormatV2, TextSystemMessageContentItem, TextToolContent, - Texts, - TextsTruncate, TokenizeResponse, TooManyRequestsErrorBody, Tool, @@ -359,7 +351,6 @@ "CitationStartEventDelta", "CitationStartEventDeltaMessage", "CitationStartStreamedChatResponseV2", - "ClassificationEmbedRequestV2", "ClassifyDataMetrics", "ClassifyExample", "ClassifyRequestTruncate", @@ -372,7 +363,6 @@ "ClientClosedRequestErrorBody", "ClientEnvironment", "ClientV2", - "ClusteringEmbedRequestV2", "CompatibleEndpoint", "Connector", "ConnectorAuthStatus", @@ -408,8 +398,8 @@ "EmbedJob", "EmbedJobStatus", "EmbedJobTruncate", - "EmbedRequestTruncate", "EmbedRequestV2", + "EmbedRequestV2Truncate", "EmbedResponse", "EmbeddingType", "EmbeddingsByTypeEmbedResponse", @@ -432,8 +422,6 @@ "Generation", "GetConnectorResponse", "GetModelResponse", - "ImageEmbedRequestV2", - "Images", "InternalServerError", "JsonObjectResponseFormat", "JsonObjectResponseFormatV2", @@ -464,9 +452,7 @@ "ResponseFormat", "ResponseFormatV2", "SagemakerClient", - "SearchDocumentEmbedRequestV2", "SearchQueriesGenerationStreamedChatResponse", - "SearchQueryEmbedRequestV2", "SearchResultsStreamedChatResponse", "ServiceUnavailableError", "SingleGeneration", @@ -496,8 +482,6 @@ "TextResponseFormatV2", "TextSystemMessageContentItem", "TextToolContent", - "Texts", - "TextsTruncate", "TokenizeResponse", "TooManyRequestsError", "TooManyRequestsErrorBody", diff --git a/src/cohere/base_client.py b/src/cohere/base_client.py index 24039b71c..3eae8f065 100644 --- a/src/cohere/base_client.py +++ b/src/cohere/base_client.py @@ -53,9 +53,7 @@ from .types.generate_request_truncate import GenerateRequestTruncate from .types.generate_request_return_likelihoods import GenerateRequestReturnLikelihoods from .types.generation import Generation -from .types.embed_input_type import EmbedInputType -from .types.embedding_type import EmbeddingType -from .types.embed_request_truncate import EmbedRequestTruncate +from .types.embed_request_v2 import EmbedRequestV2 from .types.embed_response import EmbedResponse from .types.rerank_request_documents_item import RerankRequestDocumentsItem from .types.rerank_response import RerankResponse @@ -1766,15 +1764,7 @@ def generate( raise ApiError(status_code=_response.status_code, body=_response_json) def embed( - self, - *, - texts: typing.Optional[typing.Sequence[str]] = OMIT, - images: typing.Optional[typing.Sequence[str]] = OMIT, - model: typing.Optional[str] = OMIT, - input_type: typing.Optional[EmbedInputType] = OMIT, - embedding_types: typing.Optional[typing.Sequence[EmbeddingType]] = OMIT, - truncate: typing.Optional[EmbedRequestTruncate] = OMIT, - request_options: typing.Optional[RequestOptions] = None, + self, *, request: EmbedRequestV2, request_options: typing.Optional[RequestOptions] = None ) -> EmbedResponse: """ This endpoint returns text embeddings. An embedding is a list of floating point numbers that captures semantic information about the text that it represents. @@ -1785,47 +1775,7 @@ def embed( Parameters ---------- - texts : typing.Optional[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. - - images : typing.Optional[typing.Sequence[str]] - An array of image data URIs for the model to embed. Maximum number of images per call is `1`. - - The image must be a valid [data URI](https://developer.mozilla.org/en-US/docs/Web/URI/Schemes/data). The image must be in either `image/jpeg` or `image/png` format and has a maximum size of 5MB. - - 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 : EmbedRequestV2 request_options : typing.Optional[RequestOptions] Request-specific configuration. @@ -1837,25 +1787,22 @@ def embed( Examples -------- - from cohere import Client + from cohere import Client, EmbedRequestV2 client = Client( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) - client.embed() + client.embed( + request=EmbedRequestV2( + model="model", + ), + ) """ _response = self._client_wrapper.httpx_client.request( "v1/embed", method="POST", - json={ - "texts": texts, - "images": images, - "model": model, - "input_type": input_type, - "embedding_types": embedding_types, - "truncate": truncate, - }, + json=convert_and_respect_annotation_metadata(object_=request, annotation=EmbedRequestV2, direction="write"), request_options=request_options, omit=OMIT, ) @@ -4793,15 +4740,7 @@ async def main() -> None: raise ApiError(status_code=_response.status_code, body=_response_json) async def embed( - self, - *, - texts: typing.Optional[typing.Sequence[str]] = OMIT, - images: typing.Optional[typing.Sequence[str]] = OMIT, - model: typing.Optional[str] = OMIT, - input_type: typing.Optional[EmbedInputType] = OMIT, - embedding_types: typing.Optional[typing.Sequence[EmbeddingType]] = OMIT, - truncate: typing.Optional[EmbedRequestTruncate] = OMIT, - request_options: typing.Optional[RequestOptions] = None, + self, *, request: EmbedRequestV2, request_options: typing.Optional[RequestOptions] = None ) -> EmbedResponse: """ This endpoint returns text embeddings. An embedding is a list of floating point numbers that captures semantic information about the text that it represents. @@ -4812,47 +4751,7 @@ async def embed( Parameters ---------- - texts : typing.Optional[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. - - images : typing.Optional[typing.Sequence[str]] - An array of image data URIs for the model to embed. Maximum number of images per call is `1`. - - The image must be a valid [data URI](https://developer.mozilla.org/en-US/docs/Web/URI/Schemes/data). The image must be in either `image/jpeg` or `image/png` format and has a maximum size of 5MB. - - 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 : EmbedRequestV2 request_options : typing.Optional[RequestOptions] Request-specific configuration. @@ -4866,7 +4765,7 @@ async def embed( -------- import asyncio - from cohere import AsyncClient + from cohere import AsyncClient, EmbedRequestV2 client = AsyncClient( client_name="YOUR_CLIENT_NAME", @@ -4875,7 +4774,11 @@ async def embed( async def main() -> None: - await client.embed() + await client.embed( + request=EmbedRequestV2( + model="model", + ), + ) asyncio.run(main()) @@ -4883,14 +4786,7 @@ async def main() -> None: _response = await self._client_wrapper.httpx_client.request( "v1/embed", method="POST", - json={ - "texts": texts, - "images": images, - "model": model, - "input_type": input_type, - "embedding_types": embedding_types, - "truncate": truncate, - }, + json=convert_and_respect_annotation_metadata(object_=request, annotation=EmbedRequestV2, direction="write"), request_options=request_options, omit=OMIT, ) diff --git a/src/cohere/finetuning/__init__.py b/src/cohere/finetuning/__init__.py index ea532e8b2..29eed472f 100644 --- a/src/cohere/finetuning/__init__.py +++ b/src/cohere/finetuning/__init__.py @@ -13,6 +13,7 @@ ListEventsResponse, ListFinetunedModelsResponse, ListTrainingStepMetricsResponse, + LoraTargetModules, Settings, Status, Strategy, @@ -33,6 +34,7 @@ "ListEventsResponse", "ListFinetunedModelsResponse", "ListTrainingStepMetricsResponse", + "LoraTargetModules", "Settings", "Status", "Strategy", diff --git a/src/cohere/finetuning/finetuning/__init__.py b/src/cohere/finetuning/finetuning/__init__.py index 71e235731..a8c6b7817 100644 --- a/src/cohere/finetuning/finetuning/__init__.py +++ b/src/cohere/finetuning/finetuning/__init__.py @@ -12,6 +12,7 @@ ListEventsResponse, ListFinetunedModelsResponse, ListTrainingStepMetricsResponse, + LoraTargetModules, Settings, Status, Strategy, @@ -32,6 +33,7 @@ "ListEventsResponse", "ListFinetunedModelsResponse", "ListTrainingStepMetricsResponse", + "LoraTargetModules", "Settings", "Status", "Strategy", diff --git a/src/cohere/finetuning/finetuning/types/__init__.py b/src/cohere/finetuning/finetuning/types/__init__.py index d573f6518..72f975c71 100644 --- a/src/cohere/finetuning/finetuning/types/__init__.py +++ b/src/cohere/finetuning/finetuning/types/__init__.py @@ -11,6 +11,7 @@ from .list_events_response import ListEventsResponse from .list_finetuned_models_response import ListFinetunedModelsResponse from .list_training_step_metrics_response import ListTrainingStepMetricsResponse +from .lora_target_modules import LoraTargetModules from .settings import Settings from .status import Status from .strategy import Strategy @@ -30,6 +31,7 @@ "ListEventsResponse", "ListFinetunedModelsResponse", "ListTrainingStepMetricsResponse", + "LoraTargetModules", "Settings", "Status", "Strategy", diff --git a/src/cohere/finetuning/finetuning/types/base_model.py b/src/cohere/finetuning/finetuning/types/base_model.py index 44ad40c31..fc993edb6 100644 --- a/src/cohere/finetuning/finetuning/types/base_model.py +++ b/src/cohere/finetuning/finetuning/types/base_model.py @@ -30,7 +30,7 @@ class BaseModel(UncheckedBaseModel): strategy: typing.Optional[Strategy] = pydantic.Field(default=None) """ - The fine-tuning strategy. + Deprecated: The fine-tuning strategy. """ if IS_PYDANTIC_V2: diff --git a/src/cohere/finetuning/finetuning/types/hyperparameters.py b/src/cohere/finetuning/finetuning/types/hyperparameters.py index 229549b46..2185f4c20 100644 --- a/src/cohere/finetuning/finetuning/types/hyperparameters.py +++ b/src/cohere/finetuning/finetuning/types/hyperparameters.py @@ -3,6 +3,7 @@ from ....core.unchecked_base_model import UncheckedBaseModel import typing import pydantic +from .lora_target_modules import LoraTargetModules from ....core.pydantic_utilities import IS_PYDANTIC_V2 @@ -38,6 +39,23 @@ class Hyperparameters(UncheckedBaseModel): The learning rate to be used during training. """ + lora_alpha: typing.Optional[int] = pydantic.Field(default=None) + """ + Controls the scaling factor for LoRA updates. Higher values make the + updates more impactful. + """ + + lora_rank: typing.Optional[int] = pydantic.Field(default=None) + """ + Specifies the rank for low-rank matrices. Lower ranks reduce parameters + but may limit model flexibility. + """ + + lora_target_modules: typing.Optional[LoraTargetModules] = pydantic.Field(default=None) + """ + The combination of LoRA modules to target. + """ + if IS_PYDANTIC_V2: model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 else: diff --git a/src/cohere/finetuning/finetuning/types/lora_target_modules.py b/src/cohere/finetuning/finetuning/types/lora_target_modules.py new file mode 100644 index 000000000..773ec7a5c --- /dev/null +++ b/src/cohere/finetuning/finetuning/types/lora_target_modules.py @@ -0,0 +1,13 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +LoraTargetModules = typing.Union[ + typing.Literal[ + "LORA_TARGET_MODULES_UNSPECIFIED", + "LORA_TARGET_MODULES_QV", + "LORA_TARGET_MODULES_QKVO", + "LORA_TARGET_MODULES_QKVO_FFN", + ], + typing.Any, +] diff --git a/src/cohere/types/__init__.py b/src/cohere/types/__init__.py index 106547ce1..a34d263f5 100644 --- a/src/cohere/types/__init__.py +++ b/src/cohere/types/__init__.py @@ -110,6 +110,7 @@ from .detokenize_response import DetokenizeResponse from .document import Document from .document_content import DocumentContent +from .document_source import DocumentSource from .embed_by_type_response import EmbedByTypeResponse from .embed_by_type_response_embeddings import EmbedByTypeResponseEmbeddings from .embed_floats_response import EmbedFloatsResponse @@ -117,15 +118,8 @@ from .embed_job import EmbedJob from .embed_job_status import EmbedJobStatus from .embed_job_truncate import EmbedJobTruncate -from .embed_request_truncate import EmbedRequestTruncate -from .embed_request_v2 import ( - ClassificationEmbedRequestV2, - ClusteringEmbedRequestV2, - EmbedRequestV2, - ImageEmbedRequestV2, - SearchDocumentEmbedRequestV2, - SearchQueryEmbedRequestV2, -) +from .embed_request_v2 import EmbedRequestV2 +from .embed_request_v2truncate import EmbedRequestV2Truncate from .embed_response import EmbedResponse, EmbeddingsByTypeEmbedResponse, EmbeddingsFloatsEmbedResponse from .embedding_type import EmbeddingType from .finetune_dataset_metrics import FinetuneDatasetMetrics @@ -149,7 +143,6 @@ from .generation import Generation from .get_connector_response import GetConnectorResponse from .get_model_response import GetModelResponse -from .images import Images from .json_response_format import JsonResponseFormat from .json_response_format_v2 import JsonResponseFormatV2 from .label_metric import LabelMetric @@ -205,10 +198,12 @@ from .summarize_request_format import SummarizeRequestFormat from .summarize_request_length import SummarizeRequestLength from .summarize_response import SummarizeResponse +from .system_message import SystemMessage from .system_message_content import SystemMessageContent from .system_message_content_item import SystemMessageContentItem, TextSystemMessageContentItem -from .texts import Texts -from .texts_truncate import TextsTruncate +from .text_content import TextContent +from .text_response_format import TextResponseFormat +from .text_response_format_v2 import TextResponseFormatV2 from .tokenize_response import TokenizeResponse from .too_many_requests_error_body import TooManyRequestsErrorBody from .tool import Tool @@ -217,10 +212,12 @@ from .tool_call_v2 import ToolCallV2 from .tool_call_v2function import ToolCallV2Function from .tool_content import DocumentToolContent, TextToolContent, ToolContent +from .tool_message import ToolMessage from .tool_message_v2 import ToolMessageV2 from .tool_message_v2tool_content import ToolMessageV2ToolContent from .tool_parameter_definitions_value import ToolParameterDefinitionsValue from .tool_result import ToolResult +from .tool_source import ToolSource from .tool_v2 import ToolV2 from .tool_v2function import ToolV2Function from .unprocessable_entity_error_body import UnprocessableEntityErrorBody @@ -228,6 +225,7 @@ from .usage import Usage from .usage_billed_units import UsageBilledUnits from .usage_tokens import UsageTokens +from .user_message import UserMessage from .user_message_content import UserMessageContent __all__ = [ @@ -310,7 +308,6 @@ "CitationStartEventDelta", "CitationStartEventDeltaMessage", "CitationStartStreamedChatResponseV2", - "ClassificationEmbedRequestV2", "ClassifyDataMetrics", "ClassifyExample", "ClassifyRequestTruncate", @@ -319,7 +316,6 @@ "ClassifyResponseClassificationsItemClassificationType", "ClassifyResponseClassificationsItemLabelsValue", "ClientClosedRequestErrorBody", - "ClusteringEmbedRequestV2", "CompatibleEndpoint", "Connector", "ConnectorAuthStatus", @@ -349,8 +345,8 @@ "EmbedJob", "EmbedJobStatus", "EmbedJobTruncate", - "EmbedRequestTruncate", "EmbedRequestV2", + "EmbedRequestV2Truncate", "EmbedResponse", "EmbeddingType", "EmbeddingsByTypeEmbedResponse", @@ -371,8 +367,6 @@ "Generation", "GetConnectorResponse", "GetModelResponse", - "ImageEmbedRequestV2", - "Images", "JsonObjectResponseFormat", "JsonObjectResponseFormatV2", "JsonResponseFormat", @@ -399,9 +393,7 @@ "RerankerDataMetrics", "ResponseFormat", "ResponseFormatV2", - "SearchDocumentEmbedRequestV2", "SearchQueriesGenerationStreamedChatResponse", - "SearchQueryEmbedRequestV2", "SearchResultsStreamedChatResponse", "SingleGeneration", "SingleGenerationInStream", @@ -430,8 +422,6 @@ "TextResponseFormatV2", "TextSystemMessageContentItem", "TextToolContent", - "Texts", - "TextsTruncate", "TokenizeResponse", "TooManyRequestsErrorBody", "Tool", diff --git a/src/cohere/types/embed_request_truncate.py b/src/cohere/types/embed_request_truncate.py deleted file mode 100644 index 988ddf45b..000000000 --- a/src/cohere/types/embed_request_truncate.py +++ /dev/null @@ -1,5 +0,0 @@ -# This file was auto-generated by Fern from our API Definition. - -import typing - -EmbedRequestTruncate = typing.Union[typing.Literal["NONE", "START", "END"], typing.Any] diff --git a/src/cohere/types/embed_request_v2.py b/src/cohere/types/embed_request_v2.py index d5c36dbb5..96ebe0794 100644 --- a/src/cohere/types/embed_request_v2.py +++ b/src/cohere/types/embed_request_v2.py @@ -1,56 +1,65 @@ # This file was auto-generated by Fern from our API Definition. -from __future__ import annotations from ..core.unchecked_base_model import UncheckedBaseModel import typing +import pydantic +from .embed_input_type import EmbedInputType from .embedding_type import EmbeddingType -from .texts_truncate import TextsTruncate +from .embed_request_v2truncate import EmbedRequestV2Truncate from ..core.pydantic_utilities import IS_PYDANTIC_V2 -import pydantic -import typing_extensions -from ..core.unchecked_base_model import UnionMetadata - - -class SearchDocumentEmbedRequestV2(UncheckedBaseModel): - input_type: typing.Literal["search_document"] = "search_document" - texts: typing.List[str] - model: str - embedding_types: typing.Optional[typing.List[EmbeddingType]] = None - truncate: typing.Optional[TextsTruncate] = None - - 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 - - -class SearchQueryEmbedRequestV2(UncheckedBaseModel): - input_type: typing.Literal["search_query"] = "search_query" - texts: typing.List[str] - model: str - embedding_types: typing.Optional[typing.List[EmbeddingType]] = None - truncate: typing.Optional[TextsTruncate] = None - - 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 -class ClassificationEmbedRequestV2(UncheckedBaseModel): - input_type: typing.Literal["classification"] = "classification" - texts: typing.List[str] - model: str - embedding_types: typing.Optional[typing.List[EmbeddingType]] = None - truncate: typing.Optional[TextsTruncate] = None +class EmbedRequestV2(UncheckedBaseModel): + texts: typing.Optional[typing.List[str]] = pydantic.Field(default=None) + """ + 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. + """ + + images: typing.Optional[typing.List[str]] = pydantic.Field(default=None) + """ + An array of image data URIs for the model to embed. Maximum number of images per call is `1`. + + The image must be a valid [data URI](https://developer.mozilla.org/en-US/docs/Web/URI/Schemes/data). The image must be in either `image/jpeg` or `image/png` format and has a maximum size of 5MB. + """ + + model: str = pydantic.Field() + """ + 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] = None + embedding_types: typing.Optional[typing.List[EmbeddingType]] = pydantic.Field(default=None) + """ + 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[EmbedRequestV2Truncate] = pydantic.Field(default=None) + """ + 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. + """ if IS_PYDANTIC_V2: model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 @@ -60,48 +69,3 @@ class Config: frozen = True smart_union = True extra = pydantic.Extra.allow - - -class ClusteringEmbedRequestV2(UncheckedBaseModel): - input_type: typing.Literal["clustering"] = "clustering" - texts: typing.List[str] - model: str - embedding_types: typing.Optional[typing.List[EmbeddingType]] = None - truncate: typing.Optional[TextsTruncate] = None - - 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 - - -class ImageEmbedRequestV2(UncheckedBaseModel): - input_type: typing.Literal["image"] = "image" - images: typing.List[str] - model: str - embedding_types: typing.Optional[typing.List[EmbeddingType]] = None - - 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 - - -EmbedRequestV2 = typing_extensions.Annotated[ - typing.Union[ - SearchDocumentEmbedRequestV2, - SearchQueryEmbedRequestV2, - ClassificationEmbedRequestV2, - ClusteringEmbedRequestV2, - ImageEmbedRequestV2, - ], - UnionMetadata(discriminant="input_type"), -] diff --git a/src/cohere/types/embed_request_v2truncate.py b/src/cohere/types/embed_request_v2truncate.py new file mode 100644 index 000000000..c263257dd --- /dev/null +++ b/src/cohere/types/embed_request_v2truncate.py @@ -0,0 +1,5 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +EmbedRequestV2Truncate = typing.Union[typing.Literal["NONE", "START", "END"], typing.Any] diff --git a/src/cohere/types/images.py b/src/cohere/types/images.py deleted file mode 100644 index 5c829189a..000000000 --- a/src/cohere/types/images.py +++ /dev/null @@ -1,50 +0,0 @@ -# This file was auto-generated by Fern from our API Definition. - -from ..core.unchecked_base_model import UncheckedBaseModel -import typing -import pydantic -from .embedding_type import EmbeddingType -from ..core.pydantic_utilities import IS_PYDANTIC_V2 - - -class Images(UncheckedBaseModel): - images: typing.List[str] = pydantic.Field() - """ - An array of image data URIs for the model to embed. Maximum number of images per call is `1`. - The image must be a valid [data URI](https://developer.mozilla.org/en-US/docs/Web/URI/Schemes/data). The image must be in either `image/jpeg` or `image/png` format and has a maximum size of 5MB. - """ - - model: str = pydantic.Field() - """ - 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 - """ - - embedding_types: typing.Optional[typing.List[EmbeddingType]] = pydantic.Field(default=None) - """ - 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. - """ - - 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 diff --git a/src/cohere/types/texts.py b/src/cohere/types/texts.py deleted file mode 100644 index 2f2d0978a..000000000 --- a/src/cohere/types/texts.py +++ /dev/null @@ -1,62 +0,0 @@ -# This file was auto-generated by Fern from our API Definition. - -from ..core.unchecked_base_model import UncheckedBaseModel -import typing -import pydantic -from .embedding_type import EmbeddingType -from .texts_truncate import TextsTruncate -from ..core.pydantic_utilities import IS_PYDANTIC_V2 - - -class Texts(UncheckedBaseModel): - texts: typing.List[str] = pydantic.Field() - """ - 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: str = pydantic.Field() - """ - 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 - """ - - embedding_types: typing.Optional[typing.List[EmbeddingType]] = pydantic.Field(default=None) - """ - 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[TextsTruncate] = pydantic.Field(default=None) - """ - 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. - """ - - 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 diff --git a/src/cohere/types/texts_truncate.py b/src/cohere/types/texts_truncate.py deleted file mode 100644 index b0e2faf0e..000000000 --- a/src/cohere/types/texts_truncate.py +++ /dev/null @@ -1,5 +0,0 @@ -# This file was auto-generated by Fern from our API Definition. - -import typing - -TextsTruncate = typing.Union[typing.Literal["NONE", "START", "END"], typing.Any] diff --git a/src/cohere/v2/client.py b/src/cohere/v2/client.py index b504acfb5..204b51fb9 100644 --- a/src/cohere/v2/client.py +++ b/src/cohere/v2/client.py @@ -686,16 +686,15 @@ def embed( Examples -------- - from cohere import Client, ImageEmbedRequestV2 + from cohere import Client, EmbedRequestV2 client = Client( client_name="YOUR_CLIENT_NAME", token="YOUR_TOKEN", ) client.v2.embed( - request=ImageEmbedRequestV2( - images=["string"], - model="string", + request=EmbedRequestV2( + model="model", ), ) """ @@ -1697,7 +1696,7 @@ async def embed( -------- import asyncio - from cohere import AsyncClient, ImageEmbedRequestV2 + from cohere import AsyncClient, EmbedRequestV2 client = AsyncClient( client_name="YOUR_CLIENT_NAME", @@ -1707,9 +1706,8 @@ async def embed( async def main() -> None: await client.v2.embed( - request=ImageEmbedRequestV2( - images=["string"], - model="string", + request=EmbedRequestV2( + model="model", ), )