Skip to content

Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!

Python

perf: Fine-tune exponential backoff

Clémence Lesnécc9229be13c9
diff --git a/helpers/llm_worker.py b/helpers/llm_worker.py
index 197060c..c2c02d3 100644
--- a/helpers/llm_worker.py
+++ b/helpers/llm_worker.py
@@ -110,7 +110,7 @@ async def completion_stream(
stop=stop_after_attempt(
3
), # Usage is short-lived, so stop after 3 attempts
- wait=wait_random_exponential(multiplier=0.5, max=30),
+ wait=wait_random_exponential(multiplier=0.8, max=8),
)
async for attempt in retryed:
with attempt:
@@ -259,7 +259,7 @@ async def completion_sync(
stop=stop_after_attempt(
10
), # Usage is async and long-lived, so stop after 10 attempts
- wait=wait_random_exponential(multiplier=0.5, max=30),
+ wait=wait_random_exponential(multiplier=0.8, max=8),
)
async for attempt in retryed:
with attempt:
@@ -321,7 +321,7 @@ async def _completion_sync_worker(
reraise=True,
retry=retry_if_exception_type(ValidationError),
stop=stop_after_attempt(3),
- wait=wait_random_exponential(multiplier=0.5, max=30),
+ wait=wait_random_exponential(multiplier=0.8, max=8),
)
@tracer.start_as_current_span("completion_model_sync")
async def completion_model_sync(
@@ -478,7 +478,7 @@ async def safety_check(text: str) -> str:
reraise=True,
retry=retry_if_exception_type(HttpResponseError),
stop=stop_after_attempt(3),
- wait=wait_random_exponential(multiplier=0.5, max=30),
+ wait=wait_random_exponential(multiplier=0.8, max=8),
)
async def _contentsafety_analysis(text: str) -> AnalyzeTextResult:
"""
diff --git a/helpers/translation.py b/helpers/translation.py
index 27b88ce..5c77b59 100644
--- a/helpers/translation.py
+++ b/helpers/translation.py
@@ -24,7 +24,7 @@ _client = Optional[TextTranslationClient]
reraise=True,
retry=retry_if_exception_type(HttpResponseError),
stop=stop_after_attempt(3),
- wait=wait_random_exponential(multiplier=0.5, max=30),
+ wait=wait_random_exponential(multiplier=0.8, max=8),
)
async def translate_text(
text: str, source_lang: str, target_lang: str
diff --git a/persistence/ai_search.py b/persistence/ai_search.py
index 6193cbe..12f791f 100644
--- a/persistence/ai_search.py
+++ b/persistence/ai_search.py
@@ -60,7 +60,7 @@ class AiSearchSearch(ISearch):
reraise=True,
retry=retry_if_exception_type(ServiceResponseError),
stop=stop_after_attempt(3),
- wait=wait_random_exponential(multiplier=0.5, max=30),
+ wait=wait_random_exponential(multiplier=0.8, max=8),
)
async def training_asearch_all(
self,
diff --git a/persistence/cosmos_db.py b/persistence/cosmos_db.py
index 6bfd1da..9ed9b35 100644
--- a/persistence/cosmos_db.py
+++ b/persistence/cosmos_db.py
@@ -271,9 +271,9 @@ class CosmosDbStore(IStore):
# Usage
consistency_level=ConsistencyLevel.Eventual,
# Reliability
- connection_timeout=10,
- retry_backoff_factor=0.5,
- retry_backoff_max=30,
+ connection_timeout=10, # 10 seconds
+ retry_backoff_factor=0.8,
+ retry_backoff_max=8,
retry_total=3,
# Performance
transport=await azure_transport(),