|
10 | 10 |
|
11 | 11 | from azure.ai.evaluation._http_utils import AsyncHttpPipeline, get_async_http_client
|
12 | 12 | from azure.ai.evaluation._user_agent import UserAgentSingleton
|
13 |
| -from azure.core.exceptions import HttpResponseError |
| 13 | +from azure.core.exceptions import HttpResponseError, ServiceResponseError |
14 | 14 | from azure.core.pipeline.policies import AsyncRetryPolicy, RetryMode
|
15 | 15 | from azure.ai.evaluation._common.onedp._client import AIProjectClient
|
16 | 16 | from azure.ai.evaluation._common.onedp.models import SimulationDTO
|
@@ -225,7 +225,25 @@ async def request_api(
|
225 | 225 | sleep_time = RAIService.SLEEP_TIME**request_count
|
226 | 226 | await asyncio.sleep(sleep_time)
|
227 | 227 | else:
|
228 |
| - response = await session.post(url=self.endpoint_url, headers=proxy_headers, json=sim_request_dto.to_dict()) |
| 228 | + # Retry policy for POST request to RAI service |
| 229 | + service_call_retry_policy = AsyncRetryPolicy( |
| 230 | + retry_on_exceptions=[ServiceResponseError], |
| 231 | + retry_total=7, |
| 232 | + retry_backoff_factor=10.0, |
| 233 | + retry_backoff_max=180, |
| 234 | + retry_mode=RetryMode.Exponential, |
| 235 | + ) |
| 236 | + |
| 237 | + response = None |
| 238 | + async with get_async_http_client().with_policies(retry_policy=service_call_retry_policy) as retry_client: |
| 239 | + try: |
| 240 | + response = await retry_client.post( |
| 241 | + url=self.endpoint_url, headers=proxy_headers, json=sim_request_dto.to_dict() |
| 242 | + ) |
| 243 | + except ServiceResponseError as e: |
| 244 | + self.logger.error("ServiceResponseError during POST request to rai svc after retries: %s", str(e)) |
| 245 | + raise |
| 246 | + |
229 | 247 | # response.raise_for_status()
|
230 | 248 | if response.status_code != 202:
|
231 | 249 | raise HttpResponseError(
|
|
0 commit comments