Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
820 changes: 456 additions & 364 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "cohere"

[tool.poetry]
name = "cohere"
version = "5.18.0"
version = "5.19.0"
description = ""
readme = "README.md"
authors = []
Expand Down
10 changes: 9 additions & 1 deletion src/cohere/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
UnauthorizedError,
UnprocessableEntityError,
)
from . import connectors, datasets, embed_jobs, finetuning, models, v2
from . import batches, connectors, datasets, embed_jobs, finetuning, models, v2
from .aliases import (
ChatResponse,
ContentDeltaStreamedChatResponseV2,
Expand All @@ -265,6 +265,7 @@
ToolCallStartStreamedChatResponseV2,
)
from .aws_client import AwsClient
from .batches import Batch, BatchStatus, CancelBatchResponse, CreateBatchResponse, GetBatchResponse, ListBatchesResponse
from .bedrock_client import BedrockClient, BedrockClientV2
from .client import AsyncClient, Client
from .client_v2 import AsyncClientV2, ClientV2
Expand Down Expand Up @@ -315,8 +316,11 @@
"AuthTokenType",
"AwsClient",
"BadRequestError",
"Batch",
"BatchStatus",
"BedrockClient",
"BedrockClientV2",
"CancelBatchResponse",
"ChatCitation",
"ChatCitationGenerationEvent",
"ChatCitationType",
Expand Down Expand Up @@ -417,6 +421,7 @@
"ContentEndV2ChatStreamResponse",
"ContentStartStreamedChatResponseV2",
"ContentStartV2ChatStreamResponse",
"CreateBatchResponse",
"CreateConnectorOAuth",
"CreateConnectorResponse",
"CreateConnectorServiceAuth",
Expand Down Expand Up @@ -470,6 +475,7 @@
"GenerateStreamText",
"GenerateStreamedResponse",
"Generation",
"GetBatchResponse",
"GetConnectorResponse",
"GetModelResponse",
"Image",
Expand All @@ -485,6 +491,7 @@
"JsonResponseFormat",
"JsonResponseFormatV2",
"LabelMetric",
"ListBatchesResponse",
"ListConnectorsResponse",
"ListEmbedJobResponse",
"ListModelsResponse",
Expand Down Expand Up @@ -594,6 +601,7 @@
"V2RerankResponse",
"V2RerankResponseResultsItem",
"__version__",
"batches",
"connectors",
"datasets",
"embed_jobs",
Expand Down
69 changes: 23 additions & 46 deletions src/cohere/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import typing

import httpx
from .batches.client import AsyncBatchesClient, BatchesClient
from .connectors.client import AsyncConnectorsClient, ConnectorsClient
from .core.api_error import ApiError
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
Expand Down Expand Up @@ -124,6 +125,7 @@ def __init__(
)
self._raw_client = RawBaseCohere(client_wrapper=self._client_wrapper)
self.v2 = V2Client(client_wrapper=self._client_wrapper)
self.batches = BatchesClient(client_wrapper=self._client_wrapper)
self.embed_jobs = EmbedJobsClient(client_wrapper=self._client_wrapper)
self.datasets = DatasetsClient(client_wrapper=self._client_wrapper)
self.connectors = ConnectorsClient(client_wrapper=self._client_wrapper)
Expand Down Expand Up @@ -268,9 +270,8 @@ def chat_stream(
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.
Defaults to `"enabled"`.
Citations are enabled by default for models that support it, but can be turned off by setting `"type": "disabled"`.

Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments

Expand Down Expand Up @@ -406,7 +407,8 @@ def chat_stream(
token="YOUR_TOKEN",
)
response = client.chat_stream(
message="hello world!",
model="command-a-03-2025",
message="hello!",
)
for chunk in response:
yield chunk
Expand Down Expand Up @@ -568,9 +570,8 @@ def chat(
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.
Defaults to `"enabled"`.
Citations are enabled by default for models that support it, but can be turned off by setting `"type": "disabled"`.

Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments

Expand Down Expand Up @@ -699,27 +700,15 @@ def chat(

Examples
--------
from cohere import ChatbotMessage, ChatConnector, Client, UserMessage
from cohere import Client

client = Client(
client_name="YOUR_CLIENT_NAME",
token="YOUR_TOKEN",
)
client.chat(
chat_history=[
UserMessage(
message="Who discovered gravity?",
),
ChatbotMessage(
message="The man who is widely credited with discovering gravity is Sir Isaac Newton",
),
],
message="What year was he born?",
connectors=[
ChatConnector(
id="web-search",
)
],
model="command-a-03-2025",
message="Tell me about LLMs",
)
"""
_response = self._raw_client.chat(
Expand Down Expand Up @@ -1073,7 +1062,7 @@ def embed(
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.
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`, `image/png`, `image/webp`, or `image/gif` format and has a maximum size of 5MB.

Images are only supported with Embed v3.0 and newer models.

Expand Down Expand Up @@ -1580,6 +1569,7 @@ def __init__(
)
self._raw_client = AsyncRawBaseCohere(client_wrapper=self._client_wrapper)
self.v2 = AsyncV2Client(client_wrapper=self._client_wrapper)
self.batches = AsyncBatchesClient(client_wrapper=self._client_wrapper)
self.embed_jobs = AsyncEmbedJobsClient(client_wrapper=self._client_wrapper)
self.datasets = AsyncDatasetsClient(client_wrapper=self._client_wrapper)
self.connectors = AsyncConnectorsClient(client_wrapper=self._client_wrapper)
Expand Down Expand Up @@ -1724,9 +1714,8 @@ async def chat_stream(
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.
Defaults to `"enabled"`.
Citations are enabled by default for models that support it, but can be turned off by setting `"type": "disabled"`.

Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments

Expand Down Expand Up @@ -1867,7 +1856,8 @@ async def chat_stream(

async def main() -> None:
response = await client.chat_stream(
message="hello world!",
model="command-a-03-2025",
message="hello!",
)
async for chunk in response:
yield chunk
Expand Down Expand Up @@ -2033,9 +2023,8 @@ async def chat(
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.
Defaults to `"enabled"`.
Citations are enabled by default for models that support it, but can be turned off by setting `"type": "disabled"`.

Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments

Expand Down Expand Up @@ -2166,7 +2155,7 @@ async def chat(
--------
import asyncio

from cohere import AsyncClient, ChatbotMessage, ChatConnector, UserMessage
from cohere import AsyncClient

client = AsyncClient(
client_name="YOUR_CLIENT_NAME",
Expand All @@ -2176,20 +2165,8 @@ async def chat(

async def main() -> None:
await client.chat(
chat_history=[
UserMessage(
message="Who discovered gravity?",
),
ChatbotMessage(
message="The man who is widely credited with discovering gravity is Sir Isaac Newton",
),
],
message="What year was he born?",
connectors=[
ChatConnector(
id="web-search",
)
],
model="command-a-03-2025",
message="Tell me about LLMs",
)


Expand Down Expand Up @@ -2563,7 +2540,7 @@ async def embed(
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.
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`, `image/png`, `image/webp`, or `image/gif` format and has a maximum size of 5MB.

Images are only supported with Embed v3.0 and newer models.

Expand Down
14 changes: 14 additions & 0 deletions src/cohere/batches/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This file was auto-generated by Fern from our API Definition.

# isort: skip_file

from .types import Batch, BatchStatus, CancelBatchResponse, CreateBatchResponse, GetBatchResponse, ListBatchesResponse

__all__ = [
"Batch",
"BatchStatus",
"CancelBatchResponse",
"CreateBatchResponse",
"GetBatchResponse",
"ListBatchesResponse",
]
Loading
Loading