-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy path_default_clients.py
More file actions
31 lines (23 loc) · 962 Bytes
/
_default_clients.py
File metadata and controls
31 lines (23 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import typing
import httpx
COHERE_DEFAULT_TIMEOUT = 300
try:
import httpx_aiohttp
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", COHERE_DEFAULT_TIMEOUT)
kwargs.setdefault("follow_redirects", True)
super().__init__(**kwargs)
class DefaultAsyncHttpxClient(httpx.AsyncClient):
def __init__(self, **kwargs: typing.Any) -> None:
kwargs.setdefault("timeout", COHERE_DEFAULT_TIMEOUT)
kwargs.setdefault("follow_redirects", True)
super().__init__(**kwargs)