Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!
Python
fix: Handle too many requests error in AI Search
Clémence Lesné8f4f8c1ce0a8
diff --git a/app/persistence/ai_search.py b/app/persistence/ai_search.pyindex f14146a..c837429 100644--- a/app/persistence/ai_search.py+++ b/app/persistence/ai_search.py@@ -41,6 +41,7 @@ from azure.search.documents.models import (from pydantic import TypeAdapter, ValidationErrorfrom tenacity import (retry,+ retry_any,retry_if_exception_type,stop_after_attempt,wait_random_exponential,@@ -56,6 +57,10 @@ from app.persistence.icache import ICachefrom app.persistence.isearch import ISearch+class TooManyRequests(Exception):+ pass++class AiSearchSearch(ISearch):_client: SearchClient | None = None_config: AiSearchModel@@ -87,7 +92,10 @@ class AiSearchSearch(ISearch):@retry(reraise=True,- retry=retry_if_exception_type(ServiceResponseError),+ retry=retry_any(+ retry_if_exception_type(ServiceResponseError),+ retry_if_exception_type(TooManyRequests),+ ),stop=stop_after_attempt(3),wait=wait_random_exponential(multiplier=0.8, max=8),)@@ -163,6 +171,8 @@ class AiSearchSearch(ISearch):except ResourceNotFoundError:logger.warning('AI Search index "%s" not found', self._config.index)except HttpResponseError as e:+ if "too many requests" in e.message.lower():+ raise TooManyRequests()logger.error("Error requesting AI Search: %s", e)except ServiceRequestError as e:logger.error("Error connecting to AI Search: %s", e)