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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cohere"
version = "5.0.1"
version = "5.0.2"
description = ""
readme = "README.md"
authors = []
Expand Down
10 changes: 8 additions & 2 deletions src/cohere/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,17 @@ def fn(*args, **kwargs):
class Client(BaseCohere):
def __init__(
self,
api_key: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = os.getenv("CO_API_KEY"),
api_key: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
*,
base_url: typing.Optional[str] = os.getenv("CO_API_URL"),
environment: ClientEnvironment = ClientEnvironment.PRODUCTION,
client_name: typing.Optional[str] = None,
timeout: typing.Optional[float] = 60,
httpx_client: typing.Optional[httpx.Client] = None,
):
if api_key is None:
api_key = os.getenv("CO_API_KEY")

BaseCohere.__init__(
self,
base_url=base_url,
Expand Down Expand Up @@ -130,14 +133,17 @@ def __init__(
class AsyncClient(AsyncBaseCohere):
def __init__(
self,
api_key: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = os.getenv("CO_API_KEY"),
api_key: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
*,
base_url: typing.Optional[str] = os.getenv("CO_API_URL"),
environment: ClientEnvironment = ClientEnvironment.PRODUCTION,
client_name: typing.Optional[str] = None,
timeout: typing.Optional[float] = 60,
httpx_client: typing.Optional[httpx.AsyncClient] = None,
):
if api_key is None:
api_key = os.getenv("CO_API_KEY")

AsyncBaseCohere.__init__(
self,
base_url=base_url,
Expand Down
2 changes: 1 addition & 1 deletion src/cohere/core/client_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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.0.1",
"X-Fern-SDK-Version": "5.0.2",
}
if self._client_name is not None:
headers["X-Client-Name"] = self._client_name
Expand Down
4 changes: 4 additions & 0 deletions tests/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class TestClient(unittest.IsolatedAsyncioTestCase):
def setUp(self) -> None:
self.co = cohere.AsyncClient(timeout=10000)

async def test_token_falls_back_on_env_variable(self) -> None:
cohere.AsyncClient(api_key=None)
cohere.AsyncClient(None)

async def test_chat(self) -> None:
chat = await self.co.chat(
chat_history=[
Expand Down
4 changes: 4 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

class TestClient(unittest.TestCase):

def test_token_falls_back_on_env_variable(self) -> None:
cohere.Client(api_key=None)
cohere.Client(None)

def test_chat(self) -> None:
chat = co.chat(
chat_history=[
Expand Down