@@ -219,7 +219,8 @@ async def simulate_async(
219
219
api_call_retry_limit : int = 3 ,
220
220
api_call_retry_sleep_sec : int = 1 ,
221
221
api_call_delay_sec : float = 0 ,
222
- concurrent_async_task : int = 3
222
+ concurrent_async_task : int = 3 ,
223
+ simulation_result_limit : int = 3 ,
223
224
):
224
225
"""Asynchronously simulate conversations using the provided template and parameters
225
226
@@ -241,6 +242,8 @@ async def simulate_async(
241
242
:paramtype api_call_delay_sec: float, optional
242
243
:keyword concurrent_async_task: The maximum number of asynchronous tasks to run concurrently. Defaults to 3.
243
244
:paramtype concurrent_async_task: int, optional
245
+ :keyword simulation_result_limit: The maximum number of simulation results to return. Defaults to 3.
246
+ :paramtype simulation_result_limit: int, optional
244
247
245
248
:return: A list of dictionaries containing the simulation results.
246
249
:rtype: List[Dict]
@@ -271,7 +274,6 @@ async def simulate_async(
271
274
semaphore = asyncio .Semaphore (concurrent_async_task )
272
275
sim_results = []
273
276
tasks = []
274
-
275
277
for t in templates :
276
278
for p in t .template_parameters :
277
279
if jailbreak :
@@ -294,6 +296,12 @@ async def simulate_async(
294
296
)
295
297
)
296
298
299
+ if len (tasks ) >= simulation_result_limit :
300
+ break
301
+
302
+ if len (tasks ) >= simulation_result_limit :
303
+ break
304
+
297
305
sim_results = await asyncio .gather (* tasks )
298
306
299
307
return JsonLineList (sim_results )
@@ -324,6 +332,8 @@ async def _simulate_async(
324
332
api_call_delay_sec (float, optional): The time in seconds to wait between API calls. Defaults to 0.
325
333
concurrent_async_task (int, optional): The maximum number of asynchronous tasks to run concurrently.
326
334
Defaults to 3.
335
+ simulation_result_limit (int, optional): The maximum number of simulation results to return. Defaults to 3.
336
+
327
337
Returns:
328
338
List[Dict]: A list of dictionaries containing the simulation results.
329
339
0 commit comments