Skip to content
Merged
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
14 changes: 10 additions & 4 deletions src/cohere/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def fn(*args, **kwargs):


class Client(BaseCohere, CacheMixin):
_executor: ThreadPoolExecutor

def __init__(
self,
api_key: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
Expand All @@ -80,10 +82,13 @@ def __init__(
client_name: typing.Optional[str] = None,
timeout: typing.Optional[float] = None,
httpx_client: typing.Optional[httpx.Client] = None,
thread_pool_executor: ThreadPoolExecutor = ThreadPoolExecutor(64)
):
if api_key is None:
api_key = _get_api_key_from_environment()

self._executor = thread_pool_executor

BaseCohere.__init__(
self,
base_url=base_url,
Expand All @@ -108,8 +113,6 @@ def __exit__(self, exc_type, exc_value, traceback):

wait = wait

_executor = ThreadPoolExecutor(64)

def embed(
self,
*,
Expand Down Expand Up @@ -250,6 +253,8 @@ def fetch_tokenizer(self, *, model: str) -> Tokenizer:


class AsyncClient(AsyncBaseCohere, CacheMixin):
_executor: ThreadPoolExecutor

def __init__(
self,
api_key: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
Expand All @@ -259,10 +264,13 @@ def __init__(
client_name: typing.Optional[str] = None,
timeout: typing.Optional[float] = None,
httpx_client: typing.Optional[httpx.AsyncClient] = None,
thread_pool_executor: ThreadPoolExecutor = ThreadPoolExecutor(64)
):
if api_key is None:
api_key = _get_api_key_from_environment()

self._executor = thread_pool_executor

AsyncBaseCohere.__init__(
self,
base_url=base_url,
Expand All @@ -287,8 +295,6 @@ async def __aexit__(self, exc_type, exc_value, traceback):

wait = async_wait

_executor = ThreadPoolExecutor(64)

async def embed(
self,
*,
Expand Down