Skip to content

Commit 48adaab

Browse files
authored
Reduce default PollTimer poll interval and introduce default video polling settings (#98)
- Update `PollTimer` to use a default interval of 1 second instead of 100 milliseconds. - Add `DEFAULT_VIDEO_POLL_INTERVAL` and `DEFAULT_VIDEO_TIMEOUT` constants for consistent timeout and polling interval across video clients. - Modify synchronous and asynchronous video client implementations to utilize the new default values for PollTimer initialization.
1 parent cfbaa39 commit 48adaab

4 files changed

Lines changed: 11 additions & 3 deletions

File tree

src/xai_sdk/aio/video.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from ..proto import deferred_pb2, video_pb2
99
from ..telemetry import get_tracer
1010
from ..video import (
11+
DEFAULT_VIDEO_POLL_INTERVAL,
12+
DEFAULT_VIDEO_TIMEOUT,
1113
BaseClient,
1214
VideoAspectRatio,
1315
VideoResolution,
@@ -74,7 +76,7 @@ async def generate(
7476
7577
This wraps `GenerateVideo` + repeated `GetDeferredVideo` calls until the request is complete.
7678
"""
77-
timer = PollTimer(timeout, interval)
79+
timer = PollTimer(timeout or DEFAULT_VIDEO_TIMEOUT, interval or DEFAULT_VIDEO_POLL_INTERVAL)
7880
request_pb = _make_generate_request(
7981
prompt,
8082
model,

src/xai_sdk/poll_timer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(
2121
"""
2222
self._start = time.time()
2323
self._timeout = timeout or datetime.timedelta(minutes=10)
24-
self._interval = interval or datetime.timedelta(milliseconds=100)
24+
self._interval = interval or datetime.timedelta(seconds=1)
2525

2626
def sleep_interval_or_raise(self) -> float:
2727
"""Returns the time to sleep until the next poll.

src/xai_sdk/sync/video.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from ..proto import deferred_pb2, video_pb2
99
from ..telemetry import get_tracer
1010
from ..video import (
11+
DEFAULT_VIDEO_POLL_INTERVAL,
12+
DEFAULT_VIDEO_TIMEOUT,
1113
BaseClient,
1214
VideoAspectRatio,
1315
VideoResolution,
@@ -74,7 +76,7 @@ def generate(
7476
7577
This wraps `GenerateVideo` + repeated `GetDeferredVideo` calls until the request is complete.
7678
"""
77-
timer = PollTimer(timeout, interval)
79+
timer = PollTimer(timeout or DEFAULT_VIDEO_TIMEOUT, interval or DEFAULT_VIDEO_POLL_INTERVAL)
7880
request_pb = _make_generate_request(
7981
prompt,
8082
model,

src/xai_sdk/video.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import datetime
12
from typing import Any, Optional, Union
23

34
import grpc
@@ -7,6 +8,9 @@
78
from .telemetry import should_disable_sensitive_attributes
89
from .types.video import VideoAspectRatio, VideoAspectRatioMap, VideoResolution, VideoResolutionMap
910

11+
DEFAULT_VIDEO_POLL_INTERVAL = datetime.timedelta(seconds=1)
12+
DEFAULT_VIDEO_TIMEOUT = datetime.timedelta(minutes=10)
13+
1014

1115
class BaseClient:
1216
"""Base Client for interacting with the `Video` API."""

0 commit comments

Comments
 (0)