aymara_ai.lib.async_utils#

Attributes#

Functions#

wait_until(operation, predicate[, interval, timeout, ...])

Synchronously calls operation with provided args/kwargs until predicate returns True for the result,

wait_until_complete(get_fn, resource_id[, ...])

Generic polling helper for long-running resources (sync version).

async_wait_until(operation, predicate[, interval, ...])

Asynchronously calls operation with provided args/kwargs until predicate returns True for the result,

async_wait_until_complete(get_fn, resource_id[, ...])

Async polling helper for long-running resources.

Module Contents#

aymara_ai.lib.async_utils.T#
aymara_ai.lib.async_utils.logger#
aymara_ai.lib.async_utils.wait_until(operation, predicate, interval=1.0, timeout=60, *args, backoff=False, max_interval=30.0, **kwargs)#

Synchronously calls operation with provided args/kwargs until predicate returns True for the result, or until timeout is reached. Supports optional exponential backoff.

Parameters:
  • operation (Callable[Ellipsis, T]) – Callable to invoke.

  • predicate (Callable[[Any], bool]) – Callable that takes the operation result and returns True if done.

  • interval (float) – Polling interval in seconds.

  • timeout (int) – Maximum time to wait in seconds.

  • backoff (bool) – If True, exponentially increase interval (max max_interval).

  • max_interval (float) – Maximum interval in seconds for backoff.

  • *args (Any) – Positional arguments for operation.

  • **kwargs (Any) – Keyword arguments for operation.

Returns:

The result from operation for which predicate(result) is True.

Raises:

TimeoutError – If timeout is reached before predicate is satisfied.

Return type:

T

aymara_ai.lib.async_utils.wait_until_complete(get_fn, resource_id, status_path='status', success_status='finished', failure_status='failed', timeout=300, interval=2, backoff=False, max_interval=30.0)#

Generic polling helper for long-running resources (sync version).

Parameters:
  • get_fn (Callable[[str], T]) – A function that takes resource_id and returns resource dict.

  • resource_id (str) – The ID of the resource to poll.

  • status_path (str) – Dot-path to status field (e.g. “status” or “metadata.status”).

  • success_status (aymara_ai.types.shared.status.Status) – Status value that indicates completion.

  • failure_status (Optional[aymara_ai.types.shared.status.Status]) – Status value that indicates failure (optional).

  • timeout (int) – Max time to wait, in seconds.

  • interval (int) – Poll interval in seconds.

  • backoff (bool) – If True, exponentially increase interval (max max_interval).

  • max_interval (float) – Maximum interval in seconds for backoff.

Returns:

The completed resource dict.

Raises:

TimeoutError or RuntimeError on failure.

Return type:

T

async aymara_ai.lib.async_utils.async_wait_until(operation, predicate, interval=1.0, timeout=30, *args, backoff=False, max_interval=30.0, **kwargs)#

Asynchronously calls operation with provided args/kwargs until predicate returns True for the result, or until timeout is reached. Supports optional exponential backoff.

Parameters:
  • operation (Callable[Ellipsis, Awaitable[T]]) – Async callable to invoke (e.g., await client.evals.get).

  • predicate (Union[Callable[[Any], bool], Callable[[Any], Awaitable[bool]]]) – Callable (sync or async) that takes the operation result and returns True if done.

  • interval (Optional[float]) – Polling interval in seconds (default: from AYMR_WAIT_INTERVAL or 1.0).

  • timeout (Optional[int]) – Maximum time to wait in seconds (default: from AYMR_WAIT_TIMEOUT or 60.0).

  • backoff (bool) – If True, exponentially increase interval (max max_interval).

  • max_interval (float) – Maximum interval in seconds for backoff.

  • *args (Any) – Positional arguments for operation.

  • **kwargs (Any) – Keyword arguments for operation.

Returns:

The result from operation for which predicate(result) is True.

Raises:

TimeoutError – If timeout is reached before predicate is satisfied.

Return type:

T

async aymara_ai.lib.async_utils.async_wait_until_complete(get_fn, resource_id, status_path='status', success_status='finished', failure_status='failed', timeout=300, interval=2, backoff=False, max_interval=30.0)#

Async polling helper for long-running resources.

Parameters:
  • get_fn (Callable[[str], Awaitable[T]]) – An async function that takes resource_id and returns resource dict.

  • resource_id (str) – The ID of the resource to poll.

  • status_path (str) – Dot-path to status field (e.g. “status” or “metadata.status”).

  • success_status (aymara_ai.types.shared.status.Status) – Status value that indicates completion.

  • failure_status (Optional[aymara_ai.types.shared.status.Status]) – Status value that indicates failure (optional).

  • timeout (int) – Max time to wait, in seconds.

  • interval (int) – Poll interval in seconds.

  • backoff (bool) – If True, exponentially increase interval (max max_interval).

  • max_interval (float) – Maximum interval in seconds for backoff.

Returns:

The completed resource dict.

Raises:

TimeoutError or RuntimeError on failure.

Return type:

T