[go: nahoru, domu]

Skip to content

Commit

Permalink
(fix): respect client wide timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-api[bot] committed Mar 26, 2024
1 parent 44e805e commit 145352e
Show file tree
Hide file tree
Showing 26 changed files with 476 additions and 205 deletions.
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 = "elevenlabs"
version = "v1.0.1"
version = "v1.0.2"
description = ""
readme = "README.md"
authors = []
Expand Down
16 changes: 16 additions & 0 deletions src/elevenlabs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Age,
AudioNativeCreateProjectResponseModel,
AudioNativeGetEmbedCodeResponseModel,
AudioOutput,
ChapterResponse,
ChapterSnapshotResponse,
ChapterSnapshotsResponse,
Expand All @@ -20,6 +21,7 @@
FineTuningResponse,
FinetuningState,
Gender,
GenerationConfig,
GetChaptersResponse,
GetLibraryVoicesResponse,
GetProjectsResponse,
Expand All @@ -35,14 +37,19 @@
ManualVerificationFileResponse,
ManualVerificationResponse,
Model,
NormalizedAlignment,
OptimizeStreamingLatency,
OutputFormat,
ProjectExtendedResponseModel,
ProjectResponse,
ProjectSnapshotResponse,
ProjectSnapshotsResponse,
ProjectState,
PronunciationDictionaryVersionLocator,
RealtimeVoiceSettings,
RecordingResponse,
ReviewStatus,
SendText,
Source,
SpeechHistoryItemResponse,
SpeechHistoryItemResponseModelVoiceCategory,
Expand Down Expand Up @@ -84,6 +91,7 @@
)
from .environment import ElevenLabsEnvironment
from .play import play, save, stream
from .version import __version__

__all__ = [
"Accent",
Expand All @@ -93,6 +101,7 @@
"Age",
"AudioNativeCreateProjectResponseModel",
"AudioNativeGetEmbedCodeResponseModel",
"AudioOutput",
"ChapterResponse",
"ChapterSnapshotResponse",
"ChapterSnapshotsResponse",
Expand All @@ -106,6 +115,7 @@
"FineTuningResponse",
"FinetuningState",
"Gender",
"GenerationConfig",
"GetChaptersResponse",
"GetLibraryVoicesResponse",
"GetProjectsResponse",
Expand All @@ -121,14 +131,19 @@
"ManualVerificationFileResponse",
"ManualVerificationResponse",
"Model",
"NormalizedAlignment",
"OptimizeStreamingLatency",
"OutputFormat",
"ProjectExtendedResponseModel",
"ProjectResponse",
"ProjectSnapshotResponse",
"ProjectSnapshotsResponse",
"ProjectState",
"PronunciationDictionaryVersionLocator",
"RealtimeVoiceSettings",
"RecordingResponse",
"ReviewStatus",
"SendText",
"Source",
"SpeechHistoryItemResponse",
"SpeechHistoryItemResponseModelVoiceCategory",
Expand All @@ -152,6 +167,7 @@
"VoiceSharingResponse",
"VoiceSharingState",
"VoiceVerificationResponse",
"__version__",
"audio_native",
"chapters",
"dubbing",
Expand Down
4 changes: 2 additions & 2 deletions src/elevenlabs/audio_native/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def create(
),
timeout=request_options.get("timeout_in_seconds")
if request_options is not None and request_options.get("timeout_in_seconds") is not None
else 60,
else self._client_wrapper.get_timeout(),
retries=0,
max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore
)
Expand Down Expand Up @@ -264,7 +264,7 @@ async def create(
),
timeout=request_options.get("timeout_in_seconds")
if request_options is not None and request_options.get("timeout_in_seconds") is not None
else 60,
else self._client_wrapper.get_timeout(),
retries=0,
max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore
)
Expand Down
16 changes: 10 additions & 6 deletions src/elevenlabs/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BaseElevenLabs:
- api_key: typing.Optional[str].
- timeout: typing.Optional[float]. The timeout to be used, in seconds, for requests by default the timeout is 60 seconds.
- timeout: typing.Optional[float]. The timeout to be used, in seconds, for requests by default the timeout is 60 seconds, unless a custom httpx client is used, in which case a default is not set.
- httpx_client: typing.Optional[httpx.Client]. The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
---
Expand All @@ -52,13 +52,15 @@ def __init__(
base_url: typing.Optional[str] = None,
environment: ElevenLabsEnvironment = ElevenLabsEnvironment.PRODUCTION,
api_key: typing.Optional[str] = os.getenv("ELEVEN_API_KEY"),
timeout: typing.Optional[float] = 60,
timeout: typing.Optional[float] = None,
httpx_client: typing.Optional[httpx.Client] = None
):
_defaulted_timeout = timeout if timeout is not None else 60 if httpx_client is None else None
self._client_wrapper = SyncClientWrapper(
base_url=_get_base_url(base_url=base_url, environment=environment),
api_key=api_key,
httpx_client=httpx.Client(timeout=timeout) if httpx_client is None else httpx_client,
httpx_client=httpx.Client(timeout=_defaulted_timeout) if httpx_client is None else httpx_client,
timeout=_defaulted_timeout,
)
self.history = HistoryClient(client_wrapper=self._client_wrapper)
self.samples = SamplesClient(client_wrapper=self._client_wrapper)
Expand Down Expand Up @@ -88,7 +90,7 @@ class AsyncBaseElevenLabs:
- api_key: typing.Optional[str].
- timeout: typing.Optional[float]. The timeout to be used, in seconds, for requests by default the timeout is 60 seconds.
- timeout: typing.Optional[float]. The timeout to be used, in seconds, for requests by default the timeout is 60 seconds, unless a custom httpx client is used, in which case a default is not set.
- httpx_client: typing.Optional[httpx.AsyncClient]. The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
---
Expand All @@ -105,13 +107,15 @@ def __init__(
base_url: typing.Optional[str] = None,
environment: ElevenLabsEnvironment = ElevenLabsEnvironment.PRODUCTION,
api_key: typing.Optional[str] = os.getenv("ELEVEN_API_KEY"),
timeout: typing.Optional[float] = 60,
timeout: typing.Optional[float] = None,
httpx_client: typing.Optional[httpx.AsyncClient] = None
):
_defaulted_timeout = timeout if timeout is not None else 60 if httpx_client is None else None
self._client_wrapper = AsyncClientWrapper(
base_url=_get_base_url(base_url=base_url, environment=environment),
api_key=api_key,
httpx_client=httpx.AsyncClient(timeout=timeout) if httpx_client is None else httpx_client,
httpx_client=httpx.AsyncClient(timeout=_defaulted_timeout) if httpx_client is None else httpx_client,
timeout=_defaulted_timeout,
)
self.history = AsyncHistoryClient(client_wrapper=self._client_wrapper)
self.samples = AsyncSamplesClient(client_wrapper=self._client_wrapper)
Expand Down
24 changes: 12 additions & 12 deletions src/elevenlabs/chapters/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def get_all(
),
timeout=request_options.get("timeout_in_seconds")
if request_options is not None and request_options.get("timeout_in_seconds") is not None
else 60,
else self._client_wrapper.get_timeout(),
retries=0,
max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore
)
Expand Down Expand Up @@ -119,7 +119,7 @@ def get(
),
timeout=request_options.get("timeout_in_seconds")
if request_options is not None and request_options.get("timeout_in_seconds") is not None
else 60,
else self._client_wrapper.get_timeout(),
retries=0,
max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore
)
Expand Down Expand Up @@ -175,7 +175,7 @@ def delete(
),
timeout=request_options.get("timeout_in_seconds")
if request_options is not None and request_options.get("timeout_in_seconds") is not None
else 60,
else self._client_wrapper.get_timeout(),
retries=0,
max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore
)
Expand Down Expand Up @@ -234,7 +234,7 @@ def convert(
),
timeout=request_options.get("timeout_in_seconds")
if request_options is not None and request_options.get("timeout_in_seconds") is not None
else 60,
else self._client_wrapper.get_timeout(),
retries=0,
max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore
)
Expand Down Expand Up @@ -290,7 +290,7 @@ def get_all_snapshots(
),
timeout=request_options.get("timeout_in_seconds")
if request_options is not None and request_options.get("timeout_in_seconds") is not None
else 60,
else self._client_wrapper.get_timeout(),
retries=0,
max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore
)
Expand Down Expand Up @@ -357,7 +357,7 @@ def stream_snapshot(
),
timeout=request_options.get("timeout_in_seconds")
if request_options is not None and request_options.get("timeout_in_seconds") is not None
else 60,
else self._client_wrapper.get_timeout(),
retries=0,
max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore
)
Expand Down Expand Up @@ -414,7 +414,7 @@ async def get_all(
),
timeout=request_options.get("timeout_in_seconds")
if request_options is not None and request_options.get("timeout_in_seconds") is not None
else 60,
else self._client_wrapper.get_timeout(),
retries=0,
max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore
)
Expand Down Expand Up @@ -470,7 +470,7 @@ async def get(
),
timeout=request_options.get("timeout_in_seconds")
if request_options is not None and request_options.get("timeout_in_seconds") is not None
else 60,
else self._client_wrapper.get_timeout(),
retries=0,
max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore
)
Expand Down Expand Up @@ -526,7 +526,7 @@ async def delete(
),
timeout=request_options.get("timeout_in_seconds")
if request_options is not None and request_options.get("timeout_in_seconds") is not None
else 60,
else self._client_wrapper.get_timeout(),
retries=0,
max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore
)
Expand Down Expand Up @@ -585,7 +585,7 @@ async def convert(
),
timeout=request_options.get("timeout_in_seconds")
if request_options is not None and request_options.get("timeout_in_seconds") is not None
else 60,
else self._client_wrapper.get_timeout(),
retries=0,
max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore
)
Expand Down Expand Up @@ -641,7 +641,7 @@ async def get_all_snapshots(
),
timeout=request_options.get("timeout_in_seconds")
if request_options is not None and request_options.get("timeout_in_seconds") is not None
else 60,
else self._client_wrapper.get_timeout(),
retries=0,
max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore
)
Expand Down Expand Up @@ -708,7 +708,7 @@ async def stream_snapshot(
),
timeout=request_options.get("timeout_in_seconds")
if request_options is not None and request_options.get("timeout_in_seconds") is not None
else 60,
else self._client_wrapper.get_timeout(),
retries=0,
max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore
)
Expand Down
30 changes: 24 additions & 6 deletions src/elevenlabs/core/client_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@


class BaseClientWrapper:
def __init__(self, *, api_key: typing.Optional[str] = None, base_url: str):
def __init__(self, *, api_key: typing.Optional[str] = None, base_url: str, timeout: typing.Optional[float] = None):
self._api_key = api_key
self._base_url = base_url
self._timeout = timeout

def get_headers(self) -> typing.Dict[str, str]:
headers: typing.Dict[str, str] = {
"X-Fern-Language": "Python",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "v1.0.1",
"X-Fern-SDK-Version": "v1.0.2",
}
if self._api_key is not None:
headers["xi-api-key"] = self._api_key
Expand All @@ -25,14 +26,31 @@ def get_headers(self) -> typing.Dict[str, str]:
def get_base_url(self) -> str:
return self._base_url

def get_timeout(self) -> typing.Optional[float]:
return self._timeout


class SyncClientWrapper(BaseClientWrapper):
def __init__(self, *, api_key: typing.Optional[str] = None, base_url: str, httpx_client: httpx.Client):
super().__init__(api_key=api_key, base_url=base_url)
def __init__(
self,
*,
api_key: typing.Optional[str] = None,
base_url: str,
timeout: typing.Optional[float] = None,
httpx_client: httpx.Client
):
super().__init__(api_key=api_key, base_url=base_url, timeout=timeout)
self.httpx_client = HttpClient(httpx_client=httpx_client)


class AsyncClientWrapper(BaseClientWrapper):
def __init__(self, *, api_key: typing.Optional[str] = None, base_url: str, httpx_client: httpx.AsyncClient):
super().__init__(api_key=api_key, base_url=base_url)
def __init__(
self,
*,
api_key: typing.Optional[str] = None,
base_url: str,
timeout: typing.Optional[float] = None,
httpx_client: httpx.AsyncClient
):
super().__init__(api_key=api_key, base_url=base_url, timeout=timeout)
self.httpx_client = AsyncHttpClient(httpx_client=httpx_client)
Loading

0 comments on commit 145352e

Please sign in to comment.