Skip to content
Closed
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
8 changes: 4 additions & 4 deletions .fern/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"cliVersion": "5.55.0",
"generatorName": "fernapi/fern-python-sdk",
"generatorVersion": "5.29.3",
"generatorVersion": "5.39.3",
"generatorConfig": {
"tcp_keepalive": {
"enabled": true,
Expand Down Expand Up @@ -100,10 +100,10 @@
}
]
},
"originGitCommit": "2bfdfa67e2f98426451cf784a8f798e6c9272b9b",
"originGitCommit": "90d3d3227088a6b843724a54b8779bab1aa6787e",
"originGitCommitIsDirty": false,
"invokedBy": "ci",
"requestedVersion": "7.2.0",
"requestedVersion": "7.3.0",
"ciProvider": "github",
"sdkVersion": "7.2.0"
"sdkVersion": "7.3.0"
}
8 changes: 7 additions & 1 deletion .fern/replay.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1,779 changes: 1,007 additions & 772 deletions poetry.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[project]
name = "cohere"
dynamic = ["version"]
license = "MIT"
license-files = ["LICENSE"]

[tool.poetry]
name = "cohere"
version = "7.2.0"
version = "7.3.0"
description = ""
readme = "README.md"
authors = []
Expand All @@ -26,8 +28,7 @@ classifiers = [
"Operating System :: POSIX :: Linux",
"Operating System :: Microsoft :: Windows",
"Topic :: Software Development :: Libraries :: Python Modules",
"Typing :: Typed",
"License :: OSI Approved :: MIT License"
"Typing :: Typed"
]
packages = [
{ include = "cohere", from = "src"}
Expand Down
31 changes: 22 additions & 9 deletions reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1510,8 +1510,8 @@ client.embed(
"hello",
"goodbye"
],
model="embed-v4.0",
input_type="classification",
model="embed-v5.0-fast",
input_type="search_document",
)

```
Expand Down Expand Up @@ -3025,8 +3025,8 @@ client.v2.embed(
"hello",
"goodbye"
],
model="embed-v4.0",
input_type="classification",
model="embed-v5.0-fast",
input_type="search_document",
embedding_types=[
"float"
],
Expand Down Expand Up @@ -3107,7 +3107,7 @@ For **Embed v4.0 and newer** models, there is no limit on the number of images p
**output_dimension:** `typing.Optional[int]`

The number of dimensions of the output embedding. This is only available for `embed-v4` and newer models.
Possible values are `256`, `512`, `1024`, and `1536`. The default is `1536`.
For supported dimensions, please refer to the [Embed models](https://docs.cohere.com/docs/cohere-embed) page.

</dd>
</dl>
Expand Down Expand Up @@ -3193,7 +3193,7 @@ This endpoint takes in a query and a list of texts and produces an ordered array
<dd>

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

client = Client(
Expand All @@ -3202,16 +3202,21 @@ client = Client(
)

client.v2.rerank(
model="rerank-v4.0-pro",
model="rerank-v5.0-pro",
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.",
"Capitalization or capitalisation in English grammar is the use of a capital letter at the start of a word. English usage varies from capitalization in other languages.",
"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 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."
"Capital gains are profits from the sale of an asset such as stocks or real estate. In the United States, long-term capital gains are taxed at lower rates than ordinary income."
],
top_n=3,
relevant_spans=RerankRelevantSpans(
mode="enabled",
threshold=0.1,
max_spans=3,
),
)

```
Expand All @@ -3228,7 +3233,7 @@ client.v2.rerank(
<dl>
<dd>

**model:** `str` — The identifier of the model to use, eg `rerank-v3.5`.
**model:** `str` — The identifier of the model to use, eg `rerank-v5.0-pro`.

</dd>
</dl>
Expand Down Expand Up @@ -3275,6 +3280,14 @@ For optimal performance we recommend against sending more than 1,000 documents i
<dl>
<dd>

**relevant_spans:** `typing.Optional[RerankRelevantSpans]`

</dd>
</dl>

<dl>
<dd>

**priority:** `typing.Optional[int]` — Controls how early the request is handled. Lower numbers indicate higher priority (default: 0, the highest). When the system is under load, higher-priority requests are processed first and are the least likely to be dropped.

</dd>
Expand Down
9 changes: 9 additions & 0 deletions src/cohere/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@
ParseTextBlock,
ParseTextContentBlock,
RerankDocument,
RerankRelevantSpanResponse,
RerankRelevantSpans,
RerankRelevantSpansMode,
RerankRequestDocumentsItem,
RerankResponse,
RerankResponseResultsItem,
Expand Down Expand Up @@ -572,6 +575,9 @@
"ParseTextBlock": ".types",
"ParseTextContentBlock": ".types",
"RerankDocument": ".types",
"RerankRelevantSpanResponse": ".types",
"RerankRelevantSpans": ".types",
"RerankRelevantSpansMode": ".types",
"RerankRequestDocumentsItem": ".types",
"RerankResponse": ".types",
"RerankResponseResultsItem": ".types",
Expand Down Expand Up @@ -934,6 +940,9 @@ def __dir__():
"ParseTextBlock",
"ParseTextContentBlock",
"RerankDocument",
"RerankRelevantSpanResponse",
"RerankRelevantSpans",
"RerankRelevantSpansMode",
"RerankRequestDocumentsItem",
"RerankResponse",
"RerankResponseResultsItem",
Expand Down
14 changes: 8 additions & 6 deletions src/cohere/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def __init__(
base_url: typing.Optional[str] = None,
environment: ClientEnvironment = ClientEnvironment.PRODUCTION,
client_name: typing.Optional[str] = None,
token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = os.getenv("CO_API_KEY"),
token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
headers: typing.Optional[typing.Dict[str, str]] = None,
timeout: typing.Optional[float] = None,
max_retries: typing.Optional[int] = None,
Expand All @@ -135,6 +135,7 @@ def __init__(
):
_defaulted_timeout = timeout if timeout is not None else 300 if httpx_client is None else None
_defaulted_max_retries = max_retries if max_retries is not None else 2
token = token if token is not None else os.getenv("CO_API_KEY")
if token is None:
raise ApiError(body="The client must be instantiated be either passing in token or setting CO_API_KEY")
self._client_wrapper = SyncClientWrapper(
Expand Down Expand Up @@ -1147,8 +1148,8 @@ def embed(
)
client.embed(
texts=["hello", "goodbye"],
model="embed-v4.0",
input_type="classification",
model="embed-v5.0-fast",
input_type="search_document",
)
"""
_response = self._raw_client.embed(
Expand Down Expand Up @@ -1691,7 +1692,7 @@ def __init__(
base_url: typing.Optional[str] = None,
environment: ClientEnvironment = ClientEnvironment.PRODUCTION,
client_name: typing.Optional[str] = None,
token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = os.getenv("CO_API_KEY"),
token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
headers: typing.Optional[typing.Dict[str, str]] = None,
async_token: typing.Optional[typing.Callable[[], typing.Awaitable[str]]] = None,
timeout: typing.Optional[float] = None,
Expand All @@ -1704,6 +1705,7 @@ def __init__(
):
_defaulted_timeout = timeout if timeout is not None else 300 if httpx_client is None else None
_defaulted_max_retries = max_retries if max_retries is not None else 2
token = token if token is not None else os.getenv("CO_API_KEY")
if token is None:
raise ApiError(body="The client must be instantiated be either passing in token or setting CO_API_KEY")
self._client_wrapper = AsyncClientWrapper(
Expand Down Expand Up @@ -2747,8 +2749,8 @@ async def embed(
async def main() -> None:
await client.embed(
texts=["hello", "goodbye"],
model="embed-v4.0",
input_type="classification",
model="embed-v5.0-fast",
input_type="search_document",
)


Expand Down
11 changes: 6 additions & 5 deletions src/cohere/core/client_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,22 @@ def __init__(
self._max_stream_reconnection_attempts = max_stream_reconnection_attempts
self._logging = logging

def get_headers(self) -> typing.Dict[str, str]:
def get_headers(self, *, include_token: bool = True) -> typing.Dict[str, str]:
import platform

headers: typing.Dict[str, str] = {
"User-Agent": "cohere/7.2.0",
"User-Agent": "cohere/7.3.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": "7.2.0",
"X-Fern-SDK-Version": "7.3.0",
**(self.get_custom_headers() or {}),
}
if self._client_name is not None:
headers["X-Client-Name"] = self._client_name
headers["Authorization"] = f"Bearer {self._get_token()}"
if include_token:
headers["Authorization"] = f"Bearer {self._get_token()}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Async client header construction crashes

High Severity

get_headers now takes include_token, and async_get_headers always passes it. The existing omit_authorization_header_when_api_key_is_empty patch still replaces get_headers with a one-argument wrapper, so every AsyncClient request raises TypeError when building headers.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 02e602f. Configure here.

return headers

def _get_token(self) -> str:
Expand Down Expand Up @@ -148,7 +149,7 @@ def __init__(
)

async def async_get_headers(self) -> typing.Dict[str, str]:
headers = self.get_headers()
headers = self.get_headers(include_token=self._async_token is None)
if self._async_token is not None:
token = await self._async_token()
headers["Authorization"] = f"Bearer {token}"
Expand Down
Loading
Loading