Skip to content

Commit 675f7ad

Browse files
szymondudyczManul from Pathway
authored andcommitted
Setting default retry strategy in llms and embedders (#9387)
GitOrigin-RevId: 1d851c5b456a54d2ad9de217a253e34578bdf0e7
1 parent 7f5ae6d commit 675f7ad

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
77

88
### Changed
99
- `pw.io.deltalake.read` now accepts the `start_from_timestamp_ms` parameter for non-append-only tables. In this case, the connector will replay the history of changes in the table version by version starting from the state of the table at the given timestamp. The differences between versions will be applied atomically.
10+
- Asynchronous UDFs for connecting to API based llm and embedding models now have by default retry strategy set to `pw.udfs.ExponentialRetryStrategy()`
1011

1112
## [0.26.3] - 2025-10-03
1213

python/pathway/xpacks/llm/embedders.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ class OpenAIEmbedder(BaseEmbedder):
9696
capacity: Maximum number of concurrent operations allowed.
9797
Defaults to None, indicating no specific limit.
9898
retry_strategy: Strategy for handling retries in case of failures.
99-
Defaults to None, meaning no retries.
99+
Defaults to the `ExponentialRetryStrategy
100+
<https://pathway.com/developers/api-docs/udfs#pathway.udfs.ExponentialBackoffRetryStrategy>`_.
100101
cache_strategy: Defines the caching mechanism. To enable caching,
101102
a valid `CacheStrategy` should be provided.
102103
See `Cache strategy <https://pathway.com/developers/api-docs/udfs#pathway.udfs.CacheStrategy>`_
@@ -153,7 +154,9 @@ def __init__(
153154
self,
154155
*,
155156
capacity: int | None = None,
156-
retry_strategy: udfs.AsyncRetryStrategy | None = None,
157+
retry_strategy: (
158+
udfs.AsyncRetryStrategy | None
159+
) = pw.udfs.ExponentialBackoffRetryStrategy(),
157160
cache_strategy: udfs.CacheStrategy | None = None,
158161
model: str | None = "text-embedding-3-small",
159162
truncation_keep_strategy: Literal["start", "end"] | None = "start",
@@ -259,7 +262,8 @@ class LiteLLMEmbedder(BaseEmbedder):
259262
capacity: Maximum number of concurrent operations allowed.
260263
Defaults to None, indicating no specific limit.
261264
retry_strategy: Strategy for handling retries in case of failures.
262-
Defaults to None, meaning no retries.
265+
Defaults to the `ExponentialRetryStrategy
266+
<https://pathway.com/developers/api-docs/udfs#pathway.udfs.ExponentialBackoffRetryStrategy>`_.
263267
cache_strategy: Defines the caching mechanism. To enable caching,
264268
a valid `CacheStrategy` should be provided.
265269
See `Cache strategy <https://pathway.com/developers/api-docs/udfs#pathway.udfs.CacheStrategy>`_
@@ -305,7 +309,9 @@ def __init__(
305309
self,
306310
*,
307311
capacity: int | None = None,
308-
retry_strategy: udfs.AsyncRetryStrategy | None = None,
312+
retry_strategy: (
313+
udfs.AsyncRetryStrategy | None
314+
) = pw.udfs.ExponentialBackoffRetryStrategy(),
309315
cache_strategy: udfs.CacheStrategy | None = None,
310316
model: str | None = None,
311317
**llmlite_kwargs,
@@ -454,7 +460,8 @@ class GeminiEmbedder(BaseEmbedder):
454460
capacity: Maximum number of concurrent operations allowed.
455461
Defaults to ``None``, indicating no specific limit.
456462
retry_strategy: Strategy for handling retries in case of failures.
457-
Defaults to ``None``, meaning no retries.
463+
Defaults to the `ExponentialRetryStrategy
464+
<https://pathway.com/developers/api-docs/udfs#pathway.udfs.ExponentialBackoffRetryStrategy>`_.
458465
cache_strategy: Defines the caching mechanism. To enable caching,
459466
a valid ``CacheStrategy`` should be provided.
460467
See `Cache strategy <https://pathway.com/developers/api-docs/udfs#pathway.udfs.CacheStrategy>`_
@@ -495,7 +502,9 @@ def __init__(
495502
self,
496503
*,
497504
capacity: int | None = None,
498-
retry_strategy: udfs.AsyncRetryStrategy | None = None,
505+
retry_strategy: (
506+
udfs.AsyncRetryStrategy | None
507+
) = pw.udfs.ExponentialBackoffRetryStrategy(),
499508
cache_strategy: udfs.CacheStrategy | None = None,
500509
model: str | None = "models/embedding-001",
501510
api_key: str | None = None,

python/pathway/xpacks/llm/llms.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ class OpenAIChat(BaseChat):
103103
capacity: Maximum number of concurrent operations allowed.
104104
Defaults to None, indicating no specific limit.
105105
retry_strategy: Strategy for handling retries in case of failures.
106-
Defaults to None, meaning no retries.
106+
Defaults to the `ExponentialRetryStrategy
107+
<https://pathway.com/developers/api-docs/udfs#pathway.udfs.ExponentialBackoffRetryStrategy>`_.
107108
cache_strategy: Defines the caching mechanism. To enable caching,
108109
a valid `CacheStrategy` should be provided.
109110
See `Cache strategy <https://pathway.com/developers/api-docs/udfs#pathway.udfs.CacheStrategy>`_
@@ -241,7 +242,9 @@ class OpenAIChat(BaseChat):
241242
def __init__(
242243
self,
243244
capacity: int | None = None,
244-
retry_strategy: udfs.AsyncRetryStrategy | None = None,
245+
retry_strategy: (
246+
udfs.AsyncRetryStrategy | None
247+
) = pw.udfs.ExponentialBackoffRetryStrategy(),
245248
cache_strategy: udfs.CacheStrategy | None = None,
246249
model: str | None = "gpt-3.5-turbo",
247250
*,
@@ -332,7 +335,8 @@ class LiteLLMChat(BaseChat):
332335
capacity: Maximum number of concurrent operations allowed.
333336
Defaults to None, indicating no specific limit.
334337
retry_strategy: Strategy for handling retries in case of failures.
335-
Defaults to None, meaning no retries.
338+
Defaults to the `ExponentialRetryStrategy
339+
<https://pathway.com/developers/api-docs/udfs#pathway.udfs.ExponentialBackoffRetryStrategy>`_.
336340
cache_strategy: Defines the caching mechanism. To enable caching,
337341
a valid `CacheStrategy` should be provided.
338342
See `Cache strategy <https://pathway.com/developers/api-docs/udfs#pathway.udfs.CacheStrategy>`_
@@ -371,7 +375,9 @@ class LiteLLMChat(BaseChat):
371375
def __init__(
372376
self,
373377
capacity: int | None = None,
374-
retry_strategy: udfs.AsyncRetryStrategy | None = None,
378+
retry_strategy: (
379+
udfs.AsyncRetryStrategy | None
380+
) = pw.udfs.ExponentialBackoffRetryStrategy(),
375381
cache_strategy: udfs.CacheStrategy | None = None,
376382
model: str | None = None,
377383
*,
@@ -632,7 +638,8 @@ class CohereChat(BaseChat):
632638
capacity: Maximum number of concurrent operations allowed.
633639
Defaults to None, indicating no specific limit.
634640
retry_strategy: Strategy for handling retries in case of failures.
635-
Defaults to None, meaning no retries.
641+
Defaults to the `ExponentialRetryStrategy
642+
<https://pathway.com/developers/api-docs/udfs#pathway.udfs.ExponentialBackoffRetryStrategy>`_.
636643
cache_strategy: Defines the caching mechanism. To enable caching,
637644
a valid `CacheStrategy` should be provided.
638645
See `Cache strategy <https://pathway.com/developers/api-docs/udfs#pathway.udfs.CacheStrategy>`_
@@ -666,7 +673,9 @@ class CohereChat(BaseChat):
666673
def __init__(
667674
self,
668675
capacity: int | None = None,
669-
retry_strategy: udfs.AsyncRetryStrategy | None = None,
676+
retry_strategy: (
677+
udfs.AsyncRetryStrategy | None
678+
) = pw.udfs.ExponentialBackoffRetryStrategy(),
670679
cache_strategy: udfs.CacheStrategy | None = None,
671680
model: str | None = "command",
672681
**cohere_kwargs,

0 commit comments

Comments
 (0)