Skip to content

Commit 0c44507

Browse files
slister1001Copilot
andauthored
[evaluation] add retry logic for high concurrency scenarios in AdversarailSimulator, _SafetyEvaluation (#41978)
* Add retry logic for high concurrency scenarios * Update sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/simulator/_model_tools/_proxy_completion_model.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * black fixes --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 4268dd3 commit 0c44507

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/simulator/_model_tools/_proxy_completion_model.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from azure.ai.evaluation._http_utils import AsyncHttpPipeline, get_async_http_client
1212
from azure.ai.evaluation._user_agent import UserAgentSingleton
13-
from azure.core.exceptions import HttpResponseError
13+
from azure.core.exceptions import HttpResponseError, ServiceResponseError
1414
from azure.core.pipeline.policies import AsyncRetryPolicy, RetryMode
1515
from azure.ai.evaluation._common.onedp._client import AIProjectClient
1616
from azure.ai.evaluation._common.onedp.models import SimulationDTO
@@ -225,7 +225,25 @@ async def request_api(
225225
sleep_time = RAIService.SLEEP_TIME**request_count
226226
await asyncio.sleep(sleep_time)
227227
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+
229247
# response.raise_for_status()
230248
if response.status_code != 202:
231249
raise HttpResponseError(

0 commit comments

Comments
 (0)