Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 4 additions & 5 deletions .fern/metadata.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"cliVersion": "4.48.0",
"cliVersion": "4.63.2",
"generatorName": "fernapi/fern-python-sdk",
"generatorVersion": "4.63.4",
"generatorVersion": "5.3.3",
"generatorConfig": {
"pyproject_python_version": "^3.9",
"inline_request_params": false,
"extra_dependencies": {
"fastavro": "^1.9.4",
Expand Down Expand Up @@ -79,6 +78,6 @@
}
]
},
"originGitCommit": "40f3fd11b9fd6b445b024a2fcf6f2e67f6181147",
"sdkVersion": "5.21.2"
"originGitCommit": "f6bbd671944a203a435dd01ebe619dcb4e493503",
"sdkVersion": "6.0.0"
}
1,275 changes: 1,025 additions & 250 deletions poetry.lock

Large diffs are not rendered by default.

19 changes: 13 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dynamic = ["version"]

[tool.poetry]
name = "cohere"
version = "5.21.2"
version = "6.0.0"
description = ""
readme = "README.md"
authors = []
Expand All @@ -14,7 +14,6 @@ classifiers = [
"Intended Audience :: Developers",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
Expand All @@ -38,20 +37,22 @@ packages = [
Repository = 'https://github.com/cohere-ai/cohere-python'

[tool.poetry.dependencies]
python = "^3.9"
python = "^3.10"
aiohttp = { version = ">=3.10.0,<4", optional = true}
fastavro = "^1.9.4"
httpx = ">=0.21.2"
httpx-aiohttp = { version = "0.1.8", optional = true}
pydantic = ">= 1.9.2"
pydantic-core = ">=2.18.2"
pydantic-core = ">=2.18.2,<2.44.0"
requests = "^2.0.0"
tokenizers = ">=0.15,<1"
types-requests = "^2.0.0"
typing_extensions = ">= 4.0.0"

[tool.poetry.group.dev.dependencies]
mypy = "==1.13.0"
pytest = "^7.4.0"
pytest-asyncio = "^0.23.5"
pytest = "^8.2.0"
pytest-asyncio = "^1.0.0"
pytest-xdist = "^3.6.1"
python-dateutil = "^2.9.0"
types-python-dateutil = "^2.9.0.20240316"
Expand All @@ -60,6 +61,9 @@ ruff = "==0.11.5"
[tool.pytest.ini_options]
testpaths = [ "tests" ]
asyncio_mode = "auto"
markers = [
"aiohttp: tests that require httpx_aiohttp to be installed",
]

[tool.mypy]
plugins = ["pydantic.mypy"]
Expand Down Expand Up @@ -91,3 +95,6 @@ section-order = ["future", "standard-library", "third-party", "first-party"]
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.extras]
aiohttp=["aiohttp", "httpx-aiohttp"]
18 changes: 8 additions & 10 deletions reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2309,7 +2309,7 @@ Follow the [Migration Guide](https://docs.cohere.com/v2/docs/migrating-v1-to-v2)
<dd>

```python
from cohere import Client
from cohere import Client, ChatMessageV2_User
from cohere.environment import ClientEnvironment

client = Client(
Expand All @@ -2320,10 +2320,9 @@ client = Client(
client.v2.chat_stream(
model="command-a-03-2025",
messages=[
{
"role": "user",
"content": "Tell me about LLMs"
}
ChatMessageV2_User(
content="Tell me about LLMs",
)
],
)

Expand Down Expand Up @@ -2608,7 +2607,7 @@ Follow the [Migration Guide](https://docs.cohere.com/v2/docs/migrating-v1-to-v2)
<dd>

```python
from cohere import Client
from cohere import Client, ChatMessageV2_User
from cohere.environment import ClientEnvironment

client = Client(
Expand All @@ -2619,10 +2618,9 @@ client = Client(
client.v2.chat_stream(
model="command-a-03-2025",
messages=[
{
"role": "user",
"content": "Tell me about LLMs"
}
ChatMessageV2_User(
content="Tell me about LLMs",
)
],
)

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fastavro==1.9.4
httpx>=0.21.2
pydantic>= 1.9.2
pydantic-core>=2.18.2
pydantic-core>=2.18.2,<2.44.0
requests==2.0.0
tokenizers>=0.15,<1
types-requests==2.0.0
Expand Down
8 changes: 8 additions & 0 deletions src/cohere/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
Generation,
GetConnectorResponse,
GetModelResponse,
GetModelResponseSamplingDefaults,
Image,
ImageContent,
ImageUrl,
Expand Down Expand Up @@ -257,6 +258,7 @@
UnprocessableEntityError,
)
from . import audio, batches, connectors, datasets, embed_jobs, finetuning, models, v2
from ._default_clients import DefaultAioHttpClient, DefaultAsyncHttpxClient
from .aliases import (
ChatResponse,
ContentDeltaStreamedChatResponseV2,
Expand Down Expand Up @@ -448,6 +450,8 @@
"DatasetsListResponse": ".datasets",
"DebugStreamedChatResponse": ".types",
"DebugV2ChatStreamResponse": ".v2",
"DefaultAioHttpClient": "._default_clients",
"DefaultAsyncHttpxClient": "._default_clients",
"DeleteConnectorResponse": ".types",
"DetokenizeResponse": ".types",
"Document": ".types",
Expand Down Expand Up @@ -490,6 +494,7 @@
"GetBatchResponse": ".batches",
"GetConnectorResponse": ".types",
"GetModelResponse": ".types",
"GetModelResponseSamplingDefaults": ".types",
"Image": ".types",
"ImageContent": ".types",
"ImageUrl": ".types",
Expand Down Expand Up @@ -782,6 +787,8 @@ def __dir__():
"DatasetsListResponse",
"DebugStreamedChatResponse",
"DebugV2ChatStreamResponse",
"DefaultAioHttpClient",
"DefaultAsyncHttpxClient",
"DeleteConnectorResponse",
"DetokenizeResponse",
"Document",
Expand Down Expand Up @@ -824,6 +831,7 @@ def __dir__():
"GetBatchResponse",
"GetConnectorResponse",
"GetModelResponse",
"GetModelResponseSamplingDefaults",
"Image",
"ImageContent",
"ImageUrl",
Expand Down
30 changes: 30 additions & 0 deletions src/cohere/_default_clients.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file was auto-generated by Fern from our API Definition.

import typing

import httpx

SDK_DEFAULT_TIMEOUT = 60
Comment thread
fern-support marked this conversation as resolved.

try:
import httpx_aiohttp # type: ignore[import-not-found]
except ImportError:

class DefaultAioHttpClient(httpx.AsyncClient): # type: ignore
def __init__(self, **kwargs: typing.Any) -> None:
raise RuntimeError("To use the aiohttp client, install the aiohttp extra: pip install cohere[aiohttp]")

else:

class DefaultAioHttpClient(httpx_aiohttp.HttpxAiohttpClient): # type: ignore
def __init__(self, **kwargs: typing.Any) -> None:
kwargs.setdefault("timeout", SDK_DEFAULT_TIMEOUT)
kwargs.setdefault("follow_redirects", True)
super().__init__(**kwargs)


class DefaultAsyncHttpxClient(httpx.AsyncClient):
def __init__(self, **kwargs: typing.Any) -> None:
kwargs.setdefault("timeout", SDK_DEFAULT_TIMEOUT)
kwargs.setdefault("follow_redirects", True)
super().__init__(**kwargs)
27 changes: 24 additions & 3 deletions src/cohere/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,24 @@ def audio(self):
return self._audio


def _make_default_async_client(
timeout: typing.Optional[float],
follow_redirects: typing.Optional[bool],
) -> httpx.AsyncClient:
try:
import httpx_aiohttp # type: ignore[import-not-found]
except ImportError:
pass
else:
if follow_redirects is not None:
return httpx_aiohttp.HttpxAiohttpClient(timeout=timeout, follow_redirects=follow_redirects)
return httpx_aiohttp.HttpxAiohttpClient(timeout=timeout)

if follow_redirects is not None:
return httpx.AsyncClient(timeout=timeout, follow_redirects=follow_redirects)
return httpx.AsyncClient(timeout=timeout)
Comment thread
fern-support marked this conversation as resolved.


class AsyncBaseCohere:
"""
Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.
Expand All @@ -1604,6 +1622,9 @@ class AsyncBaseCohere:
headers : typing.Optional[typing.Dict[str, str]]
Additional headers to send with every request.

async_token : typing.Optional[typing.Callable[[], typing.Awaitable[str]]]
An async callable that returns a bearer token. Use this when token acquisition involves async I/O (e.g., refreshing tokens via an async HTTP client). When provided, this is used instead of the synchronous token for async requests.

timeout : typing.Optional[float]
The timeout to be used, in seconds, for requests. By default the timeout is 300 seconds, unless a custom httpx client is used, in which case this default is not enforced.

Expand Down Expand Up @@ -1634,6 +1655,7 @@ def __init__(
client_name: typing.Optional[str] = None,
token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = os.getenv("CO_API_KEY"),
headers: typing.Optional[typing.Dict[str, str]] = None,
async_token: typing.Optional[typing.Callable[[], typing.Awaitable[str]]] = None,
timeout: typing.Optional[float] = None,
follow_redirects: typing.Optional[bool] = True,
httpx_client: typing.Optional[httpx.AsyncClient] = None,
Expand All @@ -1649,11 +1671,10 @@ def __init__(
client_name=client_name,
token=token,
headers=headers,
async_token=async_token,
httpx_client=httpx_client
if httpx_client is not None
else httpx.AsyncClient(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
if follow_redirects is not None
else httpx.AsyncClient(timeout=_defaulted_timeout),
else _make_default_async_client(timeout=_defaulted_timeout, follow_redirects=follow_redirects),
timeout=_defaulted_timeout,
logging=logging,
)
Expand Down
3 changes: 3 additions & 0 deletions src/cohere/batches/types/cancel_batch_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
import typing

CancelBatchResponse = typing.Dict[str, typing.Any]
"""
Response to a request to cancel a batch.
"""
4 changes: 2 additions & 2 deletions src/cohere/core/client_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ def get_headers(self) -> typing.Dict[str, str]:
import platform

headers: typing.Dict[str, str] = {
"User-Agent": "cohere/5.21.2",
"User-Agent": "cohere/6.0.0",
"X-Fern-Language": "Python",
"X-Fern-Runtime": f"python/{platform.python_version()}",
"X-Fern-Platform": f"{platform.system().lower()}/{platform.release()}",
"X-Fern-SDK-Name": "cohere",
"X-Fern-SDK-Version": "5.21.2",
"X-Fern-SDK-Version": "6.0.0",
**(self.get_custom_headers() or {}),
}
if self._client_name is not None:
Expand Down
Loading
Loading